Lens Distortion Correction[通俗易懂]

LensDistortionCorrectionbyShehrzadQureshiSeniorEngineer,BDTIMay14,2011AtypicalprocessingpipelineforcomputervisionisgiveninFigure1below:Thefocusofthisart

大家好,又见面了,我是你们的朋友全栈君。

Lens Distortion Correction

by Shehrzad Qureshi
Senior Engineer, BDTI
May 14, 2011

A typical processing pipeline for computer vision is given in Figure 1 below:

lens distortion figure 1

The focus of this article is on the lens correction block. In less than ideal optical systems, like those which will be found in cheaper smartphones and tablets, incoming frames will tend to get distorted along their edges. The most common types of lens distortions are either barrel distortion, pincushion distortion, or some combination of the two[1]. Figure 2 is an illustration of the types of distortion encountered in vision, and in this article we will discuss strategies and implementations for correcting for this type of lens distortion.

lens distortion figure 2

These types of lens aberrations can cause problems for vision algorithms because machine vision usually prefers straight edges (for example lane finding in automotive, or various inspection systems). The general effect of both barrel and pincushion distortion is to project what should be straight lines as curves. Correcting for these distortions is computationally expensive because it is a per-pixel operation. However the correction process is also highly regular and “embarassingly data parallel” which makes it amenable to FPGA or GPU acceleration. The FPGA solution can be particularly attractive as there are now cameras on the market with FPGAs in the camera itself that can be programmed to perform this type of processing[2].

Calibration Procedure

The rectlinear correction procedure can be summarized as warping a distorted image (see Figure 2b and 2c) to remove the lens distortion, thus taking the frame back to its undistorted projection (Figure 2a). In other words, we must first estimate the lens distortion function, and then invert it so as to compensate the incoming image frame. The compensated image will be referred to as theundistorted image.

Both types of lens aberrations discussed so far are radial distortions that increase in magnitude as we move farther away from the image center. In order to correct for this distortion at runtime, we first must estimate the coefficients of a parameterized form of the distortion function during a calibration procedure that is specific to a given optics train. The detailed mathematics behind this parameterization is beyond the scope of this article, and is covered thoroughly elsewhere[3]. Suffice it to say if we have:

Lens Distortion Correction[通俗易懂]

where:

  • Lens Distortion Correction[通俗易懂]= original distorted point coordinates
  • Lens Distortion Correction[通俗易懂]= image center
  • Lens Distortion Correction[通俗易懂]= undistorted (corrected) point coordinates

then the goal is to measure the distortion model Lens Distortion Correction[通俗易懂] where:

Lens Distortion Correction[通俗易懂]

and:

Lens Distortion Correction[通俗易懂]

The purpose of the calibration procedure is to estimate the radial distortion coefficientsLens Distortion Correction[通俗易懂] which can be achieved using a gradient descent optimizer[3]. Typically one images a test pattern with co-linear features that are easily extracted autonomously with sub-pixel accuracy. The checkerboard in Figure 2a is one such test pattern that the author has used several times in the past. Figure 3 summarizes the calibration process:

lens distortion figure 3

The basic idea is to image a distorted test pattern, extract the coordinates of lines which are known to be straight, feed these coordinates into an optimizer such as the one described in[3], which emits the lens undistort warp coefficients. These coefficients are used at run-time to correct for the measured lens distortion.

In the provided example we can use a Harris corner detector to automatically find the corners of the checkerboard pattern. The OpenCV library has a robust corner detection function that can be used for this purpose[4]. The following snippet of OpenCV code can be used to extract the interior corners of the calibration image of Figure 2a:

