openCV recognition throws exception (LBPH algorithm)

1.3k views Asked by At

I tried to detect and recognize face through LBPH algorithm. For that, I tried the following example:

Mastering OpenCV Chapter 8 FaceRecognition

The code runs and works successfully for Eignefaces and Fisherfaces but gives an exception when recognize for LBPH algorithm. I can't figure it out. The exception is:

OpenCV Error: Bad argument (no parameter 'eigenvectors' is found)  in unknown function, file "..\modules\core\src\algorithm.cpp" line 882.

In line 882,

CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "<NULL>") );

The above line is called after the following line which causes the exception

Mat eigenvectors = model->get<Mat>("eigenvectors");

So, what am I doing wrong? Please experts come and rescue me. Thanks

2

There are 2 answers

0
sarwar026 On BEST ANSWER

After posting the same question in OpenCV Forum, I learned that the problem is in my sample code. Some portions are not applicable for LBPH Algorithm. The lines are below:

Mat reconstructedFace;
reconstructedFace = reconstructFace(model, preprocessedFace);
if (m_debug)
    if (reconstructedFace.data)
        imshow("reconstructedFace", reconstructedFace);

// Verify whether the reconstructed face looks like the preprocessed face, otherwise it is probably an unknown person.
double similarity = getSimilarity(preprocessedFace, reconstructedFace);

The above lines of code are applicable for Eigenfaces and Fisherfaces which I don't know! After commenting those lines of code, I simply call

identity = model->predict(preprocessedFace);

which gives the prediction result and hence.

6
Luca Davanzo On

How you define yout algorithm?

If you want to detect face, you have to define model in this way:

const char* recAlgorithmEigenfaces = "FaceRecognizer.Eigenfaces";
Ptr<FaceRecognizer> model;
model = Algorithm::create<FaceRecognizer>(recAlgorithmEigenfaces);

Optionally you have to check the model:

if (model.empty()) {
 /* throw exception */ 
}

And then train your model..

edit

another explanation, reading here, is that:

[..]face recognition algorithms are available through the FaceRecognizer class in OpenCV's contrib module. Due to dynamic linking, it is possible that your program is linked to the contrib module but it is not actually loaded at runtinme (if it was deemed as not required). So it's recommended to call the

cv::initModule_contrib()

function before trying to access the FaceRecognizer algorithms. The function is only available from OpenCV v2.4.1, so it also ensures that the face recognition algorithms are at least available to you at compile time [..]