Disclosure of Invention
In order to solve the technical problems, the invention aims to provide a monocular camera view angle measuring method and a monocular camera view angle measuring system, which can simplify the existing camera view angle measuring device and improve the accuracy of camera view angle measurement by calculating the included angle of normal vectors of the vertical and horizontal edge straight back projection planes of the maximum inscribed orthogonal rectangle of an undistorted image.
The first technical scheme adopted by the invention is as follows: a monocular camera angle of view measuring method includes the following steps:
acquiring an internal reference matrix of a globally optimal camera to be measured and a distortion coefficient of the globally optimal camera to be measured by a Zhang calibration method based on the plane target image;
based on the internal reference matrix of the globally optimal camera to be tested and the distortion coefficient of the globally optimal camera to be tested, and combining with a Brown lens distortion model, constructing four edge linear equations of the maximum inscribed orthogonal rectangle of the undistorted image;
determining the normal vector of the back projection plane corresponding to the edge straight line of the maximum inscribed orthogonal rectangle of the undistorted image according to four edge straight line equations of the maximum inscribed orthogonal rectangle of the undistorted image;
and determining the vertical field angle of the camera to be tested and the horizontal field angle of the camera to be tested according to the normal vector of the back projection plane corresponding to the maximum inscribed orthogonal rectangular edge line of the undistorted image.
Further, the step of obtaining the internal reference matrix of the globally optimal camera to be measured and the distortion coefficient of the globally optimal camera to be measured by the Zhang calibration method based on the plane target image specifically comprises the following steps:
constructing a field angle measuring device, wherein the field angle measuring device represents a two-dimensional plane target with a characteristic pattern on the surface;
shooting the view angle measuring device through a camera to be tested to obtain a plurality of plane target images with multiple angles, wherein the plane target images are images with distortion;
and (3) calibrating the plane target image by a Zhongshi calibration method to obtain an internal reference matrix of the globally optimal camera to be tested and a distortion coefficient of the globally optimal camera to be tested.
Further, the step of performing calibration processing on the plane target image by using a Zhang calibration method to obtain an internal reference matrix of the globally optimal camera to be measured and a distortion coefficient of the globally optimal camera to be measured specifically includes:
extracting 2D coordinates of target feature points of the planar target image through a corner detection algorithm to obtain 3D coordinates of the target feature points;
acquiring a homography matrix between a target plane and an image plane according to the corresponding relation between the 2D coordinates of the target feature points and the 3D coordinates of the target feature points;
according to orthogonality of the rotation matrix and combining a homography matrix between a target plane and an image plane, constructing an absolute quadratic curve projection linear equation set related to the camera to be tested;
solving an absolute secondary curve projection linear equation set of the camera to be tested by a linear least square method and a Cholesky decomposition method to obtain a preliminary internal reference matrix of the camera to be tested;
decomposing the target homography matrix based on the initial internal reference matrix of the camera to be detected to obtain external parameters of the camera to be detected;
constructing a linear equation set of undistorted 2D coordinates and distorted 2D coordinates of target feature points through a Brown lens distortion model, and solving by a least square method to obtain a preliminary distortion coefficient of the camera to be tested;
based on a camera perspective projection model, combining an internal reference matrix of a preliminary camera to be detected and a distortion coefficient of the preliminary camera to be detected to establish a target characteristic point re-projection error objective function, and performing minimization treatment by using an LM nonlinear optimization algorithm to obtain a globally optimal internal reference matrix of the camera to be detected and a globally optimal distortion coefficient of the camera to be detected.
Further, the expression of the Brown lens distortion model is specifically as follows:
;
in the above-mentioned method, the step of,representing the normalized plane target image with distorted discrete point coordinates,and->Representing the distortion coefficient of the camera under test, +.>And (5) representing the undistorted plane target image discrete point normalized coordinates.
Further, the step of constructing four edge linear equations of the maximum inscribed orthogonal rectangle of the undistorted image based on the internal reference matrix of the globally optimal camera to be measured and the distortion coefficient of the globally optimal camera to be measured and combining a Brown lens distortion model specifically comprises the following steps:
acquiring a distorted discrete point set of a planar target image, wherein the distorted discrete point set represents an upper edge discrete point of the planar target image, a lower edge discrete point of the planar target image, a left edge discrete point of the planar target image and a right edge discrete point of the planar target image;
normalizing the distorted discrete point set of the planar target image according to the overall optimal internal reference matrix of the camera to be tested to obtain normalized distorted discrete point coordinates of the planar target image;
combining the normalized plane target image discrete point coordinates with distortion with the distortion coefficient of the globally optimal camera to be tested and substituting the distortion coefficient into a Brown lens distortion model to obtain undistorted plane target image discrete point coordinates;
performing inverse normalization processing on the undistorted planar target image discrete point normalization coordinates to obtain inverse normalized undistorted planar target image discrete point coordinates;
and determining the maximum value of the ordinate of the edge discrete point on the plane target image, the minimum value of the ordinate of the edge discrete point on the lower edge of the plane target image, the maximum value of the abscissa of the left edge discrete point of the plane target image and the minimum value of the abscissa of the right edge discrete point of the plane target image based on the undistorted plane target image discrete point coordinates after inverse normalization, and constructing four edge linear equations of the maximum inscription orthogonal rectangle of the undistorted image.
Further, the step of determining the normal vector of the back projection plane corresponding to the edge line of the maximum inscribed orthogonal rectangle of the undistorted image according to the four edge line equations of the maximum inscribed orthogonal rectangle of the undistorted image specifically comprises the following steps:
converting four edge linear equations of the maximum inscribed orthogonal rectangle of the undistorted image to obtain coefficient vectors of the four edge linear equations;
and combining the internal reference matrix of the camera to be detected with coefficient vectors of four edge linear equations to obtain a corresponding back projection plane normal vector of the maximum inscribed orthogonal rectangular edge line of the undistorted image.
Further, the step of determining a vertical field angle of the camera to be measured and a horizontal field angle of the camera to be measured according to the normal vector of the back projection plane corresponding to the maximum inscribed orthogonal rectangular edge line of the undistorted image specifically includes:
and determining the included angle between the normal vectors of the upper and lower edges of the plane target image and the normal vectors of the left and right edges of the plane target image according to the normal vectors of the back projection planes corresponding to the maximum inscribed orthogonal rectangular edge straight line of the undistorted image, wherein the included angle between the normal vectors of the upper and lower edges of the plane target image is the vertical field angle of the camera to be tested, and the included angle between the normal vectors of the left and right edges of the plane target image is the horizontal field angle of the camera to be tested.
Further, the expression of the vertical field angle of the camera to be measured and the horizontal field angle of the camera to be measured is specifically as follows:
;
in the above-mentioned method, the step of,representing the vertical field angle of the camera to be measured, +.>Representing the horizontal angle of view of the camera to be measured, +.> And->Representing normal vector of back projection plane corresponding to maximum inscribed orthogonal rectangular edge line of undistorted image, ++>Modulo representing vector, ++>Representing the inverse cosine calculation symbol.
The second technical scheme adopted by the invention is as follows: a monocular camera field angle measurement system, comprising:
the acquisition module is used for acquiring an internal reference matrix of the globally optimal camera to be tested and a distortion coefficient of the globally optimal camera to be tested through a Zhang calibration method based on the plane target image;
the construction module is used for constructing four edge linear equations of the maximum inscription orthogonal rectangle of the undistorted image based on the internal reference matrix of the globally optimal camera to be tested and the distortion coefficient of the globally optimal camera to be tested and combining the Brown lens distortion model;
the first determining module is used for determining the corresponding back projection plane normal vector of the maximum inscribed orthogonal rectangle edge straight line of the undistorted image according to the four edge straight line equations of the maximum inscribed orthogonal rectangle of the undistorted image;
and the second determining module is used for determining the vertical field angle of the camera to be detected and the horizontal field angle of the camera to be detected according to the normal vector of the back projection plane corresponding to the maximum inscribed orthogonal rectangular edge line of the undistorted image.
The method and the system have the beneficial effects that: according to the invention, the plane target image is calibrated to obtain the internal reference matrix of the camera to be measured and the distortion coefficient of the camera to be measured, the normal vector of the back projection plane corresponding to the maximum inscribed orthogonal rectangular edge straight line of the undistorted image is further determined by combining with the Brown lens distortion model, the influence caused by lens distortion is eliminated in the field angle measurement process, the field angle measurement precision is improved, and the vertical field angle of the camera to be measured and the horizontal field angle of the camera to be measured are obtained.
Detailed Description
The invention will now be described in further detail with reference to the drawings and to specific examples. The step numbers in the following embodiments are set for convenience of illustration only, and the order between the steps is not limited in any way, and the execution order of the steps in the embodiments may be adaptively adjusted according to the understanding of those skilled in the art.
Explanation of technical terms of the present invention:
angle of view: in the optical Field, the Field of View (FOV) refers to the size of the Field of View of a particular optical instrument (e.g., lens). The range takes the lens of the optical instrument as the vertex, and the object image of the measured object can pass through the included angle formed by the two edges of the maximum range of the lens. In a display system, the field angle is the angle between the edge of the display and the line of sight (eye). The larger the angle of view, the larger the field of view, the smaller the optical magnification, the angle of view refers to a camera or otherIn the imaging process of the vision sensor, the included angle of the largest imaging range of the object to be measured on the image sensor through the optical center of the lens is shown as figure 3, and the space imaging area of the general camera is a tetrahedron, so the angle of view comprises the horizontal angle of view #) And vertical angle of view (+)>)。
Calibrating a camera: camera calibration is a key technology in the field of computer vision, which is a process of quantitatively describing the relationship between pixel coordinates and real world coordinates. The main purpose of camera calibration is to establish the relationship between the two-dimensional image coordinates in the camera image coordinate system and the three-dimensional coordinates in the world coordinate system, and correct the camera with the calibration result, so that the output result of the camera is more accurate and reliable, that is, the camera calibration refers to the process of determining the internal parameters and the external parameters of the camera, wherein the internal parameters of the camera comprise an internal reference matrix and distortion coefficients, and the external parameters comprise the position and the posture of the camera in the three-dimensional space. The camera calibration generally utilizes a plane or a three-dimensional target to establish a mapping relation between the space three-dimensional coordinates of the feature points and the two-dimensional coordinates of the projection points, so that the calculation of the internal and external parameters of the camera is completed.
Lens distortion correction: the lens distortion correction is to eliminate or reduce the influence of lens distortion on an image by adjusting the configuration of a lens or using a software algorithm, the lens distortion is to cause distortion or deformation of a shot image compared with an actual object because of the optical characteristics of the lens, and the lens distortion correction process is to complete removal of radial distortion and tangential distortion of the image by using a distortion coefficient and a distortion model on the basis of completing camera calibration.
Back projection plane: on the basis of completing camera calibration and distortion correction, the method is easy to think according to a pinhole imaging model: one point in the image corresponds to one ray in space; a straight line in the image corresponds to a plane in space, which is referred to as the back projection plane of the straight line.
The measuring device is only a 2-dimensional plane target, and the target is used for completing the rapid calibration of the monocular camera internal reference matrix and the distortion coefficient, so that the accurate field angle of the camera under the distortion-free condition can be directly calculated based on the calibration result. The method for measuring the angle of view does not need to take part in reading manually in the whole process, and does not need mechanical moving devices such as a translation table, a turntable and the like in the process of measuring the angle of view, so that the device and the method for measuring the angle of view have the advantages of simple hardware structure, convenience in operation, accuracy in measurement and the like.
Referring to fig. 1, the present invention provides a monocular camera angle of view measuring method, which includes the steps of:
s1, acquiring an internal reference matrix of a globally optimal camera to be tested and a distortion coefficient of the globally optimal camera to be tested through a Zhang calibration method based on a plane target image;
in this embodiment, a surface is prepared to be printed with a specification ofThe grid side is a 2-dimensional planar target of a 20mm checkerboard. Shooting a plurality of plane target images under different angles by using a camera to be detected, and calibrating the camera by using a Camera Calibration Toolbox for Matlab toolbox developed by Jean-Yves Bouguet based on a Zhang Zhengyou calibration method to obtain a parameter matrix and distortion coefficients->. Wherein (1)>Respectively representing the normalized focal lengths of the camera in the directions of the horizontal axis and the vertical axis; />Representing principal point coordinates; />Respectively representing first-order, second-order and third-order radial distortion coefficients; />Respectively representing first order and second order tangential distortion coefficients.
The specific algorithm flow of the Zhang Zhengyou calibration method is as follows:
s11, shooting a plurality of checkerboard images under different angles by using a camera to be detected, finishing the 2D coordinate extraction of the corner points of the checkerboard by using a corner detection algorithm, and simultaneously finishing the generation of the 3D coordinates of the corner points by combining the design size of the checkerboard. The targets used herein are of the specificationCheckerboard with 20mm sides. Generating 3D coordinates of the corner points according to the design size of the checkerboard: selecting plane printed with checkerboard image as reference plane, taking upper left corner of calibration plate as origin, and setting coordinates as +.>The method comprises the steps of carrying out a first treatment on the surface of the Secondly, determining the axial direction of a coordinate system of the calibration plate, and establishing +.>An axis defining a positive direction to the right; establishing +.about.with origin as the starting point along the vertical sides of the checkerboard>The axis and defines a positive downward direction. After the coordinate system is established, determining 3D coordinates of all corner points according to the size of the checkerboard: wherein the upper left corner coordinate is +.>The upper right corner coordinates areThe lower left corner coordinate is +>The lower right corner coordinate is->. Other internal corner points are derived according to the size of the checkerboard;
s12, converting the detected 2D coordinates of the corner points and the generated 3D real coordinates into homogeneous coordinates, constructing a homogeneous linear equation for each corner point, and correlating the corresponding 2D coordinates with the 3D coordinates to form a linear equation set. Solving for the expansion of the homography matrix using a linear equation and reducing it toThe homography matrix H between the target plane and the image plane can be solved.
S13, establishing a linear equation set about the projection of the absolute conic of the camera by utilizing the homography matrix H calculated in the embodiment S12 and the orthogonality of the rotation matrix, and completing the reference matrix of the camera by utilizing the linear least square method and Cholesky decompositionSolving each element;
s14, further decomposing the homography matrix on the basis of completing the solving of the reference matrix in the camera. Decomposing the homography matrix by using a singular value decomposition method to obtain a rotation matrix R and a translation vector of the camera;
S15, establishing a linear equation set of undistorted 2D coordinates and distorted 2D coordinates of the target feature points by using a Brown lens distortion model, and solving a camera distortion coefficient;
S16, establishing a target characteristic point reprojection error objective function based on a camera perspective projection model, and minimizing the target characteristic point reprojection error objective function by using an LM nonlinear optimization algorithm to obtain a globally optimal camera internal reference matrixAnd a lens distortion coefficient。
S2, constructing four edge linear equations of the maximum inscribed orthogonal rectangle of the undistorted image based on an internal reference matrix of the globally optimal camera to be tested and a distortion coefficient of the globally optimal camera to be tested and by combining a Brown lens distortion model;
in this embodiment, the original image size of the camera is obtained by referring to the product specification manual of the camera, sets of distorted discrete points on four edge lines of the upper, lower, left and right are respectively generated according to the original image size, then the generated point coordinates are respectively substituted into a lens distortion model to calculate to obtain an undistorted discrete point set corresponding to the distorted discrete points, and four edge straight line equations corresponding to the maximum inscribed orthogonal rectangle of the undistorted image are calculated based on the contour extremum formed by the undistorted discrete points. Specifically, the calculation of the edge straight line equation is performed as follows.
S21, firstly, obtaining the size and the height of an original image by referring to a camera product specification manualWidth of (width of)At this time, the image is a distorted image, and then sets of distorted discrete points on the upper, lower, left and right edges of the image are respectively generated>Wherein->Respectively representing pixel coordinates of discrete points with distortion in the directions of a horizontal axis and a vertical axis, wherein the sampling interval of the discrete points on each edge is 1 pixel, and the sampling range of the discrete points on the upper edge, the lower edge and the edge is +.>The sampling range of the left and right edge discrete points is +.>As shown in FIG. 4, is generated based on the original imageSet of distorted discrete points on upper, lower, left and right edges。
S22, combining the normalized focal length obtained by marking in the embodiment S1And principal point coordinates +.>Pixel coordinates of discrete points with distortion on each edge line are +.>After normalization operation, the image is converted into normalized image coordinates +.>The specific normalization operation is as follows:
;
in the above-mentioned method, the step of,normalized coordinates of distorted discrete points of the normalized planar target image are represented by +.>Representing normalized focal length in the camera reference matrix, < >>A pixel coordinate point representing a discrete point with distortion on each edge line,representing principal point coordinates in the camera's reference matrix.
S23, normalizing image coordinates of discrete points with distortionIs substituted into the lens distortion model,distortion coefficient +.>Calculating normalized image coordinates of corresponding undistorted discrete points>FIG. 5 shows a calculated corresponding undistorted set of discrete pointsThe specific lens distortion model is as follows:
;
in the above-mentioned method, the step of,representing the normalized plane target image with distorted discrete point coordinates,and->Representing the distortion coefficient of the camera under test, +.>Representing undistorted plane target image discrete point normalized coordinates;
wherein,。
s24, calibrating the normalized focal length by combining the embodiment S1And principal point coordinates +.>Normalized image coordinates of undistorted discrete points calculated in embodiment S23>After inverse normalization operation, the pixel coordinates are converted into undistorted pixel coordinates>The specific inverse normalization operation is as follows:
;
in the above-mentioned method, the step of,representing the inverse normalization operation and then converting to undistorted pixel coordinates.
Distortion-bearing discrete point set on four edge lines of original imageAfter the processing of the embodiments S22 to S24, the corresponding undistorted discrete point set +.>。
S25, calculating an undistorted discrete point set from the upper edge of the original imageIs selected to be the largest +.>Recorded as->The method comprises the steps of carrying out a first treatment on the surface of the Zero distortion discrete point set at lower edge +.>Is selected to be the smallest->Recorded as->The method comprises the steps of carrying out a first treatment on the surface of the Zero distortion discrete point set at left edge +.>Is selected to be the largest +.>Recorded as->The method comprises the steps of carrying out a first treatment on the surface of the Undistorted discrete point set at right edgeIs selected to be the smallest->Recorded as->. By extremum->The four edge straight-line equations of the maximum inscribed orthogonal rectangle of the undistorted image can be determined, as shown in fig. 6, which is four edge straight lines corresponding to the maximum inscribed orthogonal rectangle of the undistorted image, and the general formulas are respectively as follows:
;
in the above-mentioned method, the step of,maximum value of ordinate representing edge discrete point on plane target image,/->Ordinate minimum representing the discrete point of the lower edge of the planar target image, +.>Maximum value of abscissa representing left edge discrete point of planar target image,/->Representing right edge separation of planar target imageThe abscissa of the scatter is the minimum.
S3, determining a corresponding back projection plane normal vector of the maximum inscribed orthogonal rectangle edge straight line of the undistorted image according to four edge straight line equations of the maximum inscribed orthogonal rectangle of the undistorted image;
in this example, the linear equation general expression calculated in the embodiment S25 is converted into a coefficient vector, and the camera internal reference matrix obtained by the calibration in the embodiment S1 is usedCalculating the normal vector of the back projection plane corresponding to the inscribed orthogonal rectangular edge line with the maximum undistorted image +.>. The specific back projection plane normal vector is calculated as follows.
S31, converting the general formula of four edge linear equations of the maximum inscribed orthogonal rectangle of the undistorted image obtained by calculation in the embodiment S25 into coefficient vectors, wherein the conversion result is as follows:
;
in the above-mentioned method, the step of,and the coefficient vector represents four edge linear equations of the maximum inscribed orthogonal rectangle of the undistorted image.
S32, calibrating the obtained camera internal reference matrix by combining the embodiment S1And the linear coefficient vector converted in embodiment S31 +.>Calculating normal vector of back projection plane corresponding to maximum inscription orthogonal rectangular edge line of undistorted image>The method comprises the following steps of:
;
in the above-mentioned method, the step of,representing normal vector of back projection plane corresponding to maximum inscribed orthogonal rectangular edge line of undistorted image, ++>Representing the transpose of the camera's reference matrix.
And S4, determining the vertical field angle of the camera to be tested and the horizontal field angle of the camera to be tested according to the normal vector of the back projection plane corresponding to the maximum inscribed orthogonal rectangular edge line of the undistorted image.
In this embodiment, the angles of normal vectors of the upper and lower pairs of edge back projection planes are calculated, wherein the angles of the upper and lower edge back projection planes are the vertical angle of view of the cameraThe angle between the left and right edge back projection planes is the horizontal angle of the camera>The method comprises the following steps:
;
in the above-mentioned method, the step of,representing the vertical field angle of the camera to be measured, +.>Representing the horizontal field angle of the camera under test,and->Representing normal vector of back projection plane corresponding to maximum inscribed orthogonal rectangular edge line of undistorted image, ++>Modulo representing vector, ++>Representing the inverse cosine calculation symbol.
Referring to fig. 2, a monocular camera angle of view measurement system includes:
the acquisition module is used for acquiring an internal reference matrix of the globally optimal camera to be tested and a distortion coefficient of the globally optimal camera to be tested through a Zhang calibration method based on the plane target image;
the construction module is used for constructing four edge linear equations of the maximum inscription orthogonal rectangle of the undistorted image based on the internal reference matrix of the globally optimal camera to be tested and the distortion coefficient of the globally optimal camera to be tested and combining the Brown lens distortion model;
the first determining module is used for determining the corresponding back projection plane normal vector of the maximum inscribed orthogonal rectangle edge straight line of the undistorted image according to the four edge straight line equations of the maximum inscribed orthogonal rectangle of the undistorted image;
and the second determining module is used for determining the vertical field angle of the camera to be detected and the horizontal field angle of the camera to be detected according to the normal vector of the back projection plane corresponding to the maximum inscribed orthogonal rectangular edge line of the undistorted image.
The content in the method embodiment is applicable to the system embodiment, the functions specifically realized by the system embodiment are the same as those of the method embodiment, and the achieved beneficial effects are the same as those of the method embodiment.
While the preferred embodiment of the present invention has been described in detail, the invention is not limited to the embodiment, and various equivalent modifications and substitutions can be made by those skilled in the art without departing from the spirit of the invention, and these modifications and substitutions are intended to be included in the scope of the present invention as defined in the appended claims.