title: How to automatically rotate a misoriented image in OpenCV?
body: <p>i have two Sample Image rotated 5 degree &amp; 17 degree clockwise. how to code to tell the system to [1] firstly, calculate the degree of rotation automatically [2] secondly, rotate back the Sample Image to 0 degree automatically [3] thirdly, compare the automatically rotated Sample Image with Template Image </p>
  
  <p>i have the following code but i got an error message ''invalid character in identifier'':</p>
  
  <pre><code>import numpy as np
  import cv2
  
  img = cv2.imread("rotated 17 degree-Sample Image-defect.png",0)
  
  def rotateImage(img, angle):
    img_center = tuple(np.array(img.shape)/2)
    rot = cv2.getRotationMatrix2D(img_center,angle,1.0)
    result = cv2.warpAffine(img,rot,img.shape,flags=cv2.INTER_LINEAR)
    return result
  
  img2 = cv2.imwrite("automatically rotated.png",result)
  
  img3 = cv2.imread("Template Image.png")
  img4 = cv2.imread("automatically rotated.png")
  
  difference = cv2.subtract(img3, img4)
  
  result = np.any(difference) 
  
  if result is True:
      print ("The images are the same")
  else:
      cv2.imshow("result.jpg", difference)
      print ("the images are different")﻿ 
  </code></pre>
  
  <p>I am new to opencv &amp; python. Please consider including your correction into my code. thank you</p>