dimanche 24 juillet 2016

cvMatchTemple assertion failed error (VS2015+opencv2)

I hope someone can figure it out.

Code

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);

And when I ran it, I got an error:

OpenCV Error: Assertion failed (result.size() == cv::Size(std::abs(img.cols - te mpl.cols) + 1, std::abs(img.rows - templ.rows) + 1) && result.type() == CV_32F) in cvMatchTemplate, file E:opencvopencvsourcesmodulesimgprocsrctemplmatch .cpp, line 1100

Aucun commentaire:

Enregistrer un commentaire