本文介绍了cvMatchTemplate()函数给出断言失败错误? OpenCV的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用cvMatchTemplate()
进行一些图像跟踪,但是我不断收到断言失败错误-215.我希望有人能弄清楚这一点.我确保所有ivars都不为零,并且结果和模板的大小正确.我正在使用opencv 2.2
I'm trying to do some image tracking using cvMatchTemplate()
but I keep getting an assertion failed error -215. I hope someone can figure this out. I've made sure that all the ivars are not nil and results and templates are sized correctly. I am on 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
行更改为:
Width and height seems fine. Maybe depth is wrong. Change your cvCreateImage
line to:
IplImage *results = cvCreateImage(tempsize,IPL_DEPTH_32F, 1);
这篇关于cvMatchTemplate()函数给出断言失败错误? OpenCV的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!