如何使用OpenCV的归一化相关? [英] How to use OpenCV's normalized correlation?

查看:138
本文介绍了如何使用OpenCV的归一化相关?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用OpenCV的归一化相关?任何人都可以提供代码示例?

How do I use OpenCV's normalized correlation? Could anyone provide a code sample?

我的问题:
我有一个螺钉头图像,需要找到拧。所以我想使用OpenCV相关性,这是一个好主意吗?

My problem: I have a screw head image and need to find the center of the screw. So I am thinking of using OpenCV correlation, is that a good idea?

你可以在下面的链接找到一个示例图片:

You can find an example image under the link below:

http://imageshack.us/photo/my-图片/ 685 / screw1.png /

请为我提供OpenCV中的相关代码示例。如何使用?相关函数的输出是什么?相关函数是否提供螺丝位置?

Please provide me with a code sample for correlation in OpenCV. How is it used? What is the output of the correlation function? Will the correlation function provide the screw location?

推荐答案

我想你正在寻找 cv :: matchTemplate function:

I think you are looking for cv::matchTemplate function:

cv::Mat image;  // Your input image
cv::Mat templ;  // Your template image of the screw 
cv::Mat result; // Result correlation will be placed here

// Do template matching across whole image
cv::matchTemplate(image, templ, result, CV_TM_CCORR_NORMED);

// Find a best match:
double minVal, maxVal;
cv::Point minLoc, maxLoc;
cv::minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc);

// Regards to documentation the best match is in maxima location
// (http://opencv.willowgarage.com/documentation/cpp/object_detection.html)

// Move center of detected screw to the correct position:  
cv::Point screwCenter = maxLoc + cv::Point(templ.cols/2, templ.rows/2);

这篇关于如何使用OpenCV的归一化相关?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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