title: Contouring a binary mask with OpenCV / Python
body: <p>With Python and OpenCV I am detecting contours of a binary mask:</p>
  
  <pre><code>import numpy as np
  import cv2
  import matplotlib.pyplot as plt
  
  mask = np.zeros(20000, dtype=np.uint8).reshape(100, 200)
  mask[5:-5,5:-5] = 255
  mask[10:70,40:80] = 0
  plt.subplot(121)
  plt.imshow(mask, cmap='Greys_r', interpolation='none')
  
  _, contours, hierarchy = cv2.findContours(mask.copy(), 
                                            cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE,
                                            offset=(0, 0))
  </code></pre>
  
  <p>Resulting in an expected behaviour :</p>
  
  <pre><code>plt.subplot(122)
  cv2.drawContours(mask, contours, -1, (127, 127, 127), 2)
  plt.imshow(mask, cmap='Greys_r',  interpolation='none')
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/zRZgB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zRZgB.png" alt="Simple opencv contouring"></a></p>
  
  <p>However, I cannot seem to understand the result of a full activated mask : </p>
  
  <pre><code>mask = np.ones(20000, dtype=np.uint8).reshape(100, 200)
  mask *=255
  _, contours, hierarchy = cv2.findContours(mask.copy(),
                                              cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE,
                                              offset=(0, 0))
  
  print contours[0]
  </code></pre>
  
  <p>Which produces:</p>
  
  <pre><code>(1   1), (1  98), (198 98), (198 1)
  </code></pre>
  
  <p>instead of <code>(0 0), (0 99), (199, 99), (199, 0)</code></p>
  
  <p>Why is opencv findcontours behaving like that, with an offset of 1?</p>