python - 如何使用Python OpenCV创建此镜筒/径向变形?

标签 python opencv computer-vision virtual-reality

我正在用python / opencv中的代码制作自定义虚拟现实耳机。我需要能够扭曲图像以创建“桶形失真” /“径向失真”效果。

一些图片说明:

enter image description here

enter image description here

enter image description here

我已经有了要使用并显示给用户的source_image,并且已经将它们并排放置。现在我只需要类似out = cv2.createBarrelDistortion(source_image, params)的东西。 (而且我不介意能够调整一些参数,例如畸变的中心,畸变的大小等,因此无论我得到什么定制镜头,我都可以使其看起来正确。)

任何帮助,不胜感激!

最佳答案

这是在Python Wand 0.5.9中执行的操作

(http://docs.wand-py.org/en/0.5.9/index.html)

输入:

enter image description here

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)

结果:

enter image description here

有关相同的示例和参数的讨论,请参见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/

相关文章:

python - 从分类器中检索训练功能名称列表

c++ - ffmpeg 是否支持 QTRLE?

python - 如何从OpenCV Python中的图像获取标题

machine-learning - 将复值图像输入神经网络( tensorflow )

opencv - 匹配两个图像的相关图

python - pytesseract 无法按预期识别文本?

python - 在 tkinter 中仅选择文本而不是整行

python - 使用命令时出错 "from polyglot.detect import Detector"

python - 从生成器创建迭代器返回相同的对象

python - 如何获得世界空间中二维点的射线方程