【opencv-python】 图像旋转、尺寸变换
顺时针旋转
def Rotate90(img):
trans_img = cv2.transpose(img)
new_img = cv2.flip(trans_img, 1)
return new_img
逆时针旋转
def Rotate_90(img):
trans_img = cv2.transpose( img )
new_img = cv2.flip( trans_img, 0 )
return new_img
尺寸缩放
resize_img = cv2.resize(img,(int(img.shape[1]*.5),int(img.shape[0]*.5)))
cv2.imshow('resize_img', resize_img)
综合程序代码
import cv2
# 顺时针旋转90度
def Rotate90(img):
trans_img = cv2.transpose(img)
new_img = cv2.flip(trans_img, 1)
return new_img
# 逆时针旋转90度
def Rotate_90(img):
trans_img = cv2.transpose( img )
new_img = cv2.flip( trans_img, 0 )
return new_img
def test(img_path):
img = cv2.imread(img_path)
cv2.imshow('raw', img)
clock90_img = Rotate_90(img)
cv2.imshow( 'Rotate90', clock90_img )
clock_90_img = Rotate90(img)
cv2.imshow('Rotate_90', clock_90_img)
resize_img = cv2.resize(img,(int(img.shape[1]*.5),int(img.shape[0]*.5)))
cv2.imshow('resize_img', resize_img)
if __name__ == '__main__':
test('mi.jpg')
cv2.waitKey(0)
cv2.destroyAllWindows()
运行效果
还没有评论,来说两句吧...