Hello
I am simply trying to use this openCV function: createFisherFaceRecognizer()
As can be seen here in the docs(http://docs.opencv.org/3.1.0/da/d60/tutorial_face_main.html) the correct way to use this function is as follows:
Ptr<BasicFaceRecognizer> model = createFisherFaceRecognizer();
Some other places in the docs claim that the function needs two parameters(http://www.docs.opencv.org/3.0-rc1/db/d7c/group__face.html#ga4cd9f632dce63aeff7cfb7738f80523c):
Ptr<BasicFaceRecognizer> cv::face::createFisherFaceRecognizer ( int num_components = 0, double threshold = DBL_MAX)
Unfortunately nothing works! Does anybody know what the issue could be?
This is my current code:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <opencv2/opencv.hpp>
#include "opencv2/core.hpp"
#include "opencv2/face.hpp"
#include "opencv2/highgui.hpp"
#include "include/faceDetection.h"
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap(CV_CAP_ANY);
Mat imgFrame;
Mat face;
vector<Mat> facesImgFrame;
faceDetection faceDetectionObj;
if( !cap.isOpened() )
{
cout << "Could not initialize capturing...\n";
return 0;
}
CascadeClassifier faceCascade;
if(!faceCascade.load("haarcascade_frontalface_alt.xml"))
{
cerr<<"error when loading xml file for face"<<endl;
exit(1);
}
CascadeClassifier eyes_cascade;
if(!eyes_cascade.load("haarcascade_eye_tree_eyeglasses.xml"))
{
cerr<<"error when loading xml file for eyes"<<endl;
exit(1);
}
cerr<<"loaded XML file"<<endl;
vector<Mat> trainImages;
vector<int> labelsTrainImages;
string fn_csv = string("/home/Desktop/myCSVFile");
try {
read_csv(fn_csv, trainImages, labelsTrainImages);
} catch (cv::Exception& e) {
cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;
exit(1);
}
// NONE OF THOSE WORKS
//Ptr<face::FaceRecognizer> model = face::createLBPHFaceRecognizer(1,1,1,1,1);
Ptr<face::FaceRecognizer> model = face::createFisherFaceRecognizer();
//Ptr<face::BasicFaceRecognizer> model = face::createFisherFaceRecognizer();
//static Ptr<face::FisherFaceRecognizer> model = create(0, DBL_MAX);
model->train(trainImages, labelsTrainImages);
while(1)
{
cap >> imgFrame;
imshow("imgFrame", imgFrame);
char c = (char)waitKey(10);
facesImgFrame = faceDetectionObj.detectAndDisplay(imgFrame, faceCascade, eyes_cascade);
if(!facesImgFrame.empty())
for(int i=0;i<facesImgFrame.size();i++)
{
string windowName = "face "+ tostr(i);
namedWindow( windowName, WINDOW_AUTOSIZE );
imshow(windowName, facesImgFrame.at(i));
int labelPerson = model->predict(facesImgFrame.at(i));
cerr<<"labePerson: "<<labelPerson<<endl;
}
cerr<<"number of detected faces: "<<facesImgFrame.size()<<endl;
facesImgFrame.clear();
}
return 0;
}