Finding the center of a contour using opencv and visual c++

家住魔仙堡 提交于 2020-01-11 10:32:12

问题


I want to find the center of a contour without doing so much calculations. Is there a built in function for that in opencv?


回答1:


for the 'geometric center', get the boundingRect() of the contour, then:

   cx = br.x+br.width/2; cy = br.y+br.height/2; 

for the 'center of mass' get the moments() of the contour, then:

   cx = m.m10 / m.m00;   cy = m.m01 / m.m00;



回答2:


Either you haven't done any research, or these questions already asked and answered here are not what you are asking:

centroid of contour/object in opencv in c?

OpenCV 2 Centroid

If latter is the case, please elaborate the question in more detail.




回答3:


To answer your question:

There is no built in function. Checkout berak for copypasta code that solves your problem.



来源:https://stackoverflow.com/questions/22399257/finding-the-center-of-a-contour-using-opencv-and-visual-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!