Fork me on Gitee

opencv 图片位移

 1 import cv2 as cv
 2 import numpy as np
 3 
 4 # 图片移位
 5 img = cv.imread('../images/moon.jpg', flags=1)  # flags=1读取为彩色,flags=0读取为灰度
 6 h, w = img.shape[:2]
 7 mat_shift = np.float32([[1, 0, 100], [0, 1, 200]])  # 移位矩阵,相当于沿x轴平移100,沿y轴平移200
 8 dst = cv.warpAffine(img, mat_shift, (h, w))
 9 cv.imshow('img', dst)
10 cv.waitKey(0)

原理简述

矩阵运算,将[[1, 0, 100], [0, 1, 200]]拆分成两个矩阵A, B

图像矩阵C

 

 

posted @ 2019-02-20 20:00  MARK+  阅读(530)  评论(0编辑  收藏  举报