title: Count shapes that may have holes in them
body: <p>I am trying to count the number of shapes in an image.<br>
  I have followed this <a href="http://www.pyimagesearch.com/2014/10/20/finding-shapes-images-using-python-opencv/" rel="nofollow noreferrer" title="tutorial">tutorial</a> and I am using getContours</p>
  
  <pre><code>contours, h = cv2.findContours(255 * oBW.copy().astype('uint8'), 
                                    cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
  </code></pre>
  
  <p>When my original image is:<br>
  <img src="https://i.stack.imgur.com/K6FpF.png" alt="Original"></p>
  
  <p>oBW is the inverted image:<br>
  <img src="https://i.stack.imgur.com/G8rbX.png" alt="Inverted"></p>
  
  <p>I want to find two shapes (the two squares):<br>
  <img src="https://i.stack.imgur.com/TWjqr.png" alt="Two Squares"></p>
  
  <p>But instead I am getting 4...<br>
  First:<br>
  <img src="https://i.stack.imgur.com/Ce3KC.png" alt="First"></p>
  
  <p>Second:<br>
  <img src="https://i.stack.imgur.com/TqjZY.png" alt="Second"></p>
  
  <p>Third:<br>
  <img src="https://i.stack.imgur.com/YQS2x.png" alt="Third"></p>
  
  <p>And Fourth:<br>
  <img src="https://i.stack.imgur.com/RidzX.png" alt="Fourth"></p>
  
  <p>How can I get only the two black shapes?<br>
  Thanks.</p>