title: Rotation of a detected rectangle in an image
body: <p>I need to extract a detected rectangle from an image. Rectangles are rotated in arbitrary degrees which are unknown. I have seen this post: <a href="https://i.stack.imgur.com/q9lXj.jpg" rel="nofollow noreferrer">How to straighten a rotated rectangle</a></p>
  
  <p>But there are two problems: </p>
  
  <ol>
  <li>How to calculate 'theta', which is solvable mathematically.</li>
  <li>The code snippet in this post works only for <code>cv</code> not <code>cv2</code>. </li>
  </ol>
  
  <p>Anybody have better solutions than this post? A solution completely developed in <code>cv2</code></p>
  
  <p>I have used RotateRect function. In both cases I have detected the rectangles and draw them. The problem is the angle. In both cases angels are detected negative. at least one of them should be positive. That,s why I can not rotate them correctly according to link. Please take a look at the photos I attached to the question.
  <a href="https://i.stack.imgur.com/q9lXj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q9lXj.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/RBu2n.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RBu2n.jpg" alt="enter image description here"></a></p>