title: Python Image Rotation
body: <p>I've a code to detect image rotation, it detects only if the image is horizontal or vertical, and if the image is vertical it doesn't detect whether it should be rotated to the right or to the left.</p>
  <pre><code>import cv2
  import numpy as np
  
  
  input_path = 'input_image.jpg'
  image = cv2.imread(input_path)
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  gray = cv2.bitwise_not(gray)
  thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
  coords = np.column_stack(np.where(thresh &gt; 0))
  angle = cv2.minAreaRect(coords)[-1]
  print(angle)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/i6yxB.jpg" rel="nofollow noreferrer">should rotated left</a></p>
  <p><a href="https://i.stack.imgur.com/YuurL.jpg" rel="nofollow noreferrer">should rotated right</a></p>
  <p>in both cases the detected angle is 90</p>
  <p>How do I detect the correct rotation angle in each case, or the English text rotation in the bottom?</p>