图像移位
作者:互联网
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)
标签:img,dst,cv2,imgInfo,图像,np,100,移位 来源: https://www.cnblogs.com/mjn1/p/11215704.html