cvMatchTemplate() 函数给出断言失败错误?开放式计算机视觉
我正在尝试使用 cvMatchTemplate()
进行一些图像跟踪,但我不断收到断言失败错误 -215。我希望有人能解决这个问题。我已确保所有 ivars 不为零,并且结果和模板的大小正确。我使用的是 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`
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);
Here's the error:
`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`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
宽度和高度看起来不错。也许深度是错误的。将您的
cvCreateImage
行更改为:Width and height seems fine. Maybe depth is wrong. Change your
cvCreateImage
line to: