2
OpenCV中的图像平移
source link: https://xugaoxiang.com/2022/07/09/opencv-translation/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
平移就是矩阵的移动,通常,我们需要定义一个 变换矩阵,这是一个2行3列的矩阵
矩阵中的 tx
和 ty
分别代表 x
方向和 y
方向上平移的距离
平移是使用放射变换函数 cv2.warpAffine
来实现的,它的函数原型是
cv2.warpAffine(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]])
src
输入图像M
2行3列变换矩阵dsize
输出图像的大小dst
可选参数,输出图像,也可以作为返回值flags
可选参数,插值方法borderMode
可选参数,边界模式borderValue
可选参数,边界填充值,默认是0
import cv2
import numpy as np
from sqlalchemy import column
image = cv2.imread("lenna.png")
cv2.imshow("original image", image)
column, row, channel = image.shape
# 变换矩阵,x放心移动100,y方向移动50
M = np.float32([[1, 0, 100], [0, 1, 50]])
dst=cv2.warpAffine(image, M, (column, row))
cv2.imshow('dst', dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK