python-opencv-旋转

 


import cv2

img = cv2.imread('3.jpg', 1)
cv2.imshow('src', img)
imgInfo = img.shape
height= imgInfo[0]
width = imgInfo[1]
deep = imgInfo[2]
matRotate = cv2.getRotationMatrix2D((width*0.5, height*0.5), 45, 0.9) # 旋转变化矩阵
'''
参数1 必选参数。用于设置旋转中心点,点坐标为OpenCV图像坐标系下的坐标。
参数2 必选参数。用于设置旋转的角度,单位为度。
参数3 必选参数。用于设置缩放系数,即对旋转的图像进行缩放。
'''
dst = cv2.warpAffine(img, matRotate, (width,height)) #旋转
'''
参数2 变换矩阵:是一个2行3列的矩阵,由这个矩阵决定是何种变换
参数3 变换后输出图像的大小:(width,height)-->宽和高(自己规定)
'''
cv2.imshow('dst',dst)


cv2.waitKey(0)
 

效果图:

 

 

 

 

posted @ 2020-01-20 08:27  天子骄龙  阅读(3557)  评论(0编辑  收藏  举报