图像平移
import cv2
import numpy as np
img = cv2.imread("1.jpg")
rows, cols = img.shape[0], img.shape[1]
# M = np.float ([[1,0,x轴 左向右移动多少],[0,1,y轴 上向下移动多少]]) # 必须是foat32
M = np.float32([[1, 0, 100], [0, 1, 0]])
# 移动函数:参数(原图、平移多少、(背景高、宽))
dst = cv2.warpAffine(img, M, (cols, rows))
cv2.imshow('img', dst)
# 只有在输入移动多少的时候,需要foat32,但平移后的图像依然是uint8类型
print(dst.dtype)
print(img.dtype)
cv2.waitKey(0)
cv2.destroyAllWindows()
图像镜像
# 镜像
img_flip = cv2.flip(img,1)
图像旋转
import cv2 as cv
img = cv.imread(r'2.jpg', 1)
rows, cols, channels = img.shape
rotate = cv.getRotationMatrix2D((rows*0.5, cols*0.5), 45, 1)
'''
第一个参数:旋转中心点
第二个参数:旋转角度
第三个参数:缩放比例
'''
res = cv.warpAffine(img, rotate, (cols, rows))
cv.imshow('res', res)
cv.waitKey(0)
cv.destroyAllWindows()
仿射变换
import numpy as np
import cv2
img = cv2.imread(r'2.jpg')
rows, cols, channels = img.shape
p1 = np.float32([[0, 0], [cols - 1, 0], [0, rows - 1]])
p2 = np

本文详细介绍图像处理中的多种变换技术,包括平移、镜像、旋转、仿射变换及透视变换等,并提供Python代码实例,帮助读者理解每种变换的具体操作过程。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



