我正在开发一个基于使用Opencv进行模板匹配的项目。
我正在尝试定义一个从OpenCV函数中得到的点数组
minMaxLoc()
,但我收到了这些错误:
temp.cpp:45:35: error: ‘minval’ was not declared in this scope
temp.cpp:45:44: error: ‘maxval’ was not declared in this scope
temp.cpp:45:53: error: ‘minloc’ was not declared in this scope
temp.cpp:45:62: error: ‘maxloc’ was not declared in this scope
temp.cpp:56:69: error: request for member ‘cols’ in ‘ref_temp’, which is of non-class type ‘cv::Mat [7]’
temp.cpp:56:93: error: request for member ‘rows’ in ‘ref_temp’, which is of non-class type ‘cv::Mat [7]’
make: *** [temp.o] Error 1
这是我写的:
Point minloc_array[7],maxloc_array[7];
double minval, maxval;
Point minloc, maxloc;
int temp_count; for(temp_count=0;temp_count<8;temp_count++)
{
cv::matchTemplate(ref_image, ref_temp[temp_count], des1, CV_TM_CCORR_NORMED);
cv::minMaxLoc(des1, &minval, &maxval, &minloc, &maxloc);
while (true){
double minval, maxval;
Point minloc, maxloc;
if (maxval >= 0.9){
minloc_array[temp_count]= minloc;
maxloc_array[temp_count]= maxloc;
std::cout << "Template Matched " << std::endl ;
cv::rectangle(image,maxloc,cv::Point(maxloc.x + ref_temp[temp_count].cols, maxloc.y+ref_temp[temp_count].rows),CV_RGB(0,255,0),2,8);
break;
}
else
std::cout << "Template NOT Matched" << std::endl ;
break;
}
}
答案 0 :(得分:1)
我可以看到很多问题。
以下是您在注释中添加注释的代码:
41: Point minloc_array[7],maxloc_array[7]; // *** arrays have length 7 (max index is 6)
42: double minval, maxval;
43: Point minloc, maxloc;
44: int temp_count; // *** newline added for readability
44: for(temp_count = 0; temp_count < 8; temp_count++)
// *** should be: temp_count < 7
45: {
46: // *** error message is on this line - is posted code accurate?
47: cv::matchTemplate(ref_image, ref_temp[temp_count], des1, CV_TM_CCORR_NORMED);
48: cv::minMaxLoc(des1, &minval, &maxval, &minloc, &maxloc);
49: while (true){
50: double minval, maxval; // *** hides minval, maxval in outer scope
51: Point minloc, maxloc; // *** likewise
52: if (maxval >= 0.9){
53: minloc_array[temp_count]= minloc;
54: maxloc_array[temp_count]= maxloc;
55: std::cout << "Template Matched " << std::endl ;
56: cv::rectangle(image,maxloc,cv::Point(maxloc.x + ref_temp[temp_count].cols, maxloc.y+ref_temp[temp_count].rows),CV_RGB(0,255,0),2,8);
// *** is ref_temp an array of Cv::Mat??
break;
}
else
std::cout << "Template NOT Matched" << std::endl ;
break;
}
}