Opencv notes-implementación simple de rotación de imágenes

Rotación de imagen:
En opencv, primero obtenga la matriz de rotación según el ángulo y centro de rotación, y luego transforme según la matriz de rotación
Parámetros:
Inserte la descripción de la imagen aquíCódigo de implementación:

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
# 中文显示配置
plt.rcParams['font.sans-serif']=['SimHei']      # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False        # 用来正常显示负号

# 载入图片
img0 = cv.imread("img/img1.jpeg")
rows, cols = img0.shape[:2]

# 图像旋转
# 生成旋转矩阵:旋转中心,旋转角度,缩放比例
M = cv.getRotationMatrix2D((cols/2,rows/2),90,1)
# 进行旋转变换
dst = cv.warpAffine(img0,M,(cols,rows))

# 图像展示
fig, axes = plt.subplots(nrows=1,ncols=2,figsize=(10,8),dpi=100)
axes[0].imshow(img0[:,:,::-1])
axes[0].set_title("原图")
axes[1].imshow(dst[:,:,::-1])
axes[1].set_title("旋转后结果")
plt.show()

Resultados de la carrera:
Inserte la descripción de la imagen aquícv Xiaobaiwang big guy apuntando

Supongo que te gusta

Origin blog.csdn.net/weixin_45666249/article/details/114946117
Recomendado
Clasificación