OpenCV-python学习笔记(二)——image processing图像基本处理

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//
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值