因此,我目前正尝试使用两个因素(Bx和By)在python中剪切图像。问题是当我输入负值时,我会从数组中获得IndexError /超出范围。
我相信我必须做一些填充,但是我不知道将其应用于代码吗?
import cv2
import numpy
#Load the source image
src = cv2.imread("lena.png")
rows, cols, c = src.shape
# x1 = x + y · Bx
# y1 = y + x · By
Bx = 0.0
By = 0.5
imgForward = numpy.ndarray(shape = (int (cols + rows*By), int (rows + cols*Bx), 3))
for row in range(rows):
for col in range(cols):
imgForward[int (row+col*By), int(col+row*Bx)] = src[row,col]/255
cv2.imshow("Forward mapping", imgForward)
cv2.waitKey(0)