【问题标题】:cvMatchTemplate() function giving assertion failed error? opencvcvMatchTemplate() 函数给出断言失败错误? opencv
【发布时间】:2011-05-22 02:37:01
【问题描述】:

我正在尝试使用 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`

【问题讨论】:

    标签: opencv


    【解决方案1】:

    宽度和高度看起来不错。也许深度是错误的。将您的 cvCreateImage 行更改为:

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

    【讨论】:

    • 是的,nChannel 是错误的,应该是 1,但我仍然遇到同样的错误
    • @ssj:你也换了IPL_DEPTH_32F吗?此外,您可能需要使用 ROI 大小而不是图像大小。使用roiFace.width 而不是image->width 和分别作为高度。
    • Banthar,你是对的,我应该使用 roi 而不是整个图像宽度。
    猜你喜欢
    • 1970-01-01
    • 2020-03-29
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    • 2017-10-26
    相关资源
    最近更新 更多