6

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

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Razor Robotics
  • 183
  • 1
  • 9
  • 1
    Visit this http://www.pyimagesearch.com/2016/02/01/opencv-center-of-contour/ – udit043 Feb 21 '16 at 00:18
  • Hello @udit043 thank you for the reply. The examples in that article are only using basic polygons and circles. The shape I am using, results in the centroid being outside of the contour. As is shown in the image. Have you seen an example using a curved shape? – Razor Robotics Feb 21 '16 at 00:23
  • http://stackoverflow.com/questions/12327791/opencv-centroid-of-irregular-shape – udit043 Feb 21 '16 at 00:32
  • how you mathematically represent such point?? Like the point you put is just by some assumption 1 thing is that you want the point to be inside the contour apart from that where exactly you want the point ? – Arijit Feb 21 '16 at 14:39
  • Hello @ArijitMukherjee That is a good question. I'm not sure how I would define the point mathematically, but essentially what I want is a point in the centre of the contour, where the mass on either side of that point is equal. I'm working at the moment on a thinning algorithm, which will erode the contour to a 1 pixel line, I will then find the centre of that line. I really would like to find a faster method though, if you have any ideas? – Razor Robotics Feb 24 '16 at 21:25

1 Answers1

3

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.

Community
  • 1
  • 1
gunshi
  • 66
  • 5