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选择旋转角度输入

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

 

上一篇:图像旋转放大缩小


下一篇:毛星云opencv之5.5.8离散傅里叶变换程序