import cv2
import os
import numpy as np
def flip(image,change_angle):
# Extracting height and width from
# image shape
height, width = image.shape[:2]
print("old image size (wxh)=", (width, height))
# get the center coordinates of the
# image to create the 2D rotation
# matrix
center = ((width-1)/2, (height-1)/2)
# using cv2.getRotationMatrix2D()
# to get the rotation matrix
rotate_matrix = cv2.getRotationMatrix2D(center=center, angle=change_angle, scale=1)
print(rotate_matrix)
bound_w = height * np.abs(rotate_matrix[0,1]) + width * np.abs(rotate_matrix[0,0])
bound_h = height * np.abs(rotate_matrix[0,0]) + width * np.abs(rotate_matrix[0,1])
bound_w = int(round(bound_w, 10))
bound_h = int(round(bound_h, 10))
print("new image size (wxh)=", (bound_w, bound_h))
rotate_matrix[0, 2] += (bound_w-1) / 2 - center[0]
rotate_matrix
Python批量剪切图像并保存
最新推荐文章于 2025-04-24 17:46:29 发布