1. 程式人生 > >OpenCV講堂 Python Opencv旋轉圖片90度

OpenCV講堂 Python Opencv旋轉圖片90度

1.圖片旋轉90度

方法一:cv2針對<class 'numpy.ndarray'>

import numpy as np
import cv2
 
img=cv2.imread("/home/lisa/dataset/HandDataSet_720_1280/lisa/image/0.jpg",1)
cv2.imshow("temp",img)
cv2.waitKey(0)
 
img90=np.rot90(img)  逆時針旋轉90度
 
cv2.imshow("rotate",img90)
cv2.waitKey(0)

 

其他方法

https://blog.csdn.net/qq_37674858/article/details/80708393

https://blog.csdn.net/qq_37674858/article/details/80708393

def rotate(image, angle, center=None, scale=1.0): #1
    (h, w) = image.shape[:2] #2
    if center is None: #3
        center = (w // 2, h // 2) #4
 
    M = cv2.getRotationMatrix2D(center, angle, scale) #5
 
    rotated = cv2.warpAffine(image, M, (w, h)) #6
 

方法一:Image針對<class 'PIL.Image.Image'>

 

image = image.rotate(-90)  # -90是順時針旋轉90度