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.
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.
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.
Contour area is given by the function cv. contourArea() or from moments, M['m00'].
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With