const int nSquaresAcross=9;
const int nSquaresDown=7;
const int nCorners=(nSquaresAcross-1)*(nSquaresDown-1);
CvSize szcorners = cvSize(nSquaresAcross-1,nSquaresDown-1);
std::vector<CvPoint2D32f> vCornerList(nCorners);
/* find corners to pixel accuracy */
int cornerCount = 0;
const int N = cvFindChessboardCorners(pImg, /* IplImage */
szcorners,
&vCornerList[0],
&cornerCount);
/* should check that cornerCount==nCorners */
/* sub-pixel refinement */
cvFindCornerSubPix(pImg,
&vCornerList[0],
cornerCount,
vSize(5,5),
cvSize(-1,-1),
cvTermCriteria(CV_TERMCRIT_EPS,0,.001));

Segments corresponding to what should be straight lines are then constructed from the point coordinates stored in the STL vCornerList container. For the best results, multiple lines should be used and it is necessary to have both vertical and horizontal line segments for the optimization procedure to converge to a viable solution (see the blue lines in Figure 3).

Finally, we are ready to determine the radial distortion coefficients. There are numerous camera calibration packages (including one in OpenCV), but a particularly good open-source ANSI C library can be locatedhere[5]. Essentially the line segment coordinates are fed into an optimizer which determines the undistort coefficients by minimizing the error between the radial distortion model and the training data. These coefficients can then be stored in a lookup table for run-time image correction.

Lens Distortion Correction (Warping)

The referenced calibration library[5] also includes a very informativeonline demo. The demo illustrates the procedure briefly described here. Application of the radial distortion coefficients to correct for the lens aberrations basically boils down an image warp operation. That is, for each pixel in the (undistorted) frame, we compute the distance from the image center and evaluate a polynomial that gives us the pixel coordinates from which to fill in the corrected pixel intensity. Because the polynomial evaluation will more than likely fall in between integer pixel coordinates, some form of interpolation must be used. The simplest and cheapest interpolant is so-called “nearest neighbor” which as its name implies means to simply pick the nearest pixel, but this technique results in poor image quality. At a bare minimum bilinear interpolation should be employed and oftentimes higher order bicubic interpolants are called for.

The amount of computations per frame can become quite large, particularly if we are dealing with color frames. The saving grace of this operation is its inherent parallelism (each pixel is completely independent of its neighbors and hence can be corrected in parallel). This parallelism and the highly regular nature of the computations lends itself readily to accelerators, either via FPGAs[6,7] or GPUs[8,9]. The source code provided in[5] includes a lens correction function with full ANSI C source.

A faster software implementation than [5] can be realized using the OpenCVcvRemap() function[4]. The input arguments into this function are the source and destination images, the source to destination pixel mapping (expressed as two floating point arrays), interpolation options, and a default fill value (if there are any holes in the rectilinear corrected image). At calibration time, we evaluate the distortion model polynomials just once and then store the pixel mapping to disk or memory. At run-time the software simply callscvRemap()—which is optimized and can accommodate color frames—to correct the lens distortion.

References

[1] Wikipedia page:  http://en.wikipedia.org/wiki/Distortion_(optics)

[2] http://www.hunteng.co.uk/info/fpgaimaging.htm

[3] L. Alvarez, L. Gomez, R. Sendra. An Algebraic Approach to Lens Distortion by Line Rectification, Journal of Mathematical Imaging and Vision, Vol. 39 (1), July 2009, pp. 36-50.

[4] Bradski, Gary and Kaebler, Adrian. Learning OpenCV (Computer Vision with the OpenCV Library), O’Reilly, 2008.

[5] http://www.ipol.im/pub/algo/ags_algebraic_lens_distortion_estimation/

[6] Daloukas, K.; Antonopoulos, C.D.; Bellas, N.; Chai, S.M. “Fisheye lens distortion correction on multicore and hardware accelerator platforms,”Parallel & Distributed Processing (IPDPS), 2010 IEEE International Symposium on , vol., no., pp.1-10, 19-23 April 2010

[7] J. Jiang , S. Schmidt , W. Luk and D. Rueckert “Parameterizing reconfigurable designs for image warping”,Proc. SPIE, vol. 4867, pp. 86 2002.

[8] http://visionexperts.blogspot.com/2010/07/image-warping-using-texture-fetches.html

