使用opencv进行模板匹配成功 [英] Success of template-matching with opencv

查看:192
本文介绍了使用opencv进行模板匹配成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何衡量opencv模板匹配算法的成功?

How do I measure success of the opencv template-matching algorithm ?

我知道minmaxLoc函数可用于找到最佳匹配的位置。但是,这是否也说明了比赛的实际效果如何? (如果是,您将如何找到?)

I understand that the minmaxLoc function can be used to find the location of the best match. But does it also give an indication on how good the match actually was ? (If yes, how would you find out ?)

是否还有一个更合适的函数来衡量找到的匹配项(绿色矩形)和原始模板之间的相关性?例如,如果模板图像与匹配图像中的图像相比稍微旋转或平移了怎么办?

Is there an even more appropriate function to measure the correlation between the found match (green rectangle) and the original template ? For example, what if the template-image is slightly rotated or translated compared to as it can be found in the matching-image ?

我是否只取所有图像的平均值minmax-locations或您会提出什么建议?

Do I simply take the average of all minmax-locations or what would you suggest ?

cv::Mat cv_in_image = [in_image CVMat];
cv::Mat cv_in_template = [in_template CVMat];
cv::Mat output;

// Do some OpenCV stuff with the image

/// Create the result matrix
int result_cols = in_image.size.width - in_template.size.width + 1;
int result_rows = in_image.size.height - in_template.size.height + 1;

output.create(result_rows, result_cols, CV_32FC1);

cv::matchTemplate(cv_in_image, cv_in_template, output, cv::TM_CCORR_NORMED);

cv::normalize(output, output, 0, 1, cv::NORM_MINMAX, -1, cv::Mat());

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

cv::minMaxLoc(output, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat());

/// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better
int match_method;
if(match_method  == cv::TM_SQDIFF || match_method == cv::TM_SQDIFF_NORMED) {
    matchLoc = minLoc;
    NSLog(@"Correlation minVal = %f", minVal);
    NSLog(@"(Correlation maxVal = %f)", maxVal);
}
else {
    matchLoc = maxLoc;
    NSLog(@"Correlation maxVal = %f", maxVal);
    NSLog(@"(Correlation minVal = %f)", minVal);
}

/// Show me what you got

cv::Rect rect1;
rect1.x = matchLoc.x;
rect1.y = matchLoc.y;
rect1.width = cv_in_template.cols;
rect1.height = cv_in_template.rows;

cv::rectangle(cv_in_image, rect1, cv::Scalar::all(0), 2, 8, 0);


推荐答案

您可以尝试使用一些相似性指标,例如< a href = http://www.snip2code.com/Snippet/27600/-C----SSIM---PSNR-quality-metrics-using- rel = nofollow> PSNR或SSIM 。

You can try to use some similarity metrics, like PSNR or SSIM.

另一个链接

这篇关于使用opencv进行模板匹配成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