FaceRecognizer
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?
congratulations for getting the general flow right, but -
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.
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 ?
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.
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