本文介绍了在OpenCV中手动校正桶形失真,而没有棋盘图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I get images from a camera where it is not possible to take a chessboard picture and calculate the correction matrix using OpenCV. Up to now I corrected the images using imagemagick convert with the option '-distort Barrel "0.0 0.0 -0.035 1.1"' where I got the parameters with trial and error.

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

Now I want to do this inside OpenCV but all I find in the web is the automatic correction using the chessboard image. Is there any chance to apply some simple manual trial and error lens distortion correction as I did with imagemagick?

推荐答案

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

Ok, I think I got it. In the matrices cam1, cam2 the image centers were missing (see documentation). I added it and changed the focal length to avoid a too strong change of image size. Here is the code:

  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中手动校正桶形失真,而没有棋盘图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:26