1

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

我了解 minmaxLoc 函数可用于查找最佳匹配的位置。但它是否也说明了这场比赛的实际表现如何?(如果是,您将如何发现?)

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

我是简单地取所有 minmax-locations 的平均值还是你有什么建议?

opencv中的模板匹配函数示例

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

1 回答 1

1

您可以尝试使用一些相似性指标,例如PSNR 或 SSIM

另一个链接

于 2014-07-12T18:38:22.237 回答