title: Finding all closed figures using OpenCv in Python
body: <p>I want to find all the closed shapes in the image with sampled points using opencv in python. I got all the contours using cv2.findContours() method and sampled it using cv2.CHAIN_APPROX_SIMPLE. Now if two closed figures share the same boundary, I am unable to segregate them as shown in the figure. The contour is shown in the image below.<br><a href="https://i.stack.imgur.com/yaaYb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yaaYb.jpg" alt="enter image description here"></a></p>
  
  <p>The outer rectangle and the border share the same boundary. So the contour is not giving all the closed figure in such cases. The original figure is shown below:<br>
  <a href="https://i.stack.imgur.com/gDeYW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gDeYW.jpg" alt="enter image description here"></a></p>
  
  <p>The code that I am using is :
  <br></p>
  
  <p><code>im2,contours,hierarchy=cv2.findContours(imagem,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
   count=(len(contours))</code></p>
  
  <p>Please suggest me modifications or some other methods to find out all the closed images in python opencv.</p>