Search code examples
c++opencvcomputer-visionlbph-algorithm

openCV recognition throws exception (LBPH algorithm)


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


Solution

  • 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.