title: straightening contoured rectangles in opencv python
body: <p>I have these images of ICs, on which i have to do some image processing. I am able to find the contour of these images. But sometimes these ICs are rotated randomly. How do I straighten them to a proper regular rectangle?</p>
  
  <p>These are some of my contour detected images:</p>
  
  <p><a href="https://i.stack.imgur.com/jgHGX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jgHGX.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/qUrPE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qUrPE.png" alt="enter image description here"></a></p>
  
  <p>Will be glad, if anyone can get me started on how to rotate back these images to straight rectangle/squares. Thanks in advance :)</p>