cvMatchTemple断言失败错误(VS2015 + opencv2)

时间:2016-06-15 15:52:55

标签: c opencv

我希望有人能搞清楚。

代码

int iwidth = screenImage->width - templ->width+1;
int iheight = screenImage->height - templ->height+1;

IplImage *ftmp = cvCreateImage(cvSize(iwidth, iheight), 8,1);
double max_val;
double min_val;
CvPoint min_loc;
CvPoint max_loc;
cvMatchTemplate(screenImage,templ,ftmp,0);
cvMinMaxLoc(ftmp, &min_val, &max_val, &min_loc, &max_loc, NULL);
cvRectangle(screenImage, cvPoint(min_loc.x, min_loc.y), cvPoint((min_loc.x + templ->width), (min_loc.y + templ->height)), CV_RGB(0, 255, 0), 1);
cvNamedWindow("src", 1);
cvShowImage("src", screenImage);
cvWaitKey(0);

当我跑步时,我收到了一个错误:

  

OpenCV错误:断言失败(result.size()== cv :: Size(std :: abs(img.cols - te)   mpl.cols)+ 1,std :: abs(img.rows - templ.rows)+ 1)&& result.type()== CV_32F)   在cvMatchTemplate中,文件E:\ opencv \ opencv \ sources \ modules \ imgproc \ src \ templmatch   .cpp,第1100行

1 个答案:

答案 0 :(得分:0)

此行产生错误

float

应该是

IplImage *ftmp = cvCreateImage(cvSize(iwidth, iheight), 8,1);

IplImage *ftmp = cvCreateImage(cvSize(iwidth, iheight), 32,1); 需要结果图像应该是32位浮点数,但你已经给出了8位。这就是错误说法

MatchTemplate
相关问题