title: Get the real bounding box of a rectangle shaped mask
body: <p>i have this binary image (numpy array)  that represents an approximation of a rectangle :</p>
  
  <p><a href="https://i.stack.imgur.com/FNrsi.png" rel="noreferrer"><img src="https://i.stack.imgur.com/FNrsi.png" alt="Mask"></a></p>
  
  <p>I'm trying to extract the real shape of the rectangle but can't seem to find a way.
  The expected result is the following:</p>
  
  <p><a href="https://i.stack.imgur.com/Jcwzk.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Jcwzk.jpg" alt="Exected"></a></p>
  
  <p>I'm using this code </p>
  
  <pre><code>contours,_ = cv2.findContours(numpymask.copy(), 1, 1) # not copying here will throw an error
  rect = cv2.minAreaRect(contours[0]) # basically you can feed this rect into your classifier
  (x,y),(w,h), a = rect # a - angle
  
  box = cv2.boxPoints(rect)
  box = np.int0(box) #turn into ints
  rect2 = cv2.drawContours(img.copy(),[box],0,(0,0,255),10)
  
  plt.imshow(rect2)
  plt.show()
  </code></pre>
  
  <p>But the resut i'm getting is the following, which i not what i need : </p>
  
  <p><a href="https://i.stack.imgur.com/Ovq52.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Ovq52.jpg" alt="enter image description here"></a></p>
  
  <p>For this i'm using Python with opencv.</p>