cvMatchTemplate()函数给出断言失败错误? OpenCV的

时间:2011-05-21 18:28:13

标签: opencv

我正在尝试使用cvMatchTemplate()进行一些图像跟踪,但我一直收到断言失败错误-215。我希望有人可以解决这个问题。我确保所有的ivars都不是nil,结果和模板的大小正确。我在opencv 2.2

    int ww = image->width - template->width + 1;
    int hh = image->height - template->height + 1;
    CvSize tempsize = cvSize(ww, hh);
    IplImage *results = cvCreateImage(tempsize,image->depth, image->nChannels);

    //set the roi
    cvSetImageROI(image, roiFace);
    cvMatchTemplate(image, template, results, CV_TM_SQDIFF_NORMED);

这是错误:

`OpenCV Error: Assertion failed (
result.size() == cv::Size(std::abs(img.cols - templ.cols) + 1, std::abs(img.rows - templ.rows) + 1) 

&& 
result.type() == CV_32F) in 

cvMatchTemplate, file /Volumes/ramdisk/opencv/OpenCV-2.2.0/modules/imgproc/src/templmatch.cpp, line 381
terminate called after throwing an instance of 'cv::Exception'


  what():  /Volumes/ramdisk/opencv/OpenCV-2.2.0/modules/imgproc/src/templmatch.cpp:381: error: (-215) result.size() == cv::Size(std::abs(img.cols - templ.cols) + 1, std::abs(img.rows - templ.rows) + 1) && result.type() == CV_32F in function cvMatchTemplate`

1 个答案:

答案 0 :(得分:2)

宽度和高度似乎很好。也许深度是错误的。将您的cvCreateImage行更改为:

IplImage *results = cvCreateImage(tempsize,IPL_DEPTH_32F, 1);