FaceRecognizer

asked 2016-03-21 14:15:03 -0600

updated 2016-03-23 14:46:31 -0600

I continue with problem with facereconizer: Please see the code:

I have this variables where is the faces

vector<Mat> images;
vector<int> labels;

... here I load the files to vectors

int img_width  = images[0].cols; // 197
int img_height = images[0].rows; // 197

CascadeClassifier face_cascade;
string classifier = "haarcascade_frontalface_alt.xml";

face_cascade.load(classifier);

I am not sure if createEigenFaceRecognizer is better to use, but I am using it

Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
model->train(images, labels);

Here is vector to store faces if exist

vector<Rect> faces;
Mat frame;
Mat cropImg;
cap >> frame;

Here I call the face_cascade to check if exist faces

face_cascade.detectMultiScale(frame, faces, 1.1, 3, 0, cv::Size(190, 190), cv::Size(200, 200));

cv::Rect roi;
for (int i = 0; i < faces.size(); i++)
{

Well, now I crop the face like the faces stored, that I am using to try reconizer

     roi.x = faces[i].x; roi.width = faces[i].width;
     roi.y = faces[i].y; roi.height = faces[i].height;
     cropImg = frame(roi);
     cvtColor(cropImg, cropImg, CV_BGR2GRAY);

And finally now I try to identify

     int label = model->predict(cropImg);
     string text;
     if(label>=0 ){
        text = format("Label = %d", label);
     }else{
        text = "Unknow";
     }
     putText(frame, text, Point(faces[i].x, faces[i].y), FONT_HERSHEY_COMPLEX_SMALL, 1.0, CV_RGB(0, 255, 0), 1.0);
}

I not know why it not work, it is exactly how is samples, maybe I am losing something, if a person that is not in my database go to camera, it identify the face with a wrong entrie.

Someone can help me?

edit retag flag offensive close merge delete

Comments

1

congratulations for getting the general flow right, but -

  • you need more images (like a good dozen per person).
  • also, it will work better with more persons (do you know, how LDA works ? with 2 persons, you have a 1-element feature vec only)
berak gravatar imageberak ( 2016-03-21 14:19:54 -0600 )edit

Thanks for reply but, I add 10 photo by person ( 2 persons ) and the problem is the same... No, I dont know how LDA work.

Can you help me?

What is better/correct to use: createEigenFaceRecognizer createFisherFaceRecognizer createLBPHFaceRecognizer

Note, I am working using openCV from GIT repository (version 3.1.0).

Thanks.

Lailton gravatar imageLailton ( 2016-03-21 15:14:26 -0600 )edit

The pictures I need save to gray and facecroped to reconize ? I am using files salved from webcam default color and size. is it wrong ?

Lailton gravatar imageLailton ( 2016-03-21 17:09:44 -0600 )edit
1

yes, please use grayscale images, and a CascadeClassifier to crop out the face region only. then resize that region to a fixed size, say, 100x100 pixel.

berak gravatar imageberak ( 2016-03-22 00:14:35 -0600 )edit

Also, I am not convinced that a system based on the OpenCV facerecognizer will work in 100% off all cases, unless the conditions are very controlled :D

StevenPuttemans gravatar imageStevenPuttemans ( 2016-03-22 08:33:05 -0600 )edit