0

I am doing thresholding on an image and I achieve this result: image after thresholding.

Now I would like to achieve only the contour of the biggest oblong shape: oblong shape.

What is the best way to achieve it with OpenCV? I know that the shape has some offshoots. Is there a possibility to get rid of them?

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
MiHu
  • 23
  • 4
  • If your "oblong shape" is always significantly thicker than the offshoots - simply dilate the image until they "fall off", then find the biggest contour. – Headcrab Sep 14 '18 at 02:33

1 Answers1

0

I would suggest that you invert the thresholded image so that the contours are white and the background is black ( cv2.threshold(cv2.THRESH_BINARY_INV)). Then you search for contours with cv2.findContours(). To select your desirable contour you can make some filters to eliminate other contours from the contour you are hoping to find. You can use the filters in a For loop ( for i in contours: ) and with some conditional statements for the filters. For filters you can try the size of contours ( size = cv2.contourArea(i) ) or height and width ( x, y, w, h = cv2.boundingRect(i) ). Then you can make the statements like if size > 100 and h > 100 and w < 50: cv2.drawContours(). Hope it gives you an idea on how to proceed. Cheers!

kavko
  • 2,751
  • 13
  • 27