我想使用Python OpenCV在图像上应用捏/鼓凸滤镜。 结果应该类似于此示例:
但我在Python OpenCV中实现这个公式时遇到了困难。
我了解到可以使用映射将滤镜应用于图像:使用OpenCv-python进行失真效果。
就我理解而言,代码可能如下所示:
https://pixijs.io/pixi-filters/tools/screenshots/dist/bulge-pinch.gif
我读了以下stackoverflow的帖子,应该是正确的筛选公式:桶形/枕形失真的公式。但我在Python OpenCV中实现这个公式时遇到了困难。
我了解到可以使用映射将滤镜应用于图像:使用OpenCv-python进行失真效果。
就我理解而言,代码可能如下所示:
import numpy as np
import cv2 as cv
f_img = 'example.jpg'
im_cv = cv.imread(f_img)
# grab the dimensions of the image
(h, w, _) = im_cv.shape
# set up the x and y maps as float32
flex_x = np.zeros((h, w), np.float32)
flex_y = np.zeros((h, w), np.float32)
# create map with the barrel pincushion distortion formula
for y in range(h):
for x in range(w):
flex_x[y, x] = APPLY FORMULA TO X
flex_y[y, x] = APPLY FORMULA TO Y
# do the remap this is where the magic happens
dst = cv.remap(im_cv, flex_x, flex_y, cv.INTER_LINEAR)
cv.imshow('src', im_cv)
cv.imshow('dst', dst)
cv.waitKey(0)
cv.destroyAllWindows()
这是实现示例图像中呈现的扭曲效果的正确方法吗?非常感谢任何有关有用资源或最好是示例的帮助。