result_img 和 原图一模一样
import cv2
import numpy as np
img = cv2.imread("OpenCV.png")
rows, cols, ch = img.shape
mapx = np.ones(img.shape[:2], np.float32)
mapy = np.ones(img.shape[:2], np.float32)
for i in range(rows):
for j in range(cols):
mapy.itemset((i, j),i)
mapx.itemset((i,j),j)
print(mapx)
print(mapy)
result_img = cv2.remap(img, mapx, mapy, cv2.INTER_LINEAR)
cv2.imshow("img", img)
cv2.imshow("result_img", result_img)
cv2.waitKey()
cv2.destroyAllWindows()
for i in range(rows):
for j in range(cols):
mapx.itemset((i, j),j)
mapy.itemset((i, j),rows-i)
原图: