Matrix error in FaceRecognizer predict
This is a question I've also asked on Stackoverflow.com
I'm trying to make a FisherFaceRecognizer's predict() method work, but I keep getting an error
Bad argument (Wrong shapes for given matrices. Was size(src) = (1,108000), size(W) = (36000,1).) in subspaceProject, file /tmp/opencv-DCb7/OpenCV-2.4.3/modules/contrib/src/lda.cpp, line 187
I've verified that both source and training images are the same data type, full color. In fact, I even tried copying one to the other just to make sure they were the same.
My code is adapted from the tutorial at http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html#fisherfaces
however, my test image is larger than the training images, so I needed to work on a region of interest (ROI) of the right size.
Here's how I read the images and converted sizes. I cloned the ROI matrix because an earlier error message told me the target matrix must be contiguous:
IplImage* img; img = cvLoadImage( imgName.c_str() ); int height = trainingImages[0].rows; // Take a subset of the same size as the training images Mat testSample1(img, Rect( xLoc, yLoc, trainingImages[0].cols, trainingImages[0].rows)); Mat testSample; testSample1.copyTo( testSample); int testLabel = 1; // The following lines create an Fisherfaces model for // face recognition and train it with the images and // labels read from the given CSV file. Ptr<FaceRecognizer> model = createFisherFaceRecognizer(); model->train(trainingImages, labels); cout << " check of data type testSample is " << testSample.type() << " images is " << trainingImages[0].type() << endl; cout << " trainingImages = " << trainingImages[0].elemSize() << " vs " << testSample.elemSize() << endl; int predictedLabel = model->predict(testSample); //
// I get an exception message at the predict statement.
I know both matrices have type 16, yet somehow it still doesn't believe the matrices are the same size and data type. I've verified that both Mat's are the same dimensions (180x200) and the same elemSize() (3). Is this an internal bug?