Using bounding rectangle to get rotation angle not working (OpenCV/Python)
<p>I'm trying to straighten this letter but I'm not sure how to use the bounding rectangle to do so. </p>

<p>Here's what I have so far: </p>

<pre><code>import cv2
import numpy as np

img = cv2.imread('rtes.jpg',0)

ret,thresh = cv2.threshold(img,127,255,0)
ret,contours,hierarchy = cv2.findContours(thresh, 1, 2)

cnt = contours[0]
M = cv2.moments(cnt)
print M
cx = int(M['m10']/M['m00'])
cy = int(M['m01']/M['m00'])
#cnt = contours[2]
#cv2.drawContours(img, [cnt], 0, (0,255,0), 3)
rect = cv2.minAreaRect(cnt)
box = cv2.boxPoints(rect)
box = np.int0(box)
cv2.drawContours(img,[box],0,(255,0,0),2)
cv2.imshow('img',img)

k = cv2.waitKey(0)
if k == 27:         # wait for ESC key to exit
    cv2.destroyAllWindows()
</code></pre>

<p>and here's the result: 
<a href="https://i.stack.imgur.com/p5iSD.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/p5iSD.jpg" alt="enter image description here"></a></p>

<p>I've looked into OpenCV docs to get it working but wasn't able to get it working. I'm trying to eventually write a loop that'll try 4 angles to see if it's straight.</p>