2016-06-15 60 views
0

我希望有人能弄明白。cvMatchTemple聲明失敗錯誤(VS2015 + opencv2)

代碼

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 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:\opencv\opencv\sources\modules\imgproc\src\templmatch .cpp, line 1100

+0

您標記C++,但使用的是C API – Berriel

+0

不要使用過時的C api! – Miki

回答

0

這條線是生產錯誤

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

應該

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

MatchTemplate需求導致的圖像應該是32位浮點的,但你給8個bit.This是什麼樣的錯誤是說

result.size() == cv::Size(std::abs(img.cols - te mpl.cols) + 1, std::abs(img.rows - templ.rows) + 1) && result.type() == CV_32F