【发布时间】:2013-02-04 21:32:45
【问题描述】:
我正在尝试使 FisherFaceRecognizer 的 predict() 方法工作,但我不断收到错误
错误的参数(给定矩阵的形状错误。大小(src)= (1,108000), size(W) = (36000,1).) in subspaceProject, file /tmp/opencv-DCb7/OpenCV-2.4.3/modules/contrib/src/lda.cpp,第 187 行
这类似于Wrong shapes for given matrices in OPENCV 提出的问题 但就我而言,源图像和训练图像都是相同的数据类型,全彩色。
我的代码改编自http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html#fisherfaces的教程
但是,我的测试图像比训练图像大,因此我需要处理大小合适的感兴趣区域 (ROI)。
以下是我读取图像和转换尺寸的方法。我克隆了 ROI 矩阵,因为 较早的错误消息告诉我目标矩阵必须是连续的:
vector<Mat> images;
images.push_back( cvLoadImage( trainingList[i].c_str()));
IplImage* img;
img = cvLoadImage( imgName.c_str() );
// take ROI and clone into a new Mat
Mat testSample1(img, Rect( xLoc, yLoc, images[0].cols, images[0].rows));
Mat testSample = testSample1.clone();
// Create a FisherFaceRecognizer in OpenCV
Ptr<FaceRecognizer> FFR = createFisherFaceRecognizer(0,DBL_MAX);
model->train(images, labels);
cout << " check of data type testSample is " << testSample.type() << " images is " << images[0].type() << endl;
int predictedLabel = model->predict(testSample);
//
我在预测语句中收到异常消息。
cout 语句告诉我两个矩阵的类型都是 16,但不知何故它仍然不相信矩阵的大小和数据类型相同...
【问题讨论】:
标签: opencv