title: How to detect intersecting shapes with OpenCV findContours?
body: <p>I have two intersecting ellipses in a black and white image. I am trying to use OpenCV findContours to identify the separate shapes as separate contours using this code (and attached image below).</p>
  <p><a href="https://i.stack.imgur.com/41CiM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/41CiM.png" alt="original image" /></a></p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  import cv2
  import skimage.morphology
  
  img_3d = cv2.imread(&quot;C:/temp/test_annotation_overlap.png&quot;)
  img_grey = cv2.cvtColor(img_3d, cv2.COLOR_BGR2GRAY)
  contours = cv2.findContours(img_grey, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2]
  
  fig, ax = plt.subplots(len(contours)+1,1, figsize=(5, 20))
  
  thicker_img_grey = skimage.morphology.dilation(img_grey, skimage.morphology.disk(radius=3))
  ax[0].set_title(&quot;ORIGINAL IMAGE&quot;)
  ax[0].imshow(thicker_img_grey, cmap=&quot;Greys&quot;)
  
  for i, contour in enumerate(contours):
      new_img = np.zeros_like(img_grey)
      cv2.drawContours(new_img, contour, -1,  (255,255,255), 10)
      ax[i+1].set_title(f&quot;Contour {i}&quot;)
      ax[i+1].imshow(new_img, cmap=&quot;Greys&quot;)
  
  plt.show()
  </code></pre>
  <p>However four contours are found, none of which are the original contour:</p>
  <p><a href="https://i.stack.imgur.com/kyj1U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kyj1U.png" alt="enter image description here" /></a></p>
  <p>How can I configure OpenCV.findContours to identify the two separate shapes? (Note I have already played around with Hough circles and found it unreliable for the images I am analysing)</p>