Precise measurement positioning method based on calibration algorithm
Technical Field
The invention relates to the field of laser precision machining, in particular to a precise measurement positioning method based on a calibration algorithm.
Background
In the field of conventional image processing, it is an important ring to restore the exact position of the object itself by an image. For example, in the field of industrial measurement and positioning, accurate measurement needs to be performed manually to obtain actual parameters of an object, such as length, width, and the like, the implementation process of the online measurement method is complicated, and for some large or small devices which are difficult to measure or require high precision, it is often difficult to obtain accurate parameters of the object by a direct measurement method. At present, a plurality of off-line measurement methods are commonly used, such as a method for measuring a precise object by microscope confocal scanning and the like, although the method has high precision, coaxial measurement is mostly required when the object is precisely machined, the machining platform and the microscope are difficult to coaxially and simultaneously measure and machine, the coaxial measurement method has high requirements on hardware equipment and external conditions, the machining platform and the object to be machined need to be accurately calibrated and matched, and the calibration and the matching of the machining platform and the object to be machined need to be carried out again after the machining platform or the object to be machined is moved every time, so the coaxial method is not suitable for simultaneously and accurately measuring during machining.
Although paraxial measurement and processing are also used, image transformation or projection transformation and other methods are generally used at present, the image transformation method has low measurement precision and high requirements on external factors, the distortion of a camera needs to be strictly controlled, the positions of the camera, a processing platform and an object are required to be relatively accurate to shoot an ideal picture for subsequent measurement operation, and the process is complicated and the cost is high. In the field of accurate positioning, the relative position of a measured object can be quickly and reliably acquired through a laser radar at present, but relevant equipment and corresponding external conditions are required. Although the image can reflect the relative position and relative parameters of the actual object, the actual parameters of the actual object cannot be accurately obtained through the image due to the influence of the shooting conditions and external factors, and spatial position information is difficult to obtain. Therefore, it is important to solve such problems.
Disclosure of Invention
Aiming at the problems, the invention provides an accurate measurement positioning method based on a calibration algorithm, which obtains a one-to-one corresponding relation between a camera and a world three-dimensional coordinate system of an object to be measured through camera imaging to obtain an image and a conversion matrix under a world coordinate, obtains a relative position relation of the object to be processed relative to a laser processing plane through the conversion matrix by utilizing the conversion relation between the world coordinate and a pixel coordinate, and thus skips the complicated step of re-matching the processing plane and the processed object after moving the object every time.
In order to realize the technical scheme, the invention provides an accurate measurement positioning method based on a calibration algorithm, which comprises the following steps:
the method comprises the following steps: acquiring sub-pixel coordinates of corner points of a shot picture, performing multi-shot of changing any position and any posture on a chessboard calibration plate with known size parameters by using a camera with fixed focal length to acquire an image, converting the image into a gray-scale image, binarizing the processed gray-scale image, judging whether the corner points exist by using a corner point detection algorithm, and if the corner points exist, acquiring accurate sub-pixel coordinates of the corner points;
step two: acquiring internal parameters of camera equipment, defining corresponding world coordinates corresponding to angular points of an image, acquiring one-to-one correspondence between the world coordinates of the angular points and the image coordinates, selecting the angular points of a plurality of groups of images and points on a corresponding world coordinate system, and acquiring the internal parameters and distortion coefficients for shooting the group of image camera equipment through a calibration algorithm;
step three: acquiring external parameters of camera equipment for shooting the group of pictures, keeping internal parameters such as focal length of the shooting camera unchanged, selecting three non-collinear points around the object to be processed on a laser processing plane, shooting the object to be processed by the camera at any position and in any posture to obtain an image, and obtaining the external parameters of the shot camera equipment through a multi-point positioning algorithm;
step four: fixing the position of the camera with the obtained internal and external parameters, keeping the imaging of the object to be processed in the camera view finding range, moving the object to be processed at will, acquiring the moved image again by the camera, obtaining pixel points on the shot image pixel by pixel, obtaining the visual relation between the laser processing plane and the image through the conversion matrix calculated by the internal and external parameters, and performing precision processing operation on any position on the image on the laser processing plane.
In a further improvement, in the step one, the gray scale map of the image is to set the gray scale value of the image to be 0 to 255, 255 represents all white, and 0 represents all black; the white and black are divided into a plurality of equal steps according to the logarithmic relation, and the gray level is divided into 256 steps.
In the first step, the corner detection algorithm includes the following steps of continuously taking out each picture of a group of pictures which are taken and subjected to graying processing, and executing the following operations for each picture:
the method comprises the following steps: preprocessing an image, binarizing the image, and converting a gray level image into a binary image;
step two: searching adjacent grids of each grid, recording the number of the adjacent grids, and classifying all the adjacent grids according to the principle that all the grids in the class are adjacent;
step three: judging whether the squares in each class are the sought chessboard squares or not according to the known number of the angular points, confirming whether the positions and the number of the squares are correct or not, if so, extracting the connection points of any two squares of the sought chessboard squares, namely the sought angular points, and obtaining the accurate sub-pixel coordinates of all the angular points; if not, the chessboard angular point detection fails.
In a further improvement, in the second step, the calibration algorithm includes the following steps, for each image from which a sub-pixel coordinate corner is successfully acquired, the following operations are performed:
the method comprises the following steps: defining world coordinate points corresponding to the coordinates of the angular points of the chessboard pattern calibration board on the image, wherein the world coordinate points need to be the same as the theoretical condition, namely the coordinate difference between two angular points is the real distance between the chessboard pattern calibration board grids used for shooting;
step two: and (4) inputting the world coordinates and the pixel coordinates of the defined corresponding corner points into a function in a matrix form to calculate the internal parameters and the distortion coefficients of the camera.
In a further improvement, the relationship between the pixel coordinates and the world coordinates is as follows:
wherein u and v represent coordinates in a pixel coordinate system, s represents a scale factor, fx, fy, u0, v0 and gamma represent 5 camera internal parameters, R and t represent camera external parameters, Xw, Yw and Zw (assuming that a calibration chessboard is positioned on a plane of which Zw is 0 in the world coordinate system) represent coordinates in the world coordinate system, that is, a plurality of sets of world coordinates and corresponding pixel coordinate points are input to obtain required camera internal parameters.
In a further improvement, the relation of the distortion coefficients is:
u1=u+(u-u0)[k1(x2+y2)+k2(x2+y2)2]
v1=v+(v-v0)[k1(x2+y2)+k2(x2+y2)2]
wherein, (u, v) represents pixel coordinates of ideal distortion-free, (u1, v1) represents pixel coordinates in the case of distortion of an actual radial image, and (u0, v0) represents principal points, and is obtained directly in the obtained internal reference matrix regardless of the presence or absence of distortion.
In a further improvement, the camera device external parameter acquisition comprises the following steps, for the camera model with the obtained internal parameters, the following operations are carried out: keeping the internal parameters such as the focal length of a camera and the like unchanged, placing an object to be processed on a laser processing operation platform, selecting three non-collinear points around the object to be processed on a laser processing plane, shooting the object to be processed by using a laser, shooting an image containing the object to be processed and the three non-collinear points shot by using the laser by using the camera at any position and posture of a paraxial of a laser processing platform, and obtaining the external parameters of the shooting camera at the moment through a multi-point positioning algorithm.
The further improvement lies in that: the multi-point positioning algorithm comprises the following steps of executing the following operations on the obtained camera shooting images:
the method comprises the following steps: inputting laser processing plane coordinates of three points around an object to be processed selected on a laser processing plane;
step two: inputting corresponding world coordinates of three points on a laser processing plane which is shot by the laser;
step three: and by means of cosine law, a translation and rotation matrix of the camera system image coordinate system shot at the moment relative to the world coordinate system can be obtained by utilizing a point cloud registration method.
The invention has the beneficial effects that: the invention provides a laser precision machining method based on paraxial offline measurement, which obtains a one-to-one corresponding relation between a camera and a world three-dimensional coordinate system of an object to be machined through camera imaging to obtain an image and a conversion matrix under a world coordinate, obtains the relative position relation of the object to be machined relative to a laser machining plane through the conversion matrix by utilizing the conversion relation between the world coordinate and a pixel coordinate, and thus skips the complicated step of re-matching the machining plane and the machining object after moving the object every time. Meanwhile, the method can realize the paraxial arrangement of the camera and the object to be processed at any pose, effectively solves the problems of complicated process and low precision of coaxial processing, has higher processing precision and simple process, and provides a novel method with low cost, high efficiency and accuracy for the field of laser precision processing.
Drawings
FIG. 1 is a flow chart of the present invention.
Fig. 2 is a schematic diagram illustrating an exemplary operation effect of the present invention.
Fig. 3 is a schematic diagram illustrating an exemplary operation effect of the present invention.
Fig. 4 is a schematic diagram illustrating an exemplary effect of the present invention.
Detailed Description
In order to further understand the present invention, the following detailed description will be made with reference to the following examples, which are only used for explaining the present invention and are not to be construed as limiting the scope of the present invention.
As shown in fig. 1, the present embodiment provides a calibration algorithm based accurate measurement positioning method, which includes the following steps:
the method comprises the following steps: acquiring sub-pixel coordinates of corner points of a shot picture, performing multi-shot of changing any position and any posture on a chessboard calibration plate with known size parameters by using a camera with fixed focal length to acquire an image, converting the image into a gray-scale image, binarizing the processed gray-scale image, judging whether the corner points exist by using a corner point detection algorithm, and if the corner points exist, acquiring accurate sub-pixel coordinates of the corner points;
step two: acquiring internal parameters of camera equipment, defining corresponding world coordinates corresponding to angular points of an image, acquiring one-to-one correspondence between the world coordinates of the angular points and the image coordinates, selecting the angular points of a plurality of groups of images and points on a corresponding world coordinate system, and acquiring the internal parameters and distortion coefficients for shooting the group of image camera equipment through a calibration algorithm;
step three: acquiring external parameters of camera equipment for shooting the group of pictures, keeping internal parameters such as focal length of the shooting camera unchanged, selecting three non-collinear points around the object to be processed on a laser processing plane, shooting the object to be processed by the camera at any position and in any posture to obtain an image, and obtaining the external parameters of the shot camera equipment through a multi-point positioning algorithm;
step four: fixing the position of the camera with the obtained internal and external parameters, keeping the imaging of the object to be processed in the camera view finding range, moving the object to be processed at will, acquiring the moved image again by the camera, obtaining pixel points on the shot image pixel by pixel, obtaining the visual relation between the laser processing plane and the image through the conversion matrix calculated by the internal and external parameters, and performing precision processing operation on any position on the image on the laser processing plane.
In the embodiment, in the first step, the grayscale map of the image is to set the grayscale value of the image to 0 to 255, 255 represents full white, and 0 represents full black; the white and black are divided into a plurality of equal steps according to the logarithmic relation, and the gray level is divided into 256 steps.
In this embodiment, in the first step, the corner detection algorithm includes the following steps of continuously taking out each picture of a group of pictures which are taken and subjected to graying processing, and executing the following operations for each picture:
the method comprises the following steps: preprocessing an image, binarizing the image, and converting a gray level image into a binary image;
step two: searching adjacent grids of each grid, recording the number of the adjacent grids, and classifying all the adjacent grids according to the principle that all the grids in the class are adjacent;
step three: judging whether the squares in each class are the sought chessboard squares or not according to the known number of the angular points, confirming whether the positions and the number of the squares are correct or not, if so, extracting the connection points of any two squares of the sought chessboard squares, namely the sought angular points, and obtaining the accurate sub-pixel coordinates of all the angular points; if not, the chessboard angular point detection fails.
In this embodiment, in the second step, the calibration algorithm includes the following steps, for each image from which a sub-pixel coordinate corner is successfully acquired, the following operations are performed:
the method comprises the following steps: defining world coordinate points corresponding to the coordinates of the angular points of the chessboard pattern calibration board on the image, wherein the world coordinate points need to be the same as the theoretical condition, namely the coordinate difference between two angular points is the real distance between the chessboard pattern calibration board grids used for shooting;
step two: and (4) inputting the world coordinates and the pixel coordinates of the defined corresponding corner points into a function in a matrix form to calculate the internal parameters and the distortion coefficients of the camera.
In this embodiment, the relationship between the pixel coordinates and the world coordinates is as follows:
wherein u and v represent coordinates in a pixel coordinate system, s represents a scale factor, fx, fy, u0, v0 and gamma represent 5 camera internal parameters, R and t represent camera external parameters, Xw, Yw and Zw (assuming that a calibration chessboard is positioned on a plane of which Zw is 0 in the world coordinate system) represent coordinates in the world coordinate system, that is, a plurality of sets of world coordinates and corresponding pixel coordinate points are input to obtain required camera internal parameters.
In this embodiment, the relationship of the distortion coefficients is:
u1=u+(u-u0)[k1(x2+y2)+k2(x2+y2)2]
v1=v+(v-v0)[k1(x2+y2)+k2(x2+y2)2]
wherein, (u, v) represents pixel coordinates of ideal distortion-free, (u1, v1) represents pixel coordinates in the case of distortion of an actual radial image, and (u0, v0) represents principal points, and is obtained directly in the obtained internal reference matrix regardless of the presence or absence of distortion.
In this embodiment, the camera device extrinsic parameter acquisition includes the following steps, for the camera model with the obtained intrinsic parameters, to perform the following operations: keeping the internal parameters such as the focal length of a camera and the like unchanged, placing an object to be processed on a laser processing operation platform, selecting three non-collinear points around the object to be processed on a laser processing plane, shooting the object to be processed by using a laser, shooting an image containing the object to be processed and the three non-collinear points shot by using the laser by using the camera at any position and posture of a paraxial of a laser processing platform, and obtaining the external parameters of the shooting camera at the moment through a multi-point positioning algorithm.
In this embodiment, the multi-point positioning algorithm includes the following steps, for the obtained camera shooting image, to perform the following operations:
the method comprises the following steps: inputting laser processing plane coordinates of three points around an object to be processed selected on a laser processing plane;
step two: inputting corresponding world coordinates of three points on a laser processing plane which is shot by the laser;
step three: and by means of cosine law, a translation and rotation matrix of the camera system image coordinate system shot at the moment relative to the world coordinate system can be obtained by utilizing a point cloud registration method.
Fig. 2-3 are schematic diagrams illustrating exemplary operation effects of the present invention, and as shown in fig. 2, a checkerboard is used as an example of the present invention for related explanation, parameters of a checkerboard calibration board are 3mm × 3mm, a camera used for shooting has been used for calibration steps of obtaining external parameters and camera distortion, the checkerboard can be shot by the camera after any pose is changed to obtain a required image, any 3 non-collinear points are selected in the actual shooting on the left side, and corresponding 3 points are selected on the simulated image on the right side. After the steps are completed, as shown in fig. 3, a desired positioning measurement point is selected on the left actual shot image, and after the steps of the invention are completed, the actual positioning measurement point is displayed on the right simulated image. This example is merely an example, and to facilitate direct observation, a checkerboard calibration board is taken as an example for description, and in actual operation, any object may be selected to perform the operation flow described in this example.
Fig. 4 is a schematic diagram illustrating an exemplary effect of the present invention, and as shown in fig. 4, a checkerboard is taken as an example of the present invention for relevant explanation, where an object to be processed is a checkerboard of 2mm × 2mm, and is placed on a laser processing platform, at this time, a camera can select any position capable of shooting the object to be processed, and at this time, the camera has performed a calibration step of acquiring an external parameter and a camera distortion coefficient, and selects any 3 non-collinear points on the object to be processed on the left side, and by using the method of the present invention, a desired processing point and an obtained transformation matrix are input, so as to obtain a processing point at an actual spatial position, and perform precision processing, thereby obtaining a processing effect shown in the right drawing. In the implementation process of the embodiment, the position of the camera is kept unchanged, the position of the object to be processed can be rotated or moved randomly, and the obtained results are consistent. The feasibility and the accuracy of the invention are proved by the example.
The foregoing illustrates and describes the principles, general features, and advantages of the present invention. It will be understood by those skilled in the art that the present invention is not limited to the embodiments described above, which are described in the specification and illustrated only to illustrate the principle of the present invention, but that various changes and modifications may be made therein without departing from the spirit and scope of the present invention, which fall within the scope of the invention as claimed.