如何在OpenCV中自动旋转错误定向的图像?

时间:2016-12-27 07:07:22

标签: python opencv

我有两个样本图像旋转5度&顺时针17度。如何编码告诉系统[1]首先,自动计算旋转度[2]其次,自动将样品图像旋转回0度[3],第三,将自动旋转的样品图像与模板图像进行比较

我有以下代码,但我收到一条错误消息''''''

;

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") 

我是opencv&的新手。蟒蛇。请考虑将您的更正包含在我的代码中。谢谢

0 个答案:

没有答案