我正在使用OpenCV将一组图像(IplImage **)传递给C ++中的对象。我然后尝试迭代该数组并将它们全部调整为固定大小(150x150)
我这样做:
for(int i = 0; i< this->numTrainingFaces; i++)
{
IplImage* frame_copy = cvCreateImage( cvSize(150,150), this->faceImageArray[0]->depth, this->faceImageArray[0]->nChannels );
cout << "Created image" << endl;
cvResize(this->faceImageArray[i], frame_copy);
cout << "Resized image" << endl;
IplImage* grey_image = cvCreateImage( cvSize( frame_copy->width, frame_copy->height ), IPL_DEPTH_8U, 1 );
cout << "Created grey image" << endl;
cvCvtColor( frame_copy, grey_image, CV_RGB2GRAY );
cout << "Converted image" << endl;
this->faceImageArray[i] = grey_image;
cvReleaseImage(&frame_copy);
cvReleaseImage(&grey_image);
}
但是我得到了这个输出,我不知道为什么:
Created image
Resized image
Created grey image
Converted image
Created image
OpenCV Error: Assertion failed (src.type() == dst.type()) in cvResize, file /build/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp, line 3102
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp:3102: error: (-215) src.type() == dst.type() in function cvResize
Aborted
我基本上只是尝试用尽可能少的步骤替换数组中的图像。
编辑:
修改我的代码如下:
for(int i = 0; i< this->numTrainingFaces; i++)
{
IplImage* frame_copy = cvCreateImage( cvSize(150,150), this->faceImageArray[i]->depth, this->faceImageArray[i]->nChannels );
cvResize(this->faceImageArray[i], frame_copy);
IplImage* grey_image = cvCreateImage( cvSize( frame_copy->width, frame_copy->height ), IPL_DEPTH_8U, 1 );
cvCvtColor( frame_copy, grey_image, CV_RGB2GRAY );
faceImageArray[i] = cvCreateImage( cvSize(grey_image->width, grey_image->height), grey_image->depth, grey_image->nChannels);
cvCopy(grey_image,faceImageArray[i]);
cvReleaseImage(&frame_copy);
cvReleaseImage(&grey_image);
}
然后我正在执行一些PCA,并获得此输出:
OpenCV Error: Null pointer (Null pointer to the written object) in cvWrite, file /build/buildd/opencv-2.1.0/src/cxcore/cxpersistence.cpp, line 4740
但我不认为我的代码已经达到了我明确调用cvWrite的程度,所以它必须是库的一部分。如果有必要,我可以给出一个完整的实现 - 我的代码中是否有任何东西可以创建一个空指针?
我的完整源代码在这里:http://pastie.org/1447022 - 创建一个类,设置变量,然后调用learn()。
答案 0 :(得分:3)
该行
IplImage* frame_copy = cvCreateImage( cvSize(150,150), this->faceImageArray[0]->depth, this->faceImageArray[0]->nChannels );
应该是
IplImage* frame_copy = cvCreateImage( cvSize(150,150), this->faceImageArray[i]->depth, this->faceImageArray[i]->nChannels );
此外,this->
通常是无操作。 faceImageArray[0]->depth, faceImageArray[0]->nChannels
就足够了。