def matrixPicture(face, eyes, height, width):
"""calculation of rotation and movement of the image"""
center = tuple((face[0] + (face[2] / 2), face[1] + (face[3] / 2)))
moveMatrix = np.float32([[1, 0, (width / 2) - center[0]],
[0, 1, (height / 2) - center[1]]])
scale = float(min(height, width)) / float(face[2]) * facescale
eye1 = tuple((eyes[0][0] + (eyes[0][2] / 2),
eyes[0][1] + (eyes[0][3] / 2)))
eye2 = tuple((eyes[1][0] + (eyes[1][2] / 2),
eyes[1][1] + (eyes[1][3] / 2)))
x = (float(eye2[0]) - float(eye1[0]))
y = (float(eye2[1]) - float(eye1[1]))
if x == 0:
angle = 0
else:
angle = atan(y / x) * 180 / pi
rotMatrix = cv2.getRotationMatrix2D(center, angle, scale)
return moveMatrix, rotMatrix
评论列表
文章目录