image processing图像处理
文章目录
1 image transfomations图像变换
1.1 translation平移
# 格式为[1,0,tx]和[0,1,ty],其中tx和ty分别为横向和纵向,正数表示向下和向右
# 负数表示向上和向左
M = np.float32([[1, 0, 25], [0, 1, 50]])
shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape
[0]))
cv2.imshow("Shifted Down and Right", shifted)
封装成一个函数的写法
# 子函数的写法
import numpy as np
import cv2
def translate(image, x, y):
# 定义平移矩阵
M = np.float32([[1, 0, x], [0, 1, y]])
# 使用warpAffine方法进行变换
shifted = cv2.warpAffine(image, M, (image.shape[1], image.
shape[0]))
return shifted
# 直接调用函数
shifted = imutils.translate(image, 0, 100)
cv2.imshow("Shifted Down", shifted)
cv2.waitKey(0)
1.2 rotation旋转
(height, width) = image.shape[:2]
center = (width//2, height

本文是OpenCV-python图像处理的学习笔记,涵盖了图像变换(平移、旋转、缩放、翻转、裁切),图像算术,位操作,遮罩应用,通道分离与合并,以及色彩空间转换等内容,通过实例讲解了各种操作的实现和应用场景。
最低0.47元/天 解锁文章
4万+

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



