Camera calibration basis

The purpose camera calibration is twofold:
first, to restore the position of an object in the camera image of the real world you need to know the world of one of the purposes of the object to the image plane is how to transform the computer, the camera calibration is to figure out this transform relations, solving the internal and external parameter matrix.
Second, the perspective projection camera has a big problem - distortion. Another object is to solve the camera calibration distortion coefficient, and the image for correction.

First, the three coordinate system

Speaking camera calibration, we have to talk about the camera coordinate system, the world coordinate system, the image coordinate system.
Here Insert Picture Description
Here Insert Picture Description
The figure is a schematic diagram of three coordinates, through which you can have an intuitive understanding of the three coordinates.

** world coordinate system (XW, YW, ZW): reference system ** target position of the object. In addition to infinity, the world coordinates can be free-standing or not at the convenience of operation, such as units of length per unit mm.

** camera coordinate system (XC, YC, ZC): ** camera stand on its own coordinate system to measure the angle of the object. The origin of the camera coordinate system of the camera in the light heart, z parallel to the optical axis of the camera. It is the bridgehead contact with the shooting of the object, the object in the world coordinate system must first undergo rigid to change the camera coordinate system, and then the image coordinate system in a relationship. It is the ties between the image coordinates and world coordinates, to communicate the farthest distance in the world. Units of length units such as mm.

** image coordinate system (x, y): ** CCD image plane center is the coordinate origin, in order from the object description of the imaging process the camera coordinate system to the transmission relationship of the projected image coordinate system is introduced, the pixel coordinate system to facilitate further the coordinates. Image coordinate system is a position of a pixel in an image with physical units (e.g. mm).

** pixel coordinate system (u, v): ** upper-left corner of the image plane CCD vertex as an origin, the coordinates of the image point to describe the object is imaged on the digital image (photograph) is introduced, we really from the camera read coordinate system information is located. Pixel coordinate system is in pixels of the image coordinate system.

** Note: ** There are a lot of people have the image coordinate system and pixel coordinates together, known as the three coordinate system, it was also separately, known as the four coordinate system.

1, the image coordinates into pixel coordinates
talking about this, you may ask why have the image coordinate system to build a pixel coordinate system?

我们以图像左上角为原点建立以像素为单位的直接坐标系u-v。像素的横坐标u与纵坐标v分别是在其图像数组中所在的列数与所在行数。
Here Insert Picture Description
由于(u,v)只代表像素的列数与行数,而像素在图像中的位置并没有用物理单位表示出来,所以,我们还要建立以物理单位(如毫米)表示的图像坐标系x-y。将相机光轴与图像平面的交点(一般位于图像平面的中心处,也称为图像的主点(principal point)定义为该坐标系的原点O1,且x轴与u轴平行,y轴与v轴平行,假设(u0,v0)代表O1在u-v坐标系下的坐标,dx与dy分别表示每个像素在横轴x和纵轴y上的物理尺寸,则图像中的每个像素在u-v坐标系中的坐标和在x-y坐标系中的坐标之间都存在如下的关系:Here Insert Picture Description
其中,我们假设物理坐标系中的单位为毫米,那么dx的的单位为:毫米/像素。那么x/dx的单位就是像素了,即和u的单位一样都是像素。为了使用方便,可将上式用齐次坐标与矩阵形式表示为:Here Insert Picture Description
为了让你更直接的理解这一块内容,我们举个例子。由于被摄像机摄物体的图像经过镜头投影到CCD芯片上(像平面),我们设CCD的大小为8x6mm,而拍摄到的图像大小为640x480,则dx=1/80mm/像素,dy=1/80mm/像素,u0=320,v0=240。

上面的矩阵公式运用了齐次坐标,初学者可能会感到有些迷惑。大家会问:怎样将普通坐标转换为齐次坐标呢?齐次坐标能带来什么好处呢?

这里对齐次坐标做一个通俗的解释。此处只讲怎么将普通坐标改写为齐次坐标及为什么引入齐次坐标。这里只做一个通俗但不太严谨的表述。力求简单明了。针对齐次坐标的严谨的纯数学推导,可参见“周兴和版的《高等几何》—1.3拓广平面上的齐次坐标”。玉米曾详细读过《高等几何》这本书,但觉得离计算机视觉有点远,是讲纯数学的投影关系的,较为生涩难懂。

齐次坐标可以理解为在原有坐标后面加一个“小尾巴”。将普通坐标转换为齐次坐标,通常就是在增加一个维度,这个维度上的数值为1。如图像坐标系(u,v)转换为(u,v,1)一样。对于无穷远点,小尾巴为0。注意,给零向量增加小尾巴,数学上无意义。

那么,为什么计算机视觉在坐标运算时要加上这个“小尾巴”呢?

1、 将投影平面扩展到无穷远点。如对消隐点(vanishing point)的描述。

2、 使得计算更加规整

如果用普通坐标来表达的话,会是下面的样子:Here Insert Picture Description
这样的运算形式会给后与运算带来一定的麻烦,所以齐次坐标是一个更好的选择。

齐次坐标还有一个重要的性质,伸缩不变性。即:设齐次坐标M,则αM=M。
我们介绍过了像素坐标系之后,我们再次三大坐标系的问题上。我们想知道这三个坐标系有什么样的关系,我们先从下图说起:Here Insert Picture Description
图中显示,世界坐标系通过刚体变换到达摄像机坐标系,然后摄像机坐标系通过透视投影变换到达图像坐标系。可以看出,世界坐标与图像坐标的关系建立在刚体变换和透视投影变换的基础上。

2、世界坐标系到摄像机坐标系
首先,让我们来看一下刚体变换是如何将世界坐标系与图像坐标系联系起来的吧。这里,先对刚体变换做一个介绍:

刚体变换(regidbody motion):三维空间中, 当物体不发生形变时,对一个几何物体作旋转, 平移的运动,称之为刚体变换。

因为世界坐标系和摄像机坐标都是右手坐标系,所以其不会发生形变。我们想把世界坐标系下的坐标转换到摄像机坐标下的坐标,如下图所示,可以通过刚体变换的方式。空间中一个坐标系,总可以通过刚体变换转换到另外一个个坐标系的。Here Insert Picture Description
下面看一下,二者之间刚体变换的数学表达:Here Insert Picture Description
Here Insert Picture Description
其中,R是3×3的正交单位矩阵(即旋转矩阵),t为平移向量,R、T与摄像机无关,所以称这两个参数为摄像机的外参数(extrinsic parameter),可以理解为两个坐标原点之间的距离,因其受x,y,z三个方向上的分量共同控制,所以其具有三个自由度。

我们假定在世界坐标系中物点所在平面过世界坐标系原点且与Zw轴垂(也即棋盘平面与Xw-Yw平面重合,目的在于方便后续计算),则Zw=0。

3、摄像机坐标系到图像坐标系
首先,让我们来看一下透视投影是如何将图像坐标系与图像坐标系联系起来的吧。这里,先对透视投影做一个介绍:

透视投影(perspective projection): 用中心投影法将形体投射到投影面上,从而获得的一种较为接近视觉效果的单面投影图。有一点像皮影戏。它符合人们心理习惯,即离视点近的物体大,离视点远的物体小,不平行于成像平面的平行线会相交于消隐点(vanish point)

这里我们还是拿针孔成像来说明(除了成像亮度低外,成像效果和透视投影是一样的,但是光路更简单)

下图是针孔-摄像机的基本模型。平面π称为摄像机的像平面,点Oc称为摄像机中心(或光心),f成为摄像机的焦距,Oc为端点且垂直于像平面的射线成为光轴或主轴,主轴与像平面的交点p是摄像机的主点。
Here Insert Picture Description
如图所示,图像坐标系为o-xy,摄像机坐标系为Ox-xcyczc。记空间点Xc摄像机坐标系中的齐次坐标为:Here Insert Picture Description
它的像点m在图像坐标系中的齐次坐标记为:Here Insert Picture Description
根据三角形相似原理,可得:
Here Insert Picture Description
我们使用矩阵表示为:Here Insert Picture Description
注意由于齐次坐标的伸缩不变性,zc[x,y,1]T和(x,y,1)T表示的是同一点。

4、总结
我们已经介绍了各个坐标系之间的转换过程,但是我们想知道的是如何从世界坐标系转换到像素坐标系,因此我们需要把上面介绍到的联系起来:

将三者相乘,可以把这三个过程和在一起,写成一个矩阵:Here Insert Picture Description
我们取世界坐标到图像坐标变换矩阵P如下:Here Insert Picture Description
P就表示了一个投影相机,有下面公式:

其中:Here Insert Picture Description
我们设:Here Insert Picture Description
最后用一幅图来总结从世界坐标系到像素坐标系(不考虑畸变)的转换关系:
Here Insert Picture Description
二、图片矫正
我们在摄像机坐标系到图像坐标系变换时谈到透视投影。摄像机拍照时通过透镜把实物投影到像平面上,但是透镜由于制造精度以及组装工艺的偏差会引入畸变,导致原始图像的失真。因此我们需要考虑成像畸变的问题。

透镜的畸变主要分为径向畸变和切向畸变,还有薄透镜畸变等等,但都没有径向和切向畸变影响显著,所以我们在这里只考虑径向和切向畸变。

径向畸变

顾名思义,径向畸变就是沿着透镜半径方向分布的畸变,产生原因是光线在原理透镜中心的地方比靠近中心的地方更加弯曲,这种畸变在普通廉价的镜头中表现更加明显,径向畸变主要包括桶形畸变和枕形畸变两种。以下分别是枕形和桶形畸变示意图:
Here Insert Picture Description
它们在真实照片中是这样的:
Here Insert Picture Description
像平面中心的畸变为0,沿着镜头半径方向向边缘移动,畸变越来越严重。畸变的数学模型可以用主点(principle point)周围的泰勒级数展开式的前几项进行描述,通常使用前两项,即k1和k2,对于畸变很大的镜头,如鱼眼镜头,可以增加使用第三项k3来进行描述,成像仪上某点根据其在径向方向上的分布位置,调节公式为:
Here Insert Picture Description
式里(x0,y0)是畸变点在像平面的原始位置,(x,y)是畸变较正后新的位置,下图是距离光心不同距离上的点经过透镜径向畸变后点位的偏移示意图,可以看到,距离光心越远,径向位移越大,表示畸变也越大,在光心附近,几乎没有偏移。

Here Insert Picture Description
切向畸变

切向畸变是由于透镜本身与相机传感器平面(像平面)或图像平面不平行而产生的,这种情况多是由于透镜被粘贴到镜头模组上的安装偏差导致。畸变模型可以用两个额外的参数p1和p2来描述:
Here Insert Picture Description
下图显示某个透镜的切向畸变示意图,大体上畸变位移相对于左下——右上角的连线是对称的,说明该镜头在垂直于该方向上有一个旋转角度。
Here Insert Picture Description
径向畸变和切向畸变模型中一共有5个畸变参数,在Opencv中他们被排列成一个5*1的矩阵,依次包含k1、k2、p1、p2、k3,经常被定义为Mat矩阵的形式,如Mat distCoeffs=Mat(1,5,CV_32FC1,Scalar::all(0));这5个参数就是相机标定中需要确定的相机的5个畸变系数。求得这5个参数后,就可以校正由于镜头畸变引起的图像的变形失真,下图显示根据镜头畸变系数校正后的效果:
Here Insert Picture Description
三、张氏标定法

The purpose camera calibration is to establish a relationship between the camera image pixel position and the position of the object space, that is, the relationship between the world coordinate system and the image coordinate system. The method is based on a camera model, camera parameters by solving the model characteristic point coordinates are known, which can recover the starting point of the three-dimensional spatial coordinates, i.e., from the image reconstruction. Therefore, the parameters to be solved include the four parameters, and 5 distortion parameters, as well as external parameter rotation matrix and translation matrix.

"Zhang calibration" refers to the camera calibration methods of teaching Zhang Zhengyou proposed in 1998 a single plane of checkerboard. Zhang calibration method has been packaged as a kit or function is widely used. Zhang calibrated Originally "A Flexible New Technique forCamera Calibration". The method mentioned in this article, provides great convenience for camera calibration, and with high precision. Since calibration may not require special calibration object, you only need to print out a checkerboard.

Above we've got mapping between coordinates of the pixel coordinate system and the world coordinate system, we assume calibration board in the world coordinates zw = 0 plane, the simplification of the foregoing formulas: Here Insert Picture Description
wherein, u, v represents the pixel coordinates coordinates, fx = f / dx, fy = f / dy, u0, x0, γ ( both axes due to manufacturing errors generated deflection parameters, usually small, if the value obtained by the above matrix calculation is the 0 ) denotes a camera internal reference 5, R, t is shown outside the camera parameters, xw, yw, zw represent the coordinates in the world coordinate system.

The relationship between the fx, fy and f is the focal length of the physical: fx = fsx and fy = fsy. Where sx = 1 / dx represents a pixel value of 1 mm and a length in the x direction represents that the pixel / millimeters, fx, fy are calculated in the whole of the camera calibration, not by the calculation formula.

Released eight original articles · won praise 3 · Views 1905

Guess you like

Origin blog.csdn.net/weixin_44017727/article/details/104713656