#点p_x, p_y 围绕center_x, center_y顺时针旋转angle度
import cv2
import math
import numpy as np
import os
def get_degree(p1, p0):
aaa = math.degrees(math.atan2((p1[1] - p0[1]), (p1[0] - p0[0])))
if aaa < 0:
aaa = 360 + aaa
aaa = (aaa + 90)
if aaa > 360:
aaa = aaa - 360
return aaa
def rotate_image(box_points, angle, scale=1.):
c_x=box_points[0][0]
c_y=box_points[0][1]
rot_mat = cv2.getRotationMatrix2D((c_x, c_y), angle, scale)
rot_move = np.dot(rot_mat, np.array([0, 0, 0]))
rot_mat[0, 2] += rot_move[0]
rot_mat[1, 2] += rot_move[1]
new_box_points = []
for point in box_points:
new_points = []
p_x, p_y = point[2],point[3]
point1 = np.dot(rot_mat, np.array([p_x, p_y, 1]))
new_points.append((point1))
new_box_points.append(new_points)
return ne
|