python--opencv图像旋转

python–opencv图像旋转

cv2.getRatationMatrix2D(center,angle,scale)

import os
import cv2
import numpy as np
import matplotlib.pyplot as plt
def read_img(img_7_path,img_8_path):
    img=cv2.imread(img_7_path)
    h,w=img.shape[:2]
    M=cv2.getRotationMatrix2D((w/2,h/2),45,0.6)
    rotate=cv2.warpAffine(img,M,(w,h))

    cv2.imshow('img',img)
    cv2.imshow('rotation',rotate)
    cv2.waitKey()
    cv2.destroyAllWindows()
if __name__ == '__main__':
    work_path = os.getcwd()
    data_path = os.path.join(work_path, 'data')
    img_7_path = os.path.join(data_path, '7.jpg')
    img_8_path = os.path.join(data_path, '8.jpg')
    read_img(img_7_path,img_8_path)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qestion_yz_10086/article/details/107914062