undefined reference to createFisherFaceRecognizer() - Incorrect openCV docs?
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;
}
EDIT 3:
I tried 2 thing that have been suggested:
1) cv::face::createFisherFaceRecognizer(int, double), but this gives:
main.cpp:(.text+0x6a8): undefined reference to`cv::face::createFisherFaceRecognizer(int, double)'
2)face::FisherFaceRecognizer::create(), but this gives:
error: ‘cv::face::FisherFaceRecognizer’ has not been declared
None of what I was suggested so far works, what would be a solution?
i removed your useless screenshot (noone can quote from it, it can't get indexed, etc).
if you think, that information is nessecary, please re-add it as a text version
I tried this exact line: Ptr < FisherFaceRecognizer> model = face::FisherFaceRecognizer::create(); As shown in the tutorial, but the error still persists. My code: https://pastebin.com/MhuGYhxB Also the screenshot is a screenshot from the header file.
exact opencv version ?
If I'm not mistaken I use opencv 3.1 and installed opencv_contrib-3.1.
did you link
-lopencv_face
(or whatever it is on your system) ?(and sorry, should have asked earlier for the version ..)
I also tried to compile it via the command line using: g++ main.cpp -L/usr/local/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -lopencv_face -o main
But that still returns: main.cpp:86:46: error: 'cv::face::FisherFaceRecognizer' has not been declared Ptr<face::facerecognizer> model = face::FisherFaceRecognizer::create();
code: https://pastebin.com/vT7pD99b
the error in your title is a linker problem, your current one a compiler one (missing namespace face::)
line 84 (of your paste) should be the correct one for opencv3.1
if line 84 is correct. What is the problem then?
Even adding the lines using namespace face; using namespace cv::face; in stead of mentionnig the namespaces explicitel doesn't change anything.
I have to say that "pkg-config --modversion opencv" returns 3.1.0 and dpkg -l | grep libopencv returns 2.4.9.1+dfsg-1.5ubuntu1. Do you think this might be an issue? http://imgur.com/a/p7T08