使用 OpenCV 去失真/校正图像 [英] Undistorting/rectify images with OpenCV

查看:38
本文介绍了使用 OpenCV 去失真/校正图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从本书中获取了校准相机和不失真图像的代码示例:shop.oreilly.com/product/9780596516130.do

I took the example of code for calibrating a camera and undistorting images from this book: shop.oreilly.com/product/9780596516130.do

据我了解,OpenCV 的常用相机校准方法非常适用于普通"相机.当涉及到鱼眼镜头时,虽然我们必须使用 8 个校准参数而不是 5 个向量以及方法 cvCalibrateCamera2 中的标志 CV_CALIB_RATIONAL_MODEL.至少,它在 OpenCV 纪录片

As far as I understood the usual camera calibration methods of OpenCV work perfectly for "normal" cameras. When it comes to Fisheye-Lenses though we have to use a vector of 8 calibration parameters instead of 5 and also the flag CV_CALIB_RATIONAL_MODEL in the method cvCalibrateCamera2. At least, that's what it says in the OpenCV documentary

所以,当我在这样的一组图像上使用它时(来自 OCamCalib 的示例图像)我使用 cvInitUndistortMap 得到以下结果:abload.de/img/rastere4u2w.jpg

So, when I use this on an array of images like this (Sample images from OCamCalib) I get the following results using cvInitUndistortMap: abload.de/img/rastere4u2w.jpg

由于生成的图像是从整个未失真的图像中剪下的,我继续使用 cvInitUndistortRectifyMap(就像这里描述的那样 stackoverflow.com/questions/8837478/opencv-cvremap-cropping-image).所以我得到了以下结果:abload.de/img/rasterxisps.jpg

Since the resulting images are cut out of the whole undistorted image, I went ahead and used cvInitUndistortRectifyMap (like it's described here stackoverflow.com/questions/8837478/opencv-cvremap-cropping-image). So I got the following results: abload.de/img/rasterxisps.jpg

现在我的问题是:为什么整个图像没有失真?在我后来结果的一些照片中,您可以识别出例如笔记本电脑仍然完全失真.如何使用标准 OpenCV 方法获得更好的结果?

And now my question is: Why is not the whole image undistorted? In some pics of my later results you can recognize that the laptop for example is still totally distorted. How can I acomplish even better results using the standard OpenCV methods?

我是 stackoverflow 的新手,我也是 OpenCV 的新手,所以在表达我的问题时,请原谅我的任何不足之处.

I'm new to stackoverflow and I'm new to OpenCV as well, so please excuse any of my shortcomings when it comes to expressing my problems.

推荐答案

  1. 所有棋盘角都应该是可见的.该算法需要一定大小的棋盘,例如 4x3 或 7x6(例如).棋盘周围的白色边框也应该可见,否则可能无法精确定义深色方块.

  1. All chessboard corners should be visible to be found. The algorithm expect a certain size of chessboard such as 4x3 or 7x6 (for example). The white border around a chess board should be visible too or dark squares may not be defined precisely.

在 undistort() 之后,您在图像外围仍然有很高的失真,因为失真是径向的(即它们随着半径的增加而增加)并且您找到的系数是错误的.后者是错误的,因为校准过程使像素坐标中的平方误差之和最小化,并且您没有用足够的样本表示外围.

You still have high distortions at the image periphery after undistort() since distortions are radial (that is they increase with the radius) and your found coefficients are wrong. The latter are wrong since a calibration process minimizes the sum of squared errors in pixel coordinates and you did not represent the periphery with enough samples.

TODO:如果使用 8 个 distCoeff,则必须有 20-40 个棋盘图案图像.以不同的角度倾斜你的木板,把它们放在不同的距离,然后把它们散开,尤其是在外围.请记住,校准的成功取决于采样以及从您的棋盘(因此 s倾斜和倾斜).

TODO: You have to have 20-40 chess board pattern images if you use 8 distCoeff. Slant your boards at different angles, put them at different distances and spread them around, especially at the periphery. Remember, the success of calibration depends on sampling and also on seeing vanishing points clearly from your chess board (hence slanting and tilting).

这篇关于使用 OpenCV 去失真/校正图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