Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 587
shahd Avatar asked Dec 19 '22 17:12

shahd


1 Answers

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;
like image 144
berak Avatar answered Mar 23 '23 06:03

berak