我正在尝试使用cvMatchTemplate()
进行一些图像跟踪,但我不断收到断言失败错误-215。我希望有人能弄清楚这一点。我已经确保所有 ivar 都不是零,并且结果和模板的大小正确。我在 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`
宽度和高度似乎很好。也许深度是错误的。将cvCreateImage
行更改为:
IplImage *results = cvCreateImage(tempsize,IPL_DEPTH_32F, 1);