江户川乱折腾
您可以使用重新映射。这是一个快速演示,但请注意,您必须知道确切的失真功能才能复制 Photoshop 的功能import cv2 as cvimport numpy as npfrom matplotlib import pyplot as pltimport mathimg = cv.imread('kit.jpg')right_eye = (215,105)radius = 30power = 1.6 # >1.0 for expansion, <1.0 for shrinkageheight, width, _ = img.shapemap_y = np.zeros((height,width),dtype=np.float32)map_x = np.zeros((height,width),dtype=np.float32)# create index mapfor i in range(height): for j in range(width): map_y[i][j]=i map_x[i][j]=j# deform around the right eyefor i in range (-radius, radius): for j in range(-radius, radius): if (i**2 + j**2 > radius ** 2): continue if i > 0: map_y[right_eye[1] + i][right_eye[0] + j] = right_eye[1] + (i/radius)**power * radius if i < 0: map_y[right_eye[1] + i][right_eye[0] + j] = right_eye[1] - (-i/radius)**power * radius if j > 0: map_x[right_eye[1] + i][right_eye[0] + j] = right_eye[0] + (j/radius)**power * radius if j < 0: map_x[right_eye[1] + i][right_eye[0] + j] = right_eye[0] - (-j/radius)**power * radiuswarped=cv.remap(img,map_x,map_y,cv.INTER_LINEAR)cv.imwrite('warp.jpg', warped)