gpt4 book ai didi

objective-c - 使用openCV在 objective-c 中进行模板匹配

转载 作者:行者123 更新时间:2023-12-02 17:53:30 25 4
gpt4 key购买 nike

我已使用以下代码进行模式识别。但是它给出了错误的匹配结果。请帮助我,这有什么问题。这是用xcode编写的。

Mat img_display;
img.copyTo( img_display );

/// Create the result matrix
int result_cols = img.cols - templ.cols + 1;
int result_rows = img.rows - templ.rows + 1;

result.create( result_cols, result_rows, CV_32FC1 );

/// Do the Matching and Normalize
matchTemplate( img, templ, result, 5 );
normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );

/// Localizing the best match with minMaxLoc
double minVal; double maxVal; Point minLoc; Point maxLoc;
Point matchLoc;

minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() );


/// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better
if( match_method == CV_TM_SQDIFF || match_method == CV_TM_SQDIFF_NORMED )
{
matchLoc = minLoc;
printf("fsf");
}
else
{
matchLoc = maxLoc;
printf("fsf2");
}

/// Show me what you got
rectangle( img_display, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );
//rectangle( result, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );

//imshow( image_window, img_display );
//imshow( result_window, result );

return img_display;

提前致谢 。我已经在这里附上了屏幕截图

最佳答案

您应该替换result.create(result_cols,result_rows,CV_32FC1);
与result.create(result_rows,result_cols,CV_32FC1);

关于objective-c - 使用openCV在 objective-c 中进行模板匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13899811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com