0

I have a contour in Opencv with a convexity defect (the one in red) and I want to cut that contour in two parts, horizontally traversing that point, is there anyway to do it, so I just get the contour marked in yellow? Image describing the problem

enter image description here

EdChum
  • 376,765
  • 198
  • 813
  • 562
cvguy
  • 433
  • 1
  • 5
  • 6
  • Does your image always have exactly one convex region? Can you show other examples? – Miki Mar 15 '16 at 13:38
  • Draw black line just as on your right image and find contours again. – Andrey Smorodov Mar 15 '16 at 14:04
  • @Miki It has more convex regions, it is actually a hand, what I just want is to remove the fingers, it doesn't have to be perfect, so picking the convex with the biggest Y Coordinate and the right depth will give me the point I'm interested in. – cvguy Mar 15 '16 at 14:15
  • @AndreySmorodov Interesting observation, I will try that. – cvguy Mar 15 '16 at 14:18
  • Have a look at [this answer](http://stackoverflow.com/a/35252058/5008845). Once you remove convexity defects, you should have your result – Miki Mar 15 '16 at 14:27

1 Answers1

0

That's an interesting question. There are some solutions based on how the concavity points are distributed in your image.

1) If such points does not occur at the bottom of the contour (like your simple example). Then here is a pseudo-code.

  1. Find convex hull C of the image I.
  2. Subtract I from C, that will give you the concavity areas (like the black triangle between two white triangles in your example).
  3. The point with the minimum y value in that area gives you the horizontal line to cut.

2) If such points can occur anywhere, you need a more intelligent algorithm which has cut lines that are not constrained by only being horizontal (because the min-y point of that difference will be the min-y of the image). You can find the "inner-most" corner points, and connect them to each other. You can recursively cut the remainder in y-,x+,y+,x- directions. It really depends on the specs of your input.

ilke444
  • 2,641
  • 1
  • 17
  • 31