加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何使用OpenCV的规范化关联?

发布时间:2020-12-16 10:22:29 所属栏目:百科 来源:网络整理
导读:如何使用OpenCV的规范化关联?任何人都可以提供代码示例吗? 我的问题: 我有一个螺丝头图像,需要找到螺丝的中心.所以我在考虑使用OpenCV相关性,这是一个好主意吗? 您可以在以下链接下找到示例图片: http://imageshack.us/photo/my-images/685/screw1.png/
如何使用OpenCV的规范化关联?任何人都可以提供代码示例吗?

我的问题:
我有一个螺丝头图像,需要找到螺丝的中心.所以我在考虑使用OpenCV相关性,这是一个好主意吗?

您可以在以下链接下找到示例图片:

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

请在OpenCV中向我提供相关的代码示例.怎么用?相关函数的输出是什么?相关函数是否会提供螺钉位置?

解决方法

我想你正在寻找cv :: matchTemplate函数:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读