Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

图像缩放

  • 两种方式
  1. dsize : 元组,传入要缩放图像的宽高
import cv2
img = cv2.imread('img_path')
img1 = cv2.resize(av,dsize=(100,100))
cv2.imshow('img',img)
cv2.imshow('img1',img1)
cv2.waitKey()
cv2.destroyAllWindows()
  1. fx fy 参数,分别 修改横列 缩放系数
import cv2
img = cv2.imread('img_path')
img1 = cv2.resize(img,None,fx=2,fy=2)
cv2.imshow('img',img)
cv2.imshow('img1',img1)
cv2.waitKey()
cv2.destroyAllWindows()

翻转变换

flipCode:

  • >1 沿着y axis左右变换
  • =0 沿着x axis上下变换
  • <0 沿着x axis上下 翻转,再沿着y axis 左右反转
import cv2
img = cv2.imread('img_path')
img1 = cv2.flip(img,flipCode=1)
cv2.imshow('img',img)
cv2.imshow('img1',img1)
cv2.waitKey()
cv2.destroyAllWindows()