CN118015095A - A camera calibration algorithm - Google Patents
A camera calibration algorithm Download PDFInfo
- Publication number
- CN118015095A CN118015095A CN202410150485.6A CN202410150485A CN118015095A CN 118015095 A CN118015095 A CN 118015095A CN 202410150485 A CN202410150485 A CN 202410150485A CN 118015095 A CN118015095 A CN 118015095A
- Authority
- CN
- China
- Prior art keywords
- coordinate system
- camera
- image
- point
- matrix
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/80—Analysis of captured images to determine intrinsic or extrinsic camera parameters, i.e. camera calibration
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T5/00—Image enhancement or restoration
- G06T5/20—Image enhancement or restoration using local operators
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/20—Special algorithmic details
- G06T2207/20024—Filtering details
- G06T2207/20028—Bilateral filtering
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Length Measuring Devices By Optical Means (AREA)
Abstract
本发明公开了一种相机标定算法,涉及非接触式测量技术领域,包括:采用改进的Harris角点检测算法从受电弓图像提取角点,利用提取的角点和成像模型,采用张氏标定法估计相机内参和畸变参数;使用相机内参和畸变参数对受电弓图像进行畸变矫正;采用改进的Harris角点检测算法提取畸变矫正后的受电弓图像中的特征点,并构造匹配的特征点对;使用匹配的特征点对,根据成像模型估计受电弓图像间的几何变换关系;根据受电弓图像间的几何变换关系,对受电弓图像进行矫正。本发明易于操作,不会对图像角点进行平滑,提高了Harris角点检测结果的精度,且选择合适的邻域大小也能够提升精度。
The present invention discloses a camera calibration algorithm, which relates to the field of non-contact measurement technology, including: using an improved Harris corner detection algorithm to extract corner points from a pantograph image, using the extracted corner points and an imaging model, using Zhang's calibration method to estimate camera intrinsic parameters and distortion parameters; using the camera intrinsic parameters and distortion parameters to perform distortion correction on the pantograph image; using the improved Harris corner detection algorithm to extract feature points in the pantograph image after distortion correction, and constructing matching feature point pairs; using the matching feature point pairs, estimating the geometric transformation relationship between pantograph images according to the imaging model; and correcting the pantograph image according to the geometric transformation relationship between pantograph images. The present invention is easy to operate, does not smooth the image corner points, improves the accuracy of the Harris corner detection result, and selecting a suitable neighborhood size can also improve the accuracy.
Description
技术领域Technical Field
本发明涉及非接触式测量技术领域,具体而言,涉及一种相机标定算法。The present invention relates to the field of non-contact measurement technology, and in particular to a camera calibration algorithm.
背景技术Background technique
受电弓是列车最为主要的受流装置之一,它的主要功能是使得列车获取电能。由于其功能特征,碳滑板与接触线采用滑动摩擦接触形式,因此碳滑板在使用过程中处于不断磨损状态,为保障列车运行安全应当及时更换超过磨耗界限的碳滑板;同时列车在运行过程中,由于受电弓的结构特性将发生左右偏移现象,过大的中心线偏移难以保障受电弓的正常工作,因此对受电弓中心线偏移进行检测,及时发现可能存在的安全问题具有重要意义。The pantograph is one of the most important current-collecting devices of the train, and its main function is to enable the train to obtain electrical energy. Due to its functional characteristics, the carbon slide plate and the contact line adopt the form of sliding friction contact, so the carbon slide plate is in a state of continuous wear during use. In order to ensure the safety of train operation, the carbon slide plate that exceeds the wear limit should be replaced in time; at the same time, during the operation of the train, due to the structural characteristics of the pantograph, the pantograph will deviate left and right. Excessive centerline deviation makes it difficult to ensure the normal operation of the pantograph. Therefore, it is of great significance to detect the centerline deviation of the pantograph and discover possible safety problems in time.
为了对受电弓中心线偏移进行检测,需要利用相机获取受电弓相关图像。In order to detect the pantograph centerline deviation, a camera is needed to obtain the pantograph related images.
在计算机视觉中,三维空间物体投影到平面图形的过程称为成像模型,大量研究资料表明,摄像机成像模型可以用针孔模型代替。为描述成像模型,将坐标系分为世界坐标系、相机坐标系和图像坐标系。将世界坐标系旋转和平移便得到相机坐标系,但是由于镜头工艺、安装等因素的影响,相机在成像过程中并不是理想的针孔成像模型,成像过程中将发生偏移,即透视畸变。畸变修正又称为相机标定,常见的相机标定分为相机自标定法、主动视觉标定法和基于标定物的标定法,三种标定方法应当根据检测场景与检测需求进行合理选择。In computer vision, the process of projecting a three-dimensional object onto a plane figure is called an imaging model. A large amount of research data shows that the camera imaging model can be replaced by a pinhole model. To describe the imaging model, the coordinate system is divided into a world coordinate system, a camera coordinate system, and an image coordinate system. The camera coordinate system is obtained by rotating and translating the world coordinate system. However, due to factors such as lens technology and installation, the camera is not an ideal pinhole imaging model during the imaging process, and an offset will occur during the imaging process, which is perspective distortion. Distortion correction is also called camera calibration. Common camera calibration methods are divided into camera self-calibration method, active vision calibration method, and calibration method based on calibration objects. The three calibration methods should be reasonably selected according to the detection scene and detection requirements.
现有的相机标定算法,在进行特征点提取时,有的采用了Harris角点检测算法。其原理是通过滑动窗口像素变化来实现角点检测。对于图像f(x,y)取任意大小窗口W,在点(x,y)处平移Δx与Δy,在考虑局部特性变化情形下,滑动前后窗口中像素点的灰度变换公式描述如下:Some existing camera calibration algorithms use the Harris corner detection algorithm when extracting feature points. The principle is to detect corners by sliding window pixel changes. For an image f(x, y), take an arbitrary size window W, translate Δx and Δy at the point (x, y), and consider the change of local characteristics. The grayscale transformation formula of the pixel points in the window before and after sliding is described as follows:
式中,Δx与Δy表示窗口W滑动前后的偏移量,(x,y)是W对应的像素点坐标,w(x,y)表示加权函数,最简单的权重系数均为1,有时也将w(x,y)函数设定为以窗口中心为原点的二元正态分布。将变换公式根据泰勒展开,将图像在平移Δx与Δy后进行一阶近似为:In the formula, Δx and Δy represent the offset of window W before and after sliding, (x, y) is the pixel coordinate corresponding to W, w(x, y) represents the weighting function, the simplest weight coefficient is 1, and sometimes the w(x, y) function is set to a binary normal distribution with the center of the window as the origin. The transformation formula is expanded according to Taylor, and the image is approximated to the first order after translation Δx and Δy:
f(x+Δx,v+Δy)≈f(u,v)+fx(u,v)Δx+fy(u,v)Δyf(x+Δx,v+Δy)≈f(u,v)+ fx (u,v)Δx+ fy (u,v)Δy
带入滑动前后窗口中像素点的灰度变换公式中化简得:Substitute it into the grayscale transformation formula of the pixel points in the window before and after sliding and simplify it to get:
式中,fx,fy分别为窗口内像素点(x,y)在x和y方向上的梯度值,M为Harris矩阵,由于像素点是否为角点是由图像梯度变换进行体现,因此通过分析M矩阵的两个特征值λ1和λ2可以判断是否为角点,通常对每个窗口计算一个R值进行角点响应度量,根据R值大小来判断窗口内是否存在角点,计算公式如下:Where fx , fy are the gradient values of the pixel point (x, y) in the window in the x and y directions respectively, and M is the Harris matrix. Since whether a pixel point is a corner point is reflected by the image gradient transformation, the two eigenvalues λ1 and λ2 of the M matrix can be analyzed to determine whether it is a corner point. Usually, an R value is calculated for each window to measure the corner response. The R value is used to determine whether there is a corner point in the window. The calculation formula is as follows:
R=det(M)-k(trace(M))2 R = det(M) - k(trace(M)) 2
式中,k为灵敏参数,通常0.04<k<0.06,detM=λ1λ2,traceM=λ1+λ2。因此,Harris角点检测算法评判标准为:Where k is a sensitive parameter, usually 0.04<k<0.06, detM=λ 1 λ 2 , traceM=λ 1 +λ 2 . Therefore, the evaluation criteria of the Harris corner detection algorithm are:
1)当R趋于0,窗口内无角点;1) When R approaches 0, there are no corner points in the window;
2)当R>0,窗口内有角点,且R越大角点特征越明显;2) When R>0, there are corner points in the window, and the larger R is, the more obvious the corner point features are;
3)当R<0,窗口内含有边缘。3) When R < 0, the window contains an edge.
然而现今的Harris角点检测采用高斯滤波对图像进行平滑处理,高斯窗口过小达不到滤波效果容易造成伪角点产生,高斯窗口过大使得图像平滑容易造成角点位置发生偏移;同时,Harris算法精度为像素级,即检测到的角点位置为像素位置,当图像质量不高时容易造成较大误差。However, the current Harris corner detection uses Gaussian filtering to smooth the image. If the Gaussian window is too small, the filtering effect cannot be achieved and pseudo corners may be generated. If the Gaussian window is too large, the image smoothing may cause the corner position to shift. At the same time, the accuracy of the Harris algorithm is pixel-level, that is, the detected corner position is the pixel position, which may cause large errors when the image quality is not high.
根据成像原理,当相机与物体之间的距离不相同时,距离越远的物体在图像上所占有的像素个数越少,像元尺寸越大。而当被拍摄物体与相机存在一定夹角并且物体两端与相机距离不同的情形下,最终成像会显示成一种“近大远小”的现象,即透视形变,一般可采用仿射变换修正,而受电弓图像不具备仿射变换特征,因此为测量精确本发明提出一种像元尺寸标定方法。According to the imaging principle, when the distance between the camera and the object is different, the farther the object is, the fewer pixels it occupies on the image, and the larger the pixel size. When there is a certain angle between the object and the camera and the distances between the two ends of the object and the camera are different, the final image will show a phenomenon of "larger near and smaller far", that is, perspective deformation, which can generally be corrected by affine transformation. However, the pantograph image does not have the affine transformation feature. Therefore, in order to measure accurately, the present invention proposes a pixel size calibration method.
发明内容Summary of the invention
本发明在于提供一种相机标定算法,其能够解决上述问题。The present invention provides a camera calibration algorithm, which can solve the above problems.
为了解决上述的问题,本发明采取的技术方案如下:In order to solve the above problems, the technical solution adopted by the present invention is as follows:
本发明提供了一种相机标定算法,包括:The present invention provides a camera calibration algorithm, comprising:
采用Harris角点检测算法从受电弓图像提取角点,采用双边滤波过滤噪声,利用提取的角点和成像模型,采用张氏标定法估计相机内参和畸变参数;Harris corner detection algorithm is used to extract corners from pantograph images, bilateral filtering is used to filter noise, and Zhang calibration method is used to estimate camera intrinsic parameters and distortion parameters using the extracted corners and imaging model.
使用相机内参和畸变参数对受电弓图像进行畸变矫正;Use camera intrinsic parameters and distortion parameters to correct the pantograph image distortion;
采用Harris角点检测算法提取畸变矫正后的受电弓图像中的特征点,并构造匹配的特征点对;Harris corner detection algorithm is used to extract feature points in the pantograph image after distortion correction, and matching feature point pairs are constructed.
使用匹配的特征点对,根据成像模型估计受电弓图像间的几何变换关系;Using the matched feature point pairs, the geometric transformation relationship between the pantograph images is estimated according to the imaging model;
根据受电弓图像间的几何变换关系,对受电弓图像进行矫正,采用像元尺寸标定方法来修正透视形变使测量结果更加准确;According to the geometric transformation relationship between pantograph images, the pantograph images are corrected, and the pixel size calibration method is used to correct the perspective deformation to make the measurement results more accurate.
其中,Harris角点检测算法采用双边滤波,相比高斯滤波在过滤噪声的同时不会对图像角点进行平滑,从而提高Harris角点检测结果的精度;亚像素级角点提取,设q点为所求的像素级角点坐标,在其邻域内有两种类型的p点,一种是梯度值G0为0的p0点,第二种便是处于边缘的p1点,该点梯度不为0,但是与q、p1向量垂直。因此,对于q点邻域内的任意点pi,设其梯度值为Gi,再根据不同pi点与q点之间的距离不同引入权重ωi,则得到唯一q点,即:Among them, the Harris corner detection algorithm uses bilateral filtering. Compared with Gaussian filtering, it does not smooth the image corners while filtering noise, thereby improving the accuracy of Harris corner detection results; sub-pixel corner extraction, let q point be the pixel-level corner coordinates required, there are two types of p points in its neighborhood, one is the p 0 point with a gradient value G 0 of 0, and the second is the p 1 point on the edge, the gradient of which is not 0, but is perpendicular to the q and p 1 vectors. Therefore, for any point p i in the neighborhood of point q, let its gradient value be G i , and then introduce weights ω i according to the different distances between different p i points and point q, and then get a unique q point, that is:
具体地,成像模型通过对坐标系的分类来描述,将世界坐标系、相机坐标系、图像坐标系和像素坐标系之间的关系模型作为成像模型,为:Specifically, the imaging model is described by classifying the coordinate system, and the relationship model among the world coordinate system, the camera coordinate system, the image coordinate system and the pixel coordinate system is taken as the imaging model, which is:
式中,fx=f/dx,fy=f/dy,uo为两平面坐标系原点在x轴方向上的距离,vo为像素坐标系原点和图像坐标系原点在y轴方向上的距离,像素在u轴与v轴方向的实际物理距离分别为dx,dy,fx、fy、uo、vo统称为相机内参,R、T为相机的外参。In the formula, fx = f/ dx , fy = f/ dy , uo is the distance between the origins of the two plane coordinate systems in the x-axis direction, vo is the distance between the origins of the pixel coordinate system and the origins of the image coordinate system in the y-axis direction, the actual physical distances of the pixels in the u-axis and v-axis directions are dx and dy respectively, fx , fy , uo , and vo are collectively referred to as camera intrinsic parameters, and R and T are camera extrinsic parameters.
具体地,畸变分为径向畸变和切向畸变;Specifically, distortion is divided into radial distortion and tangential distortion;
径向畸变使用主点周围的泰勒级数展开式子的前两项k1和k2进行描述,径向畸变矫正公式如下:The radial distortion is described using the first two terms k1 and k2 of the Taylor series expansion around the principal point. The radial distortion correction formula is as follows:
式中,(x,y)为畸变点在图像上的位置,(x′,y′)为畸变矫正后的位置,r为像素点到图像中心点的距离,即r2=x2+y2,k1、k2为径向畸变参数;Where (x, y) is the position of the distortion point on the image, (x′, y′) is the position after distortion correction, r is the distance from the pixel to the center of the image, that is, r 2 = x 2 + y 2 , k 1 and k 2 are radial distortion parameters;
切向畸变矫正公式如下:The tangential distortion correction formula is as follows:
式中,p1、p2为切向畸变系数。Where p 1 and p 2 are tangential distortion coefficients.
具体地,将世界坐标系(Xw,Yw,Zw)置于于标定板上,使得世界坐标系中Zw=0,则四种坐标系的关系可以简化为:Specifically, the world coordinate system ( Xw , Yw , Zw ) is placed on the calibration plate so that Zw = 0 in the world coordinate system. Then the relationship between the four coordinate systems can be simplified as follows:
式中,s=1/Zc,M为相机内参矩阵;设矩阵sM[R1R2T]的单应性矩阵为H,H定义如下:Where s = 1/Z c , M is the camera intrinsic parameter matrix; let the homography matrix of the matrix sM[R 1 R 2 T] be H, which is defined as follows:
当标定板图像的角点数量大于等于4时,通过角点检测得到标定板图像上角点的像素坐标(u,v),同时标定板的物理尺寸大小已知,即可得到该标定板图像所对应的矩阵H,再由H求出相机的内外参数。又旋转矩R的前两列R1、R2存在单位正交性关系,即:When the number of corner points of the calibration plate image is greater than or equal to 4, the pixel coordinates (u, v) of the corner points on the calibration plate image are obtained by corner point detection. At the same time, the physical size of the calibration plate is known, and the matrix H corresponding to the calibration plate image can be obtained. Then the internal and external parameters of the camera are calculated from H. The first two columns R 1 and R 2 of the rotation moment R have a unit orthogonal relationship, that is:
又由H和R1、R2之间的关系可得到:From the relationship between H and R 1 and R 2 , we can get:
带入矩阵H中可得:Substituting into the matrix H, we get:
记N=Zc 2M-TM-1为对称矩阵,则通过求解出矩阵N便可以求解出相机内参矩阵M。将相机内参矩阵M的逆矩阵带入N=Zc 2M-TM-1中有:Let N = Z c 2 M - TM -1 be a symmetric matrix. Then, by solving the matrix N, we can solve the camera intrinsic parameter matrix M. Substituting the inverse matrix of the camera intrinsic parameter matrix M into N = Z c 2 M - TM -1 , we have:
由于H已知,每张标定板图片可以提供一个约束关系,由带入矩阵H后的式子可知N为对称矩阵,求解N则需要3张标定板图像,根据N与相机内参的对应关系解得ZC。Since H is known, each calibration plate image can provide a constraint relationship. From the formula after substituting into the matrix H, we can know that N is a symmetric matrix. Solving N requires three calibration plate images. According to the corresponding relationship between N and the camera intrinsic parameters, Z C is solved.
与现有技术相比,本发明的有益效果是:Compared with the prior art, the present invention has the following beneficial effects:
本发明对相机标定进行实验,采用重投影误差进行评价,而且改进的Harris角点检测算法精度更高,从而能够提升检测系统的检测精度,使分析数据可靠、准确。The present invention experiments on camera calibration and uses reprojection error for evaluation. In addition, the improved Harris corner detection algorithm has higher accuracy, thereby improving the detection accuracy of the detection system and making the analysis data reliable and accurate.
1)基于标定物的张氏标定法使用二维方格组成的标定板进行相机标定,精度高且易于操作;1) Zhang’s calibration method based on calibration objects uses a calibration plate composed of two-dimensional grids for camera calibration, which is highly accurate and easy to operate;
2)采用双边滤波即非线性滤波,算法包含空域矩阵与值域矩阵两部分,空域矩阵可类比高斯滤波用于模糊去噪,值域矩阵根据灰度相似性得到用来保护边缘,这样在过滤噪声的同时不会对图像角点进行平滑,从而提高Harris角点检测结果的精度;2) Bilateral filtering, i.e. nonlinear filtering, is used. The algorithm includes two parts: spatial matrix and range matrix. The spatial matrix can be used for fuzzy denoising similar to Gaussian filtering. The range matrix is obtained based on grayscale similarity and is used to protect the edge. In this way, the image corners will not be smoothed while filtering the noise, thereby improving the accuracy of Harris corner detection results.
3)通过亚像素级角点的提取,可得出获得到的像素级角点坐标不仅与初始点坐标有关,还与选取的像素级角点坐标的邻域大小有关,因此,选择合适的邻域大小具有提升精度的作用;3) Through the extraction of sub-pixel corner points, it can be concluded that the obtained pixel-level corner point coordinates are not only related to the initial point coordinates, but also to the neighborhood size of the selected pixel-level corner point coordinates. Therefore, choosing a suitable neighborhood size has the effect of improving accuracy;
4)在实施方式中对本发明方案所述的相机标定算法进行实验,采用重投影误差进行评价。重投影误差即理论像素点a与畸变矫正后的测量点像素点a′的欧氏距离||a-a′||2,重投影误差越小反应相机标定结果越好。根据实验结果表明,两种算法的重投影误差中棋盘格照片数量的累加并不会明显提升相机标定结果精度,因为角点检测精度不仅与算法有关,还与图像的质量有关。然而,在棋盘格照片数量相同的情况下,改进的Harris角点检测算法的重投影误差更小,两者精度相差及其明显,即改进后的角点检测算法精度更高,从而能够提升检测系统的检测精度;4) In the implementation manner, the camera calibration algorithm described in the solution of the present invention is experimented and evaluated using the reprojection error. The reprojection error is the Euclidean distance between the theoretical pixel point a and the measured pixel point a′ after distortion correction ||aa′|| 2. The smaller the reprojection error, the better the camera calibration result. According to the experimental results, the accumulation of the number of checkerboard photos in the reprojection error of the two algorithms does not significantly improve the accuracy of the camera calibration results, because the accuracy of corner point detection is not only related to the algorithm, but also to the quality of the image. However, when the number of checkerboard photos is the same, the reprojection error of the improved Harris corner point detection algorithm is smaller, and the difference in accuracy between the two is very obvious, that is, the improved corner point detection algorithm has higher accuracy, thereby improving the detection accuracy of the detection system;
5)在实施方式中,为避免成像过程中产生的透视形变,采用一种像元尺寸标定方法进行修正,使测量碳滑板图像更加精确。5) In the implementation method, in order to avoid perspective deformation during the imaging process, a pixel size calibration method is used for correction to make the measurement of the carbon slide plate image more accurate.
为使本发明的上述目的、特征和优点能更明显易懂,下文特举本发明实施例,并配合所附附图,作详细说明如下。In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the embodiments of the present invention are specifically cited below and described in detail with reference to the attached drawings.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本发明实施例的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,应当理解,以下附图仅示出了本发明的某些实施例,因此不应被看作是对范围的限定,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他相关的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
图1成像坐标系关系示意图,成像模型分为世界坐标系(Xw,Yw,Zw),相机坐标系(Xc,Yc,Zc),图像坐标系(x,y),像素坐标系(u,v)。Figure 1 is a schematic diagram of the relationship between imaging coordinate systems. The imaging model is divided into the world coordinate system ( Xw , Yw , Zw ), the camera coordinate system ( Xc , Yc , Zc ), the image coordinate system (x, y), and the pixel coordinate system (u, v).
图2为两种算法的重投影误差。Figure 2 shows the reprojection errors of the two algorithms.
图3为控制邻域大小的重投影误差。Figure 3 shows the reprojection error of controlling the neighborhood size.
图4为左右碳滑板图像纵向像元尺寸变化趋势图。Figure 4 is a graph showing the longitudinal pixel size variation trend of the left and right carbon slide images.
具体实施方式Detailed ways
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments.
本实施方式提供一种相机标定改进算法,操作步骤如下:This embodiment provides an improved camera calibration algorithm, and the operation steps are as follows:
步骤1:改进Harris角点检测算法。Step 1: Improve the Harris corner detection algorithm.
为了有效的避免高斯滤波在过滤噪声的同时对受电弓图像角点进行平滑,从而提高Harris角点检测结果的精度,本发明采用的Harris角点检测算法的改进点如下:In order to effectively avoid the Gaussian filter from smoothing the pantograph image corners while filtering noise, thereby improving the accuracy of the Harris corner detection result, the improvements of the Harris corner detection algorithm used in the present invention are as follows:
(1)双边滤波为非线性滤波,相比高斯滤波在过滤噪声的同时不会对图像角点进行平滑,从而提高Harris角点检测结果的精度。(1) Bilateral filtering is a nonlinear filtering. Compared with Gaussian filtering, it does not smooth the image corners while filtering noise, thereby improving the accuracy of Harris corner detection results.
双边滤波是一种非线性滤波器,算法包含空域矩阵与值域矩阵两部分,空域矩阵可类比高斯滤波用于模糊去噪,值域矩阵根据灰度相似性得到用来保护边缘。定义式如下:Bilateral filtering is a nonlinear filter. The algorithm consists of two parts: the spatial matrix and the range matrix. The spatial matrix can be used for fuzzy denoising similar to Gaussian filtering, and the range matrix is obtained based on grayscale similarity to protect edges. The definition is as follows:
式中,双边滤波的空间域定义如下:In the formula, The spatial domain of bilateral filtering is defined as follows:
像素域定义如下:The pixel domain is defined as follows:
式中,S为选取的矩阵框;q为输入像素点;m、n分别为输入像素点的横纵坐标;I(m,n)为输入像素值;p为方框中心像素点;i、j分别为方框中心像素点的横纵坐标;I(i,j)为方框中心像素值;为输出像素值大小;σs、σr为自定义值。Where S is the selected matrix box; q is the input pixel point; m and n are the horizontal and vertical coordinates of the input pixel point respectively; I (m, n) is the input pixel value; p is the center pixel point of the box; i and j are the horizontal and vertical coordinates of the center pixel point of the box respectively; I (i, j) is the center pixel value of the box; is the output pixel value size; σ s and σ r are custom values.
(2)亚像素角点提取,设q点为所求的像素级角点坐标,在其邻域内有两种类型的p点,一种是梯度值G0为0的p0点,第二种便是处于边缘的p1点,该点梯度不为0,但是与q、p1向量垂直。因此,对于q点邻域内的任意点pi,设其梯度值为Gi,根据不同pi点与q点之间的距离不同而引入不同的权重值ωi,则得到唯一q点位置,公式定义如下:(2) Sub-pixel corner point extraction, let q be the pixel-level corner point coordinates to be sought. There are two types of p points in its neighborhood. One is p0 with a gradient value G0 of 0, and the other is p1 at the edge. The gradient of this point is not 0, but it is perpendicular to the q and p1 vectors. Therefore, for any point p i in the neighborhood of point q, let its gradient value be G i , and introduce different weight values ω i according to the different distances between different p i points and point q, then the unique position of point q is obtained. The formula is defined as follows:
式中,获取到的q点不仅与初始q点坐标有关,还与选取的q点邻域大小有关,选择合适的邻域大小具有提升精度作用。In the formula, the obtained q point is not only related to the initial q point coordinates, but also to the selected q point neighborhood size. Choosing a suitable neighborhood size can improve the accuracy.
步骤2:采用改进的Harris角点检测算法从受电弓图像提取角点,利用提取的角点和成像模型,采用张氏标定法估计相机内参和畸变参数。Step 2: Use the improved Harris corner detection algorithm to extract corner points from the pantograph image. Using the extracted corner points and the imaging model, the Zhang calibration method is used to estimate the camera intrinsic parameters and distortion parameters.
在本发明中,成像模型分为世界坐标系(Xw,Yw,Zw),相机坐标系(Xc,Yc,Zc),图像坐标系(x,y),像素坐标系(u,v),四种坐标系关系示意图如图1所示。In the present invention, the imaging model is divided into a world coordinate system ( Xw , Yw , Zw ), a camera coordinate system ( Xc , Yc , Zc ), an image coordinate system (x, y), and a pixel coordinate system (u, v). The relationship diagram of the four coordinate systems is shown in FIG1.
世界坐标系用以描述物体实际坐标,相机坐标系是连接图像物理坐标系与世界坐标系的桥梁,图像坐标系表示像素在图像的位置,像素坐标系为图像坐标系的缩放与平移。The world coordinate system is used to describe the actual coordinates of the object. The camera coordinate system is the bridge connecting the image physical coordinate system and the world coordinate system. The image coordinate system represents the position of the pixel in the image, and the pixel coordinate system is the scaling and translation of the image coordinate system.
设将世界坐标系绕Zw轴旋转θ角矩阵表达式:Suppose the matrix expression of rotating the world coordinate system around the Z w axis by an angle of θ is:
设绕三个方向的旋转矩阵为R=RXRYRZ。平移矩阵表达式为:Assume that the rotation matrix around three directions is R = R X R Y R Z. The translation matrix expression is:
则世界坐标系转为相机坐标系的矩阵形式为:The matrix form of converting the world coordinate system to the camera coordinate system is:
世界坐标系、相机坐标系、图像坐标系、像素坐标系四种坐标系的数学表达式为:The mathematical expressions of the four coordinate systems: world coordinate system, camera coordinate system, image coordinate system, and pixel coordinate system are:
图像坐标系与像素坐标系为单位不一的平面坐标系,设像素在u轴与v轴方向的实际物理距离分别为dx,dy,则有:The image coordinate system and the pixel coordinate system are plane coordinate systems with different units. Assuming that the actual physical distances of pixels in the u-axis and v-axis directions are d x and dy respectively, we have:
可得图像坐标系与像素坐标系的关系为:The relationship between the image coordinate system and the pixel coordinate system is:
因此,世界坐标系、相机坐标系、图像坐标系、像素坐标系四种坐标系之间的关系模型,即成像模型为:Therefore, the relationship model between the four coordinate systems, namely the world coordinate system, the camera coordinate system, the image coordinate system, and the pixel coordinate system, is the imaging model:
在本发明中,采用张氏标定法估计相机内参和畸变参数。In the present invention, Zhang's calibration method is used to estimate camera intrinsic parameters and distortion parameters.
将世界坐标系(Xw,Yw,Zw)置于标定板上,即有Zw=0,则公式:Place the world coordinate system ( Xw , Yw , Zw ) on the calibration board, that is, Zw = 0, then the formula is:
式中,s=1/Zc,M为相机内参矩阵。Where, s = 1/Z c , and M is the camera intrinsic parameter matrix.
设矩阵sM[R1R2R3]的单应性矩阵为H,H定义如下:Let the homography matrix of the matrix sM[R 1 R 2 R 3 ] be H, which is defined as follows:
当标定板图像的角点数量大于等于4时,通过角点检测得到标定板图像上的角点坐标(u,v),同时标定板的物理尺寸大小已知,即可得到该标定板图像所对应的矩阵H,再由H求出相机的内外参数。又旋转矩R的前两列R1、R2存在单位正交性关系,即:When the number of corner points of the calibration plate image is greater than or equal to 4, the corner point coordinates (u, v) on the calibration plate image are obtained by corner point detection. At the same time, the physical size of the calibration plate is known, and the matrix H corresponding to the calibration plate image can be obtained. Then the internal and external parameters of the camera are calculated from H. The first two columns R 1 and R 2 of the rotation moment R have a unit orthogonal relationship, that is:
又由H和R1、R2之间的关系可得到:From the relationship between H and R 1 and R 2 , we can get:
联系上式可得:Connecting the above formula, we can get:
记N=Zc 2M-TM-1为对称矩阵,则通过求解出矩阵N便可以求解出相机内参矩阵M。将M矩阵的逆矩阵带入N=Zc 2M-TM-1中有:Let N = Z c 2 M -TM -1 be a symmetric matrix. Then, by solving the matrix N, we can solve the camera intrinsic parameter matrix M. Substituting the inverse matrix of the M matrix into N = Z c 2 M -TM -1 , we have:
由于H已知,每张标定板图片可以提供一个约束关系,且N为对称矩阵,求解N则需要3张标定板图像,根据N与相机内参的对应关系解得ZC。Since H is known, each calibration plate image can provide a constraint relationship, and N is a symmetric matrix. Three calibration plate images are required to solve N. Z C is obtained based on the corresponding relationship between N and the camera intrinsic parameters.
步骤3:使用相机内参和畸变参数对受电弓图像进行畸变矫正。Step 3: Use the camera intrinsic parameters and distortion parameters to correct the distortion of the pantograph image.
在本发明中,畸变分为径向畸变和切向畸变。In the present invention, distortion is divided into radial distortion and tangential distortion.
径向畸变使用主点周围的泰勒级数展开式子的前两项k1和k2进行描述,径向畸变矫正公式如下:The radial distortion is described using the first two terms k1 and k2 of the Taylor series expansion around the principal point. The radial distortion correction formula is as follows:
式中,(x,y)为畸变点在图像上的位置,(x′,y′)为畸变矫正后的位置,r为像素点到图像中心点的距离,即r2=x2+y2,k1、k2为径向畸变参数。Where (x, y) is the position of the distortion point on the image, (x′, y′) is the position after distortion correction, r is the distance from the pixel to the center of the image, that is, r 2 =x 2 +y 2 , k 1 and k 2 are radial distortion parameters.
切向畸变是由于安装、制造过程中,相机传感器平面与透镜不平行而产生,切向畸变矫正公式如下:Tangential distortion is caused by the fact that the camera sensor plane is not parallel to the lens during installation and manufacturing. The tangential distortion correction formula is as follows:
式中,p1、p2为切向畸变系数。Where p 1 and p 2 are tangential distortion coefficients.
步骤4:采用改进的Harris角点检测算法提取畸变矫正后的受电弓图像中的特征点,并构造匹配的特征点对。Step 4: Use the improved Harris corner detection algorithm to extract feature points in the distortion-corrected pantograph image and construct matching feature point pairs.
步骤5:使用匹配的特征点对,根据成像模型估计受电弓图像间的几何变换关系。Step 5: Use the matched feature point pairs to estimate the geometric transformation relationship between pantograph images according to the imaging model.
步骤6:根据受电弓图像间的几何变换关系,对受电弓图像进行矫正,采用像元尺寸标定方法来修正透视形变使测量结果更加准确。Step 6: According to the geometric transformation relationship between pantograph images, the pantograph image is corrected, and the pixel size calibration method is used to correct the perspective deformation to make the measurement result more accurate.
根据成像原理,当相机与物体之间的距离不相同时,距离越远的物体在图像上所占有的像素个数越少,像元尺寸越大;而当被拍摄物体与相机存在一定夹角并且物体两端与相机距离不同的情形下,最终成像会显示成一种“近大远小”的现象,即透视形变,对于这种现象,近端与远端缩放比例不同,若能够在横向上将图像尺寸放大到实际长度,在纵向采用不同缩放比例,即可将两端放大到实际物理尺寸大小。若将近端与远端之间分割成多段,那么每段的两端都有一个近端与远端,当知道每段近端与远端的比例因子便可以精确求解为实际尺寸。将多段分割成像素大小,那么每两个相邻像素一个为近端,另一个便为远端,当知道两端的像元尺寸大小,便可将图像尺寸转换到物理实际尺寸。According to the imaging principle, when the distance between the camera and the object is different, the farther the object is, the fewer pixels it occupies on the image, and the larger the pixel size; when there is a certain angle between the object and the camera and the distances between the two ends of the object and the camera are different, the final image will show a phenomenon of "large near and small far", that is, perspective deformation. For this phenomenon, the near end and the far end have different scaling ratios. If the image size can be enlarged to the actual length in the horizontal direction and different scaling ratios are used in the vertical direction, the two ends can be enlarged to the actual physical size. If the near end and the far end are divided into multiple segments, then each segment has a near end and a far end at both ends. When the scale factor of each segment's near end and far end is known, the actual size can be accurately solved. Divide the multiple segments into pixel sizes, then one of every two adjacent pixels is the near end and the other is the far end. When the pixel sizes at both ends are known, the image size can be converted to the actual physical size.
对于横向像元尺寸的进行标定可由两组受电弓图像求得,设左右碳滑板横向像元尺寸分别为lx、rx,左右碳滑板求得完整横向像素个数分别为L、R,则满足:The calibration of the horizontal pixel size can be obtained from two sets of pantograph images. Assume that the horizontal pixel sizes of the left and right carbon slides are lx and rx respectively, and the numbers of complete horizontal pixels of the left and right carbon slides are L and R respectively, then:
式中,δ表示两接触线之间的距离,大小为40mm,碳滑板总长度为1050mm。Where, δ represents the distance between the two contact lines, which is 40 mm, and the total length of the carbon slide plate is 1050 mm.
在实际中,为保证碳滑板的有效测量长度,碳滑板无法完全填充整个视场。会引起较大误差,引起误差主要有受电弓发生左右偏移、升弓高度等因素的影响。本发明统计实际拍摄图像的纵向像素尺寸大小,以左右碳滑板图像的18个横向像素位置为横坐标,像元尺寸为纵坐标作图,结果如图4所示。图中像元尺寸趋势线不为水平直线,左碳滑板曲线呈现递增趋势,右碳滑板曲线呈现递减趋势,与相机和受电弓的实际相对位置相符。In practice, in order to ensure the effective measurement length of the carbon slide, the carbon slide cannot completely fill the entire field of view. It will cause a large error, which is mainly caused by the left and right deviation of the pantograph, the height of the pantograph, and other factors. The present invention counts the vertical pixel size of the actual captured image, and plots the 18 horizontal pixel positions of the left and right carbon slide images as the horizontal coordinate and the pixel size as the vertical coordinate. The result is shown in Figure 4. The pixel size trend line in the figure is not a horizontal straight line. The left carbon slide curve shows an increasing trend, and the right carbon slide curve shows a decreasing trend, which is consistent with the actual relative position of the camera and the pantograph.
下面对本发明所述的相机标定改进算法进行评价。The improved camera calibration algorithm described in the present invention is evaluated below.
本实验对相机标定进行实验,采用重投影误差进行评价,即理论像素点a与畸变矫正后的测量像素点a′的欧氏距离||a-a′||2,重投影误差越小反映相机标定结果越好,即畸变修正越符合实际情形。This experiment conducts experiments on camera calibration and uses reprojection error for evaluation, that is, the Euclidean distance between the theoretical pixel point a and the measured pixel point a′ after distortion correction ||aa′|| 2 . The smaller the reprojection error, the better the camera calibration result, that is, the more the distortion correction conforms to the actual situation.
实验结果如图2,结果表明棋盘格照片数量的累加并不会明显提升相机标定结果精度,因为角点检测精度不仅与算法有关,还与图像的质量有关。然而,在棋盘格照片数量相同的情况下,改进的Harris角点检测算法的重投影误差更小,两者精度相差及其明显,即改进后的角点检测算法精度更高,从而能够提升检测系统的检测精度。The experimental results are shown in Figure 2. The results show that the accumulation of the number of chessboard photos does not significantly improve the accuracy of the camera calibration results, because the accuracy of corner detection is not only related to the algorithm, but also to the quality of the image. However, when the number of chessboard photos is the same, the reprojection error of the improved Harris corner detection algorithm is smaller, and the difference in accuracy between the two is very obvious, that is, the improved corner detection algorithm has higher accuracy, which can improve the detection accuracy of the detection system.
本发明再以邻域大小为唯一变量,采用30张照片进行实验,结果图3所示。随着邻域大小的增加,重投影误差呈现先减小后增大的现象,这是由于邻域的增大求得的角点越靠近理论角点位置,而邻域的过大会导致邻域内远离理论角点的点增多,可得出结论:将导致求得的角点远离理论角点位置,重投影误差变大,即精度降低,因此在进行相机标定计算时应当选择合适邻域大小。The present invention uses the neighborhood size as the only variable and conducts experiments with 30 photos, and the results are shown in Figure 3. As the neighborhood size increases, the reprojection error decreases first and then increases. This is because the corner point obtained is closer to the theoretical corner point position as the neighborhood increases, and the excessive size of the neighborhood will lead to an increase in the number of points far away from the theoretical corner point in the neighborhood. It can be concluded that the corner point obtained will be far away from the theoretical corner point position, and the reprojection error will become larger, that is, the accuracy will decrease. Therefore, a suitable neighborhood size should be selected when performing camera calibration calculations.
经过统计受电弓图像中碳滑板厚度约占80个像素,若像元尺寸偏差0.01个单位,实际厚度值的误差将达到0.8mm,显然不符合检测精度要求。According to statistics, the thickness of the carbon plate in the pantograph image accounts for about 80 pixels. If the pixel size deviation is 0.01 units, the error of the actual thickness value will reach 0.8mm, which obviously does not meet the detection accuracy requirements.
本发明将统计得到的每个横向像素位置都求得纵向像元尺寸大小,而不是只采用同一个值,虽然操作复杂,但是具有提升碳滑板磨耗检测精度的作用,结果如图4所示。The present invention calculates the longitudinal pixel size for each horizontal pixel position obtained by statistics, rather than using only the same value. Although the operation is complicated, it has the effect of improving the accuracy of carbon slide wear detection, and the result is shown in FIG4 .
以上所述仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims (4)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410150485.6A CN118015095A (en) | 2024-02-02 | 2024-02-02 | A camera calibration algorithm |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410150485.6A CN118015095A (en) | 2024-02-02 | 2024-02-02 | A camera calibration algorithm |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN118015095A true CN118015095A (en) | 2024-05-10 |
Family
ID=90951644
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202410150485.6A Pending CN118015095A (en) | 2024-02-02 | 2024-02-02 | A camera calibration algorithm |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN118015095A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119672129A (en) * | 2024-11-29 | 2025-03-21 | 苏州柏川数据科技有限公司 | A camera calibration method and system for 3D geometric reconstruction |
-
2024
- 2024-02-02 CN CN202410150485.6A patent/CN118015095A/en active Pending
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119672129A (en) * | 2024-11-29 | 2025-03-21 | 苏州柏川数据科技有限公司 | A camera calibration method and system for 3D geometric reconstruction |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN104981105B (en) | A kind of quickly accurate detection and method for correcting error for obtaining element central and deflection angle | |
| CN108369650B (en) | Method for identifying possible characteristic points of calibration pattern | |
| CN106408609B (en) | A kind of parallel institution end movement position and posture detection method based on binocular vision | |
| CN111915485B (en) | Rapid splicing method and system for feature point sparse workpiece images | |
| CN108230237A (en) | A kind of multispectral image reconstructing method for electrical equipment on-line checking | |
| US20150262346A1 (en) | Image processing apparatus, image processing method, and image processing program | |
| CN102722731A (en) | Efficient image matching method based on improved scale invariant feature transform (SIFT) algorithm | |
| CN111462214B (en) | Line structure light stripe center line extraction method based on Hough transformation | |
| CN110222661B (en) | Feature extraction method for moving target identification and tracking | |
| CN103761768A (en) | Stereo matching method of three-dimensional reconstruction | |
| CN112465707B (en) | Processing methods, devices, media and electronic equipment for stripe noise in infrared images | |
| CN113920073B (en) | Thin card counting method, device, electronic equipment and storage medium | |
| CN118015095A (en) | A camera calibration algorithm | |
| CN118762059A (en) | Image registration method for multi-camera imaging system | |
| CN117635874A (en) | A three-dimensional rapid inversion system for fragmentation fields based on image multi-feature extraction and fusion algorithms | |
| CN115100153B (en) | In-pipe detection method, device, electronic equipment and medium based on binocular matching | |
| CN112923852B (en) | SD card pose detection method based on dynamic corner positioning | |
| CN118864526A (en) | A printing trajectory fast tracking method and system based on template matching | |
| CN118747811A (en) | Improved monocular SLAM image feature matching method based on ORB algorithm | |
| CN117911364A (en) | Cable joint roundness detection method and equipment based on sub-pixel edge detection | |
| US7702176B2 (en) | One dimensional feature enhancement | |
| WO2020031980A1 (en) | Method for correcting lens marker image, correcting device, program, and recording medium | |
| CN118941646B (en) | Infrared binocular camera calibration method, device, equipment and medium | |
| CN116152167B (en) | Sliding detection method, device, medium, equipment | |
| CN119444831B (en) | A method for measuring the width of an expansion joint |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |