我正在尝试旋转(对齐)图像,其中P1
包含P2
沿y-axis
注:绿色区域代表原图
注:红色区域代表旋转后的原图
所以我需要计算由P1(x1,y1)
andP2(x2,y2)
和 by定义的线之间的角度y-axis
,
我的代码是:
import cv2
import numpy as np
from math import *
import math
import imutils
height = 500
width = 500
original_image = np.zeros((height,width,3), np.uint8)
original_image[:] = (0,255,0)
x1 = 400
y1 = 50
P1 = (x1, y1)
x2 = 100
y2 = 300
P2 = (x2, y2)
cv2.line(original_image, P1, P2, (0, 0, 0), 3)
deltaY = y1 - y2
deltaX = x1 - x2
angleInDegrees = atan2(deltaY, deltaX) * 180 / math.pi
print(angleInDegrees)
rotated_image = imutils.rotate_bound(original_image, angleInDegrees)
cv2.imshow("Original", original_image)
cv2.imshow("Rotated", rotated_image)
cv2.waitKey(0)
但是我的rotated_image 没有正确对齐
结果如下:
我应该如何解决它?
POPMUISE
相关分类