opencv学习笔记——图像几何变换

图像几何变换

图像缩放

resize函数

语法格式:dst = cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])

cv2.resize(src, dsize, fx, fy)  # dsize和fx, fy设置一个即可
# src:原图像
# dsize:缩放大小
# fx, fy:缩放比例

图像翻转

语法格式:dst = cv2.flip(src, flipCode)

  • filpCode = 0:上下翻转
  • filpCode > 0:左右翻转
  • filpCode < 0:上下左右翻转
cv2.flip(src, flipCode)

应用

"""
图像缩放
"""
import cv2

color = cv2.imread('image/color.jpg')
cv2.imshow('color', color)

# 按照大小缩放
dst1 = cv2.resize(color, (1000, 500))  # color size -> [500, 1000]
cv2.imshow('dst', dst1)

# 按照比例缩放
dst2 = cv2.resize(color, None, fx=0.5, fy=0.5)  # color size -> [rows*0.5, columns*0.5]
cv2.imshow('dst2', dst2)

cv2.waitKey(0)
cv2.destroyAllWindows()
"""
图像翻转
"""
import cv2

color = cv2.imread('image/color.jpg')
cv2.imshow('color', color)

# 左右翻转
left_right_flip = cv2.flip(color, 1)
cv2.imshow('left_right_flip', left_right_flip)

# 上下翻转
up_down_flip = cv2.flip(color, 0)
cv2.imshow('up_down_flip', up_down_flip)

# 上下左右翻转
up_down_left_right_flip = cv2.flip(color, -1)
cv2.imshow('up_down_left_right_flip', up_down_left_right_flip)

cv2.waitKey(0)
cv2.destroyAllWindows()

你可能感兴趣的:(opencv)