title: OpenCV, cover contour with rectangles
body: <p>how is it possible with OpenCV to cover an irregular shape with multiple rectangles? See example figurs.</p>
  
  <p>The rectangles should be covering max area of the object and can be in any angles. It is important that they do not overlap each other. If rectangle is covering some of the background, it is perfectly OK. </p>
  
  <p>I have found this <a href="https://answers.opencv.org/question/25912/split-contours-into-many-small-rectangles/" rel="nofollow noreferrer">thread</a> who split contours into small rectangles, but they do not merge into biggest rectangle possible. [<a href="https://answers.opencv.org/question/25912/split-contours-into-many-small-rectangles/]" rel="nofollow noreferrer">https://answers.opencv.org/question/25912/split-contours-into-many-small-rectangles/]</a></p>
  
  <p>I do use OpenCV with python, but if you have example code in C++ it is completely fine.</p>
  
  <p><a href="https://i.stack.imgur.com/LBFrB.png" rel="nofollow noreferrer">Before image</a></p>
  
  <p><a href="https://i.stack.imgur.com/68tlg.png" rel="nofollow noreferrer">Wanted result</a></p>