开发者

cvMatchTemplate() function giving assertion failed error? opencv

开发者 https://www.devze.com 2023-03-07 18:09 出处:网络
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

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,i开发者_运维问答mage->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`


Width and height seems fine. Maybe depth is wrong. Change your cvCreateImage line to:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号