face2movie.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:face2movie 作者: Stunkymonkey 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号