愁死了,想同时对img和mask做一个上下左右旋转,竟然找不到一份能用的代码。我提供一份算了。
'''
@Author: haoMax
@Github: https://github.com/liuzehao
@Blog: https://blog.youkuaiyun.com/liu506039293
@Date: 2019-10-10 11:15:18
@LastEditTime: 2019-11-15 16:44:15
@LastEditors: haoMax
@Description:
'''
# -*- coding: utf-8 -*-
import cv2
from math import *
import numpy as np
import os
# 旋转angle角度,缺失背景白色(255, 255, 255)填充
def rotate_bound_white_bg(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)
# -angle位置参数为角度参数负值表示顺时针旋转; 1.0位置参数scale是调整尺寸比例(图像缩放参数),建议0.75
M = cv2.getRotationMatrix2D((cX, cY), -angle, 1.0)