opencv - 手动校正 OpenCV 中的桶形失真,没有棋盘图像

标签 opencv imagemagick distortion

我从无法使用 OpenCV 拍摄棋盘照片和计算校正矩阵的相机获取图像。到目前为止,我使用带有选项 '-distort Barrel "0.0 0.0 -0.035 1.1"' 的 imagemagick convert 校正了图像,在那里我通过反复试验获得了参数。

现在我想在 OpenCV 中执行此操作,但我在网上找到的只是使用棋盘图像的自动校正。是否有机会像我使用 imagemagick 那样应用一些简单的手动试错镜头畸变校正?

最佳答案

好的,我想我明白了。在矩阵 cam1、cam2 中,图像中心缺失(请参阅文档)。我添加了它并改变了焦距以避免图像尺寸变化太大。这是代码:

  import numpy as np
  import cv2

  src    = cv2.imread("distortedImage.jpg")
  width  = src.shape[1]
  height = src.shape[0]

  distCoeff = np.zeros((4,1),np.float64)

  # TODO: add your coefficients here!
  k1 = -1.0e-5; # negative to remove barrel distortion
  k2 = 0.0;
  p1 = 0.0;
  p2 = 0.0;

  distCoeff[0,0] = k1;
  distCoeff[1,0] = k2;
  distCoeff[2,0] = p1;
  distCoeff[3,0] = p2;

  # assume unit matrix for camera
  cam = np.eye(3,dtype=np.float32)

  cam[0,2] = width/2.0  # define center x
  cam[1,2] = height/2.0 # define center y
  cam[0,0] = 10.        # define focal length x
  cam[1,1] = 10.        # define focal length y

  # here the undistortion will be computed
  dst = cv2.undistort(src,cam,distCoeff)

  cv2.imshow('dst',dst)
  cv2.waitKey(0)
  cv2.destroyAllWindows()

非常感谢您的协助。

关于opencv - 手动校正 OpenCV 中的桶形失真,没有棋盘图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26602981/

相关文章:

imagemagick - 转换 :not authorized `aaaa` @ error/constitute. c/ReadImage/453

opencv - 使用 OpenCV 进行表面投影的图像校正

javascript - 在 Canvas 上挥动文字

svg - 使用固定大小的元素来增长 svg?

imagemagick - 在 ImageMagick 的循环中使用复合

pdf - 使用具有可靠字体选择的 ImageMagick 将 SVG 转换为 PDF?

python - 改进图像分割以创建围绕对象的闭合轮廓

c++ - OpenCV中 "object detection"基于HOG特征的SVM分类器

c++ - openCV,C++ 并发,windows

c++ - 在 C++ 中使用 .at() 使用 OpenCV 扫描图像的异常未处理错误