Ask Your Question
0

LBPHFaceRecognizer train length error

asked 2017-08-04 02:18:45 -0600

Hi,

I am trying to extract histograms from a grayscale face image, but I am getting a std::length_error. I am using opencv 3.1.0

This is my code:

 int GetHistograms(cv::Mat &features)
{   
    cv::Mat img;
    img = cv::imread("face_grayscale.bmp",CV_LOAD_IMAGE_UNCHANGED);
    std::vector<cv::Mat> images;
    std::vector<int> labels;
    images.push_back(img); labels.push_back(0);

    cv::Ptr<cv::face::LBPHFaceRecognizer> model2 = cv::face::createLBPHFaceRecognizer();
    model2->train(images, labels);
    std::vector<cv::Mat> histogramsS = model2->getHistograms();
    features =  histogramsS[0];

    return histogramsS[0].cols;
}

The code fails on train(images, labels). Going into details, I could see that the exception is through in lbph_faces.cpp in _in_src.getMatVector(src)

I have checked the loaded image is really loaded, has format CV_8U (grayscale), size 100x100 and no stride (isContinuos = true).

Any suggestions?

Thanks.

edit retag flag offensive close merge delete

Comments

What is error message ? You have only one label and one image ?

LBerger gravatar imageLBerger ( 2017-08-04 02:55:03 -0600 )edit

Yes, I have only one image and one label. The error in output is "std::length_error. Debugging I obtain "Exception thrown at 0x52BCE39D (opencv_core310.dll). Access violation writing location 0x80000640.

tralladas gravatar imagetralladas ( 2017-08-04 03:22:00 -0600 )edit

there is no error using opencv 3.3. Please use IMREAD_GRAYSCALE instead of CV_LOAD_IMAGE_UNCHANGED

You mustn't use opencv_core310.dll if your program is in debug mode

LBerger gravatar imageLBerger ( 2017-08-04 04:20:47 -0600 )edit

tralladas, any chance, you're mixing debug build & release libs, or the other way round ?

berak gravatar imageberak ( 2017-08-04 04:32:35 -0600 )edit

Hi, Libraries are correct because same libraries are used in other proyect (receiving an image from camera) and train works correctly. The problem is when image is loaded from file. I have already tried IMREAD_GRAYSCALE also, and the error persists.

tralladas gravatar imagetralladas ( 2017-08-04 06:29:35 -0600 )edit

Are you in release or debug? try to update to 3.3. You will have to change your code to create object ( cv::Ptr<cv::face::lbphfacerecognizer> model2 = face::LBPHFaceRecognizer::create();)

LBerger gravatar imageLBerger ( 2017-08-04 07:31:55 -0600 )edit

Sorry, actually opencv 3.1.0 is used in several projects in Production environment and I can't migrate to 3.3.0 version.

tralladas gravatar imagetralladas ( 2017-08-08 08:31:52 -0600 )edit

"because same libraries are used in other proyect" -- that is not a proof. please check your linker settings, again. (this time for real !)

berak gravatar imageberak ( 2017-08-08 08:46:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-08-10 02:53:12 -0600

Hi,

I could resolve it the same way my other post: Creating new project and linking opencv libraries again. I supose it was wrongly linked.

Thanks for all replies.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-08-04 02:18:45 -0600

Seen: 587 times

Last updated: Aug 10 '17