[9] Rosner,J., Fassold,H., Bailer,W., Schallauer,P.: “Fast GPU-based Image Warping and Inpainting for Frame Interpolation”, Proceedings of Computer Graphics, Computer Vision and Mathematics (GraVisMa) Workshop, Plzen, CZ, 2010

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/126183.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 桌面太单调?一起用Python做个自定义动画挂件,好玩又有趣!

    桌面太单调?一起用Python做个自定义动画挂件,好玩又有趣!前言前段时间,写了篇博客关于Python自制一款炫酷音乐播放器。有粉丝问我,音乐播放器为什么要用PyQt5,效果是不是比Tkinter赞?PyQt5真的可以实现这些炫酷的UI画面吗?之前没接触过PyQt5,能不能多分享一些这方面的开发案例?今天就带大家,一起用Python的PyQt5开发一个有趣的自定义桌面动画挂件,看看实现的动画挂件效果!下面,我们开始介绍这个自定义桌面动画挂件的制作过程。一、核心功能设计总体来说,我们需要实现将自己喜欢的动态图gif或者视频转成一个桌面动画挂件,并且可以通过鼠

    2022年4月25日
    54
  • burpsuite小米手机抓包_Android 7.0+手机burpsuite抓包https

    burpsuite小米手机抓包_Android 7.0+手机burpsuite抓包https记录一下以后可能会遇到的此类问题的解决方案。方法1:系统证书目录:/system/etc/security/cacerts/其中的每个证书的命名规则如下:.文件名是一个Hash值,而后缀是一个数字。文件名可以用下面的命令计算出来:opensslx509-subject_hash_old-in后缀名的数字是为了防止文件名冲突的,比如如果两个证书算出的Hash值是一样的话,那么一个证书的后缀名…

    2022年5月30日
    62
  • 科研伦理与学术规范期末考试1题库「建议收藏」

    科研伦理与学术规范期末考试1题库「建议收藏」**科研伦理与学术规范期末考试1题库**自行复制到自己的文档当中便于搜索1.科研伦理与学术规范引论科研伦理与学术规范引论试题1、下列说法错误的是?A、所有的规范的评判都涉及到“善恶正邪”的价值判断B、伦理学已经从传统的以人为中心走向现代的以行为为中心C、现代伦理学主要关注以行为、准则、规范、义务D、规范则未必均是在道德层面上具有调整性参考答案:A2、哈佛模式下的引证规范的特点是?A、注释引证式B、插句式C、循环数字编码式D、MLA引用格式参考答案:B3、关于科研伦理和学术

    2022年7月11日
    15
  • day08(异常处理,创建异常,finally,throws和throw的区别)

    day08(异常处理,创建异常,finally,throws和throw的区别)

    2022年3月6日
    51
  • 电力电子技术 学习总结1

    第二章PPT91以前电力电子器件(PowerElectronicDevice)—可直接用于处理电能的主电路中,实现电能的变换或控制的电子器件。主电路(MainPowerCircuit)—电力电子设备或系统中,直接完成电能变换或控制的电路。广义上电力电子器件可分为电真空器件和半导体器件两类。自20世纪50年代以来,真空管(VacuumValve)仅在频率很高(如微波,数GHz)的大功率高频电源中还在使用,而在大多数电能变换领域,电力半导体器件已取代了汞弧整流器、闸流管等电真空器件

    2022年4月14日
    90
  • mysql成绩用什么类型_数据库里面的数据类型都有哪些

    mysql成绩用什么类型_数据库里面的数据类型都有哪些1、整型取值范围如果加了unsigned,则最大值翻倍,如tinyintunsigned的取值范围为(0~256)。int(m)里的m是表示SELECT查询结果集中的显示宽度,并不影响实际的取值范围,没有影响到显示的宽度,不知道这个m有什么用。2、浮点型(float和double)设一个字段定义为float(5,3),如果插入一个数123.45678,实际数据库里存的是123.457,但总个数还…

    2022年9月15日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号