|
|
@@ -166,7 +166,7 @@ def rotate_image_and_coordinates(
|
|
|
new_x2 = orig_width - x1
|
|
|
new_y2 = orig_height - y1
|
|
|
|
|
|
- else: # 任意角度算法,目前90,-90不对
|
|
|
+ else: # 任意角度算法 - 修正版本
|
|
|
# 将角度转换为弧度
|
|
|
angle_rad = np.radians(rotation_angle)
|
|
|
cos_angle = np.cos(angle_rad)
|
|
|
@@ -188,13 +188,13 @@ def rotate_image_and_coordinates(
|
|
|
(x1 - orig_center_x, y2 - orig_center_y) # 左下角
|
|
|
]
|
|
|
|
|
|
- # 应用旋转矩阵变换每个角点
|
|
|
+ # 应用修正后的旋转矩阵变换每个角点
|
|
|
rotated_corners = []
|
|
|
for x, y in corners:
|
|
|
- # 旋转矩阵: [cos(θ) -sin(θ)] [x]
|
|
|
- # [sin(θ) cos(θ)] [y]
|
|
|
- rotated_x = x * cos_angle - y * sin_angle
|
|
|
- rotated_y = x * sin_angle + y * cos_angle
|
|
|
+ # 修正后的旋转矩阵: [cos(θ) sin(θ)] [x]
|
|
|
+ # [-sin(θ) cos(θ)] [y]
|
|
|
+ rotated_x = x * cos_angle + y * sin_angle
|
|
|
+ rotated_y = -x * sin_angle + y * cos_angle
|
|
|
|
|
|
# 转换回绝对坐标(相对于新图像)
|
|
|
abs_x = rotated_x + new_center_x
|