Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting the centre of a curved shape with opencv

I've been trying for a while to find the centre of a curved shape (for example a banana). I can do all the basics, such as creating a binary image, and locating the contour. However, the centroid function correctly finds a point outside of the contour. The point I require must be inside the contour. I've attached an image which should explain things better.

If anyone has any ideas, or has seen something similar I would really appreciate some help.

enter image description here

like image 706
Razor Robotics Avatar asked Feb 21 '16 00:02

Razor Robotics


People also ask

What is cv2 arcLength?

cv2. arcLength() is used to calculate the perimeter of the contour. If the second argument is True then it considers the contour to be closed. Then this perimeter is used to calculate the epsilon value for cv2. approxPolyDP() function with a precision factor for approximating a shape.

What is cv2 approxPolyDP?

We make use of a function in OpenCV called approxPolyDP() function to perform an approximation of a shape of a contour. The image of a polygon whose shape of a contour must be approximated is read using the imread() function.

How do you find the contour area in OpenCV?

Contour area is given by the function cv. contourArea() or from moments, M['m00'].


1 Answers

You could look at this answer, What is the fastest way to find the "visual" center of an irregularly shaped polygon?

Basically skeletonisation algorithms should help (in terms of efficiency and accuracy as compared to continuous erosion, which would fail in some cases), since they narrow down the set of possible valid points to a set of line segments, which you can then do some sort of conditional processing on.

like image 160
gunshi Avatar answered Oct 12 '22 21:10

gunshi