计算轮廓/面积的中心 [英] Calculate the center of a contour/Area

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

问题描述

我正在开发一个图像处理链,它按颜色和轮廓分离单个对象,然后计算该对象的y位置。

I'm working on a Image-processing chain that seperates a single object by color and contour and then calculates the y-position of this object.

如何使用OpenCV计算轮廓或区域的中心?

How do I calculate the center of a contour or area with OpenCV?

Opencv链接:

  • http://opencv.willowgarage.com/wiki/
  • http://en.wikipedia.org/wiki/OpenCV

推荐答案

你可以得到通过首先计算时刻的。然后质量中心由 yc = M01 / M00 给出,其中M01和M00是Moments调用返回的结构中的字段。

You can get the center of mass in the y direction by first calculating the Moments. Then the center of mass is given by yc = M01 / M00, where M01 and M00 are fields in the structure returned by the Moments call.

如果你只想要边界矩形的中心,这也很容易用 BoundingRect 。这会返回一个CvRect,你只需要占据一半的高度。

If you just want the center of the bounding rectangle, that is also easy to do with BoundingRect. This returns you a CvRect and you can just take half of the height.

如果这不够精确,请告诉我,我可以在某个地方找到示例代码对你而言。

Let me know if this isn't precise enough, I have sample code somewhere I can dig up for you.

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

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