LBPHFaceRecognizer train length error
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.
What is error message ? You have only one label and one image ?
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.
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
tralladas, any chance, you're mixing debug build & release libs, or the other way round ?
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.
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();)
Sorry, actually opencv 3.1.0 is used in several projects in Production environment and I can't migrate to 3.3.0 version.
"because same libraries are used in other proyect" -- that is not a proof. please check your linker settings, again. (this time for real !)