Hi,
I am rotating the snapshot at various angles to search for face_objects. Then drawing a rectangle around the first face it finds:
for angle in [-15, 15, 30, 30, -45, 45]:
extra_fb.replace(img)
extra_fb.rotation_corr(x_rotation=0.0, y_rotation=0.0, z_rotation=angle)
face_objects = extra_fb.find_features(face_cascade, threshold=0.75, scale_factor=1.25)
if face_objects:
face_angle = angle
face_object = face_objects[0]
img.draw_rectangle(face_object)
I still need to display the original image, so I use extra_fb for the rotation. Predictably, the rectangle is then slightly off. So I’ve tried rotating the rectangle around the center of the image, like this:
def rotate(xy, angle):
theta = math.radians(angle * -1)
cos_theta, sin_theta = math.cos(theta), math.sin(theta)
return (
int(xy[0] * cos_theta - xy[1] * sin_theta),
int(xy[0] * sin_theta + xy[1] * cos_theta)
)
def translate(xy, offset):
return xy[0] + offset[0], xy[1] + offset[1]
x = face_object[0]
y = face_object[1]
width = face_object[2]
height = face_object[3]
rect = [
(x, y),
(x, y + height),
(x + width, y + height),
(x + width, y)
]
frame_center = (int(img_width / 2), int(image_height / 2))
rotated_rect = [translate(rotate(xy, face_angle), offset) for xy in points]
img.draw_line((rotated_rect[0][0], rotated_rect[0][1], rotated_rect[1][0], rotated_rect[1][1]))
img.draw_line((rotated_rect[1][0], rotated_rect[1][1], rotated_rect[2][0], rotated_rect[2][1]))
img.draw_line((rotated_rect[2][0], rotated_rect[2][1], rotated_rect[3][0], rotated_rect[3][1]))
img.draw_line((rotated_rect[3][0], rotated_rect[3][1], rotated_rect[0][0], rotated_rect[0][1]))
But the rotated rectangle also doesn’t align with where the face is in the original, unrotated image. Am I on the right track or is there already a function related to rotation_corr
that I should use?