1. Image scaling: resize (src, dst, dsize, fx, fy, interpolation)
Src: image source (image path)
Dsize: the size of the target (how large to zoom to)
Fx: scaling factor of x-axis
Fy: scaling factor of y-axis
Dsize conflicts with fx and fy. If dsize is set, it is unnecessary to set fx and fy.
Interpolation: difference algorithm, which includes the following (specific algorithm for image scaling)
INTER_ NEAREST, proximity difference, fast speed, poor effect
INTER_ LINEAR, bilinear interpolation, default algorithm, fast speed and good effect
INTER_ CUBIC, three times difference, slightly lower speed, slightly better effect
INTER_ AREA, the best effect and the slowest speed
2. Flip of image: flip (img, flipCode) Img: specific image to flip
FlipCode:flipCode==0是上下翻转,flipCode>0是左右翻转,flipCode<0是上下加左右翻转
3. Image rotation: rotate (img, rotateCode) Img: specific image to rotate
RotateCode: the following values
ROTATE_ 90_ CLOCKWISE, 90 ° clockwise rotation
ROTATE_ 90180 ° rotation
ROTATE_ 90_ CUTERCLOCKWISE, 270 ° rotation
import cv2 from cv2 import ROTATE_90_CLOCKWISE import numpy as np # 导入一张图片 img=cv2.imread('20220627214919.jpg') # 缩放图片 new_img=cv2.resize(img,dsize=None,fx=0.3,fy=0.3,interpolation=cv2.INTER_AREA) # 翻转图片 new_img1=cv2.flip(img,-1) # 旋转图片 new_img2=cv2.rotate(img,rotateCode=ROTATE_90_CLOCKWISE) # 显示图片 cv2.imshow('new_img',new_img) cv2.imshow('img',img) cv2.imshow('new_img1',new_img1) cv2.imshow('new_img2',new_img2) cv2.waitKey(0)