python opencv图片旋转任意角度

python opencv图片旋转任意角度

 

import cv2

# Load the image
img = cv2.imread("20230222100736979.jpg")

# Get the image dimensions
height, width = img.shape[:2]

# Set the rotation angle
angle = 25

# Calculate the rotation matrix
rotation_matrix = cv2.getRotationMatrix2D((width/2, height/2), angle, 1)

# Apply the rotation matrix to the image
rotated_img = cv2.warpAffine(img, rotation_matrix, (width, height))

# Display the rotated image
cv2.imshow("Rotated Image", rotated_img)
cv2.waitKey(0)
cv2.destroyAllWindows()

  

 

####################

posted @ 2023-06-07 19:50  西北逍遥  阅读(218)  评论(0编辑  收藏  举报