c中opencv中轮廓/对象的质心? [英] centroid of contour/object in opencv in c?

查看:754
本文介绍了c中opencv中轮廓/对象的质心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一些更好的方法可以在opencv中找到轮廓质心,而无需使用内置函数?

is there some good and better way to find centroid of contour in opencv, without using built in functions?

推荐答案

虽然Sonaten的答案完全正确,但有一种简单的方法:使用专用的opencv函数: ()

While Sonaten's answer is perfectly correct, there is a simple way to do it: Use the dedicated opencv function for that: moments()

http://opencv.itseez.com/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#moments

确实如此不仅返回质心,还有一些关于你的形状的统计数据。您可以发送轮廓或光栅形状(二进制图像),最适合您的需要。

It does not only returns the centroid, but some more statistics about your shape. And you can send it a contour or a raster shape (binary image), whatever best fits your need.

编辑

示例(修改)来自学习OpenCV,由gary bradsky提供

example (modified) from "Learning OpenCV", by gary bradsky

CvMoments moments; 
double M00, M01, M10;

cvMoments(contour,&moments); 
M00 = cvGetSpatialMoment(&moments,0,0); 
M10 = cvGetSpatialMoment(&moments,1,0); 
M01 = cvGetSpatialMoment(&moments,0,1); 
centers[i].x = (int)(M10/M00); 
centers[i].y = (int)(M01/M00); 

这篇关于c中opencv中轮廓/对象的质心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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