图像移位

 

  

import cv2
import numpy as np

img = cv2.imread('image0.jpg', 1)
cv2.imshow('src', img)

imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]

matShift = np.float32([[1, 0, 100], [0, 1, 200]]) # 2*3
dst = cv2.warpAffine(img, matShift, (height, width))
# 原始图片data信息, 移位矩阵, 图片的info信息
# 移位 矩阵
cv2.imshow('dst', dst)
cv2.waitKey(0)

  

# API 移位原理
# [1, 0, 100], [0, 1, 200] 2*2 2*1
# [[1, 0], [0, 1]] 2*2 A
# [[100], [200]] 2*1 B
# [[x], [y]] C 2*1
# A*C + B = [[1*x+0*y],[0*x+1*y]] + [[100], [200]]
# = [[x+100], [y+200]]

# (10, 20) -> (110, 120)

import cv2
import numpy as np

img = cv2.imread('image0.jpg', 1)
cv2.imshow('src', img)
imgInfo = img.shape
dst = np.zeros(img.shape, np.uint8)
height = imgInfo[0]
width = imgInfo[1]
for i in range(0, height):
    for j in range(0, width-100):
        dst[i, j+100] = img[i, j]

cv2.imshow('image', dst)
cv2.waitKey(0)

  

 

 

posted @ 2019-07-19 20:59  青衫客36  阅读(185)  评论(0编辑  收藏  举报