I'm trying to find the contours of this image, but the method findContours only returns 1 contour, the contour is highlighted in image 2. I'm trying to find all external contours like these circles where the numbers are inside. What am i doing wrong? What can i do to accomplish it?
image 1:
image 2:
Below is the relevant portion of my code.
thresh = cv2.threshold(image, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
When i change cv2.RETR_EXTERNAL to cv2.RETR_LIST it seems to detect the same contour twice or something like this. Image 3 shows when the border of circle is first detected and then it is detected again as shows image 4. I'm trying to find only outer borders of these circles. How can i accomplish that?












The problem is the flag
cv2.RETR_EXTERNALthat you used in the function call. As described in the OpenCV documentation, this only returns the external contour.Using the flag
cv2.RETR_LISTyou get all contours in the image. Since you try to detect rings, this list will contain the inner and the outer contour of these rings.To filter the outer boundary of the circles, you could use
cv2.contourArea()to find the larger of two overlapping contours.