我正在用python / opencv中的代码制作自定义虚拟现实耳机。我需要能够扭曲图像以创建“桶形失真” /“径向失真”效果。
一些图片说明:
我已经有了要使用并显示给用户的source_image
,并且已经将它们并排放置。现在我只需要类似out = cv2.createBarrelDistortion(source_image, params)
的东西。 (而且我不介意能够调整一些参数,例如畸变的中心,畸变的大小等,因此无论我得到什么定制镜头,我都可以使其看起来正确。)
任何帮助,不胜感激!
最佳答案
这是在Python Wand 0.5.9中执行的操作
(http://docs.wand-py.org/en/0.5.9/index.html)
输入:
from wand.image import Image
import numpy as np
import cv2
with Image(filename='checks.png') as img:
print(img.size)
img.virtual_pixel = 'transparent'
img.distort('barrel', (0.2, 0.0, 0.0, 1.0))
img.save(filename='checks_barrel.png')
# convert to opencv/numpy array format
img_opencv = np.array(img)
# display result with opencv
cv2.imshow("BARREL", img_opencv)
cv2.waitKey(0)
结果:
有关相同的示例和参数的讨论,请参见https://imagemagick.org/Usage/distorts/#barrel。
有关Python / OpenCV方法,请参见https://hackaday.io/project/12384-autofan-automated-control-of-air-flow/log/41862-correcting-for-lens-distortions。
关于python - 如何使用Python OpenCV创建此镜筒/径向变形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60609607/