Ask Your Question

How large should the dataset be when using cv2 recognizers (FisherFace, LBPH)? 10 images? 20? 100?

asked 2018-10-24 07:59:11 -0500

Q1 - Should the people be facing the camera or can I use images of them looking slightly to the sides/ slightly up and down?

Q2 - What is the minimum recommended dataset size?

Q3 - What is the maximum recommended dataset size?

Q4 - When should I worry about over fitting?

Q5 - All faces found during facial detection are resized to 350x350 whether it's during dataset preparation or during actual recognition is this right?

I'm using around 7 - 15 images for each person, most are 640x420 that i captured with my webcam, some taken from social media. First LBP or HAAR detector is used to find and grab the faces and store them as 350x350 greyscale images, those images are then used as the dataset when you train the recognizer (the dataset labels are the names of the folders holding each person's images).

the detectors are then fed a live stream of frames and the faces are found, turned into 350x350 greyscale images and fed into the recognizer, unfortunately the recognizers are usually pretty confused, mostly they return person 1 (who has 30 images) for most faces.

Any advice / answers are welcome.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-10-24 08:27:50 -0500

berak gravatar image

mostly they return person 1 (who has 30 images) for most faces.

that sounds likely. remember, it just tries to find the one with the smallest distance from the dataset. if one person is "over-represented" in your db, it will show up more often than others.

Q1: the more you can restrict it to "straight", the better.

Q2: say, 10 images per person.

Q3: depends on your hardware. training fisherfaces with more than 5000 images might take hours (and the larger the images, the worse it will get).

Q4: you can't really "overfit" a linear, 1 nearest neighbour search (it's maybe the wrong word). but the more persons you add, the less "room" to distinguish them is left.

Q5: yea, preprocessing, it's important. the more "background" you have in the images, the more likely it is, that it decides because of that, and not the actual face. also, you could try to align the cropped face images, so the eyes are on a horizontal line, and all in the same distance to the image borders.

last, but not least: what are you trying to achieve with it ? those face recognizer classes are meant to do identification (closest from a db). if your problem is authentication (yes/no for a single person -- it's probably the wrong tool.)

then, current opencv also has a new pretrained dnn method available (also works on color images)

edit flag offensive delete link more


First, thank you for answering!

Secondly. I modified the images and tested again with 13 images for 6 people I know and 11 images for 5 people that I took from the yale dataset, HAAR detection was used to get the faces from each image and store them as 350x350 greyscale images, those where then used for training.

The recognition process improved, it still became confused uncomfortably often but at least it wasn't 100% telling me that everyone was in fact Bob.

The goal of my project is to perform live facial recognition on a stream of images.

I tested with HAAR detection + LBPH recognition.

Mahmoud gravatar imageMahmoud ( 2018-10-24 09:57:52 -0500 )edit

yea, takes some fiddling, to get nice results. if you do a research on "face alignment for recognition" or so, you'd be amazed, how much work ppl put into it, for grayscale images, opencv also has BIF (works good with an ANN as classifier (solves ATT 100%)

but in the end, SOA is facenet, and it can be used with opencv's dnn module.

berak gravatar imageberak ( 2018-10-24 10:48:24 -0500 )edit

Yup, i just tested to see if resizing the faces to 350x350 before feeding them into the recognizer had any positive/negative affect, and it turns out it was the right move. the HAAR detection + LBPH recognition seems to be the best, but it's still not satisfactory.

I'm updating opencv-python using pip as i write, i'm planning on getting into cv2.dnn using Adrian Rosebrock's tutorials on

Mahmoud gravatar imageMahmoud ( 2018-10-24 14:01:07 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-10-24 07:57:07 -0500

Seen: 267 times

Last updated: Oct 24 '18