def rotate_bboxes(image, obj_list, angle):
'''
Rotates the bounding boxes of the given objects by the given angle. The bounding box will be
translated into absolute coordinates. Therefore the image (resp. its shape) is needed.
'''
rotated_obj_list = []
cosOfAngle = np.cos(2 * np.pi / 360 * -angle)
sinOfAngle = np.sin(2 * np.pi / 360 * -angle)
image_shape = np.array(np.atleast_3d(image).shape[0:2][::-1])
rot_mat = np.array([[cosOfAngle, -sinOfAngle], [sinOfAngle, cosOfAngle]])
for obj in obj_list:
obj_name = obj[0]
upper_left = obj[1]['upper_left'] * image_shape
lower_right = obj[1]['lower_right'] * image_shape
upper_left = AugmentationCreator._rotate_vector_around_point(image_shape/2, upper_left, rot_mat) / image_shape
lower_right = AugmentationCreator._rotate_vector_around_point(image_shape/2, lower_right, rot_mat) / image_shape
rotated_obj_list.append((obj_name, {'upper_left' : upper_left, 'lower_right' : lower_right}))
return rotated_obj_list
评论列表
文章目录