编程语言
首页 > 编程语言> > python open cv 图片的旋转(便于人脸识别检测)

python open cv 图片的旋转(便于人脸识别检测)

作者:互联网

 输入图片,进行旋转,达到校正人脸的目的,提高识别精准度与识别成功率

def rotate_bound(image, angle):
    # grab the dimensions of the image and then determine the
    # center
    (h, w) = image.shape[:2]
    (cX, cY) = (w // 2, h // 2)

    # grab the rotation matrix (applying the negative of the
    # angle to rotate clockwise), then grab the sine and cosine
    # (i.e., the rotation components of the matrix)
    M = cv2.getRotationMatrix2D((cX, cY), -angle, 1.0)
    cos = np.abs(M[0, 0])
    sin = np.abs(M[0, 1])

    # compute the new bounding dimensions of the image
    nW = int((h * sin) + (w * cos))
    nH = int((h * cos) + (w * sin))

    # adjust the rotation matrix to take into account translation
    M[0, 2] += (nW / 2) - cX
    M[1, 2] += (nH / 2) - cY

    # perform the actual rotation and return the image
    return cv2.warpAffine(image, M, (nW, nH))


img1=rotate_bound(img1,anger)   #img1图片资源 anger选择旋转角度输入

 

标签:nH,人脸识别,angle,python,image,cY,rotation,open,img1
来源: https://blog.csdn.net/qq_49835304/article/details/120930992