Ask Your Question
0 example help

asked 2012-07-12 09:09:22 -0600

coredumped gravatar image

Hello, I'm currently doing some work in face recognition with small training data samples (typically only one per person). I was initially trying to do face recognition with eigenfaces but getting terrible results, and was guided to use Local Binary Patterns Histograms by this stack overflow post:

I started to study the libfacerec as suggested and tried to use the facerec_lbph.cpp example which uses the Local Binary Patterns Histograms to recognize faces. However, my results were still very poor. I suspect the reason for this is that my preprocessing method for the images was applying grayscale and histogram equalization. The stack overflow post linked above suggested using the TanTriggs method to preprocess the images in order to achieve good results. So, some research later, I found which seems to be doing what I need in python. From a sample video, detecting the faces in it, and predicting who they might belong to, giving as a second argument to the program, a training set of images.

I must admit, I'm quite new to python, and the fact that there isn't much documentation on this particular example, I'm having trouble making it work.

Currently if I try running it in its original code (The only thing I changed was making so instead of capturing frames from a video file, it captures from a live camera feed) it simply does not detect any faces.. I tested the code and it works on its own. I started messing around a bit with the code, and by changing the

img = cv2.resize(frame, (frame.shape[1]/2, frame.shape[0]/2), interpolation = cv2.INTER_CUBIC)


img = cv2.resize(frame, (frame.shape[1]2, frame.shape[0]2), interpolation = cv2.INTER_CUBIC)

the program is able to detect faces. However, when reaching the predict step

get a prediction

prediction = self.predictor.predict(face)

it gives me this error:

Traceback (most recent call last): File "", line 98, in <module> App(videosrc, datasetfn).run() File "", line 74, in run prediction = self.predictor.predict(face) File "../../facerec/", line 21, in predict return self.classifier.predict(q) File "../../facerec/", line 38, in predict hist = dict((key,val) for key, val in enumerate(np.bincount(sorted_y)) if val) ValueError: The first argument cannot be empty.

and I am stuck here... Can someone help me to better understand this code, or fix my problem please? Thank you.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-07-12 16:49:17 -0600

blue gravatar image

Looks to me like you have an empty face database. The exception thrown is probably because the argument to np.bincount has length 0. This could either be because k==0 (unlikely) or len(predictor.y)==0. This value is assigned at self.predictor.compute(). Check that dataset_fn (command line argument 2) is valid.

edit flag offensive delete link more

answered 2012-07-12 13:36:43 -0600

updated 2012-07-12 15:30:56 -0600

This is a not an OpenCV question, so it doesn't really belong here. Don't take this personal: If you have problems with Open Source projects, then use the bug tracker of the specific project. Most github projects have a bug tracker, so does this one:

You have luck, since I am browsing here regularly, but this is definitely not the case for other project authors. Regarding your question. Without knowing anything about setup and data, it's nearly impossible to recreate problems. The program you have found was a sample application I hacked up in some minutes, just to show case how to connect the Python framework with OpenCV. I didn't invest much time in checking wether the input data is valid or not.

The specific problem you see is located in the Nearest Neighbor classifier:

I am short on time and I can't support this project a lot. So if anyone finds and fixes a bug, please make a Pull Request and I'll put it upstream.

Algorithmically. You are asking for a very tough problem, but you seem to expect a simple answer. There isn't one. Do you have only one image per person? Then Local Binary Pattern Histograms might help, at least a lot of publications report it. Do you have a lot of difference in illumination? Then a Tan Triggs preprocessing might help. Are the objects in your image rotated? Then do a geometric normalization on your input images, this will enhance recognition rates. The face recognition algorithms I have contributed are neither rotation-invariant, nor scale-invariant. If I had one of those I would go out and make a million of dollars.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-07-12 09:09:22 -0600

Seen: 1,003 times

Last updated: Jul 12 '12