A lens evaluation and image restoration method for machine vision measurement system
Through the lens evaluation method based on CNN, the problem of inaccurate lens distortion parameter estimation in the existing technology is solved, and high-precision image restoration of the machine vision measurement system is achieved. Parameters are directly extracted from the distorted image and inversely transformed, which improves the accuracy of the lens distortion parameter estimation. Imaging accuracy.
Patent Information
- Application Number
- CN202111514563.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-13
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-12-13
AI Technical Summary
Existing lens distortion parameter estimation methods have insufficient accuracy, especially the neglect of tangential distortion parameters, resulting in low image recovery accuracy. In addition, other lens parameters need to be known before the distortion parameters can be calculated. The process is complex and has low accuracy.
Using the lens evaluation method based on CNN, the convolutional neural network is trained through the generated and annotated data set to estimate the radial and tangential distortion parameters k1, k2, k3, p1, p2, and use these parameters to restore the distortion of the image, directly from Extract parameters from the distorted image and perform inverse transformation.
It achieves accurate estimation of lens distortion parameters and high-precision image recovery, can directly extract parameters from distorted images, eliminate image distortion, improve the imaging accuracy of the machine vision measurement system, and meet actual task requirements.
Smart Images

Figure CN114298923B
Abstract
Description
Technical Field
[0001] The invention belongs to the field of machine vision, and in particular relates to a lens evaluation and image restoration method for a machine vision measurement system based on CNN. Background Art
[0002] Machine vision is a rapidly developing branch of artificial intelligence. Simply put, machine vision is to use machines to replace human eyes to perform tasks such as measurement. The machine vision measurement system converts the captured target into an image signal through the machine vision product, that is, the image capture device lens, and transmits it to a dedicated image processing system to obtain the morphological information of the captured target, and converts it into a digital signal based on the pixel distribution, brightness, color and other information; the image system performs various operations on these signals to extract the characteristics of the target, and then controls the equipment action on site based on the results of the judgment. However, the lens, its core component, causes lens distortion due to manufacturing accuracy and assembly deviation, which distorts the image obtained by the system. Evaluating the factors that cause lens distortion is to estimate the lens distortion parameters. First, the lens manufacturing accuracy causes radial distortion of the lens, and the deviation of the assembly process causes tangential distortion of the lens. There are three distortion parameters representing radial distortion, namely k1, k2, and k3, and two distortion parameters representing tangential distortion, namely p1 and p2. Therefore, the two factors that cause the lens distortion of the visual measurement system are evaluated, that is, the five parameters k1, k2, k3, p1, and p2 are estimated.
[0003] At present, people have explored distortion parameter estimation methods to restore the images obtained by the system, but they all have shortcomings in some aspects, and there are not many methods that can be put into practical use. For example, the traditional method Zhang Zhengyou calibration method must first know other parameters of the lens before obtaining the distortion parameters, and this method only considers radial distortion and ignores the radial distortion coefficient k3. This shows that the traditional method is not accurate in estimating the distortion parameters of the lens. On the other hand, after obtaining other parameters of the lens, this method must use mathematical tools to calculate the distortion parameters, and cannot directly obtain the distortion parameters. In addition, some parameters are ignored, and the parameters calculated by mathematical tools are not accurate, so the image restoration accuracy is not high. Summary of the invention
[0004] The purpose of the present invention is to overcome the shortcomings of the traditional distortion parameter estimation method and provide a CNN-based machine vision measurement system lens evaluation and restoration method to meet the requirements of obtaining accurate imaging of the subject when the machine vision measurement system is actually working. CNN, namely Convolutional Neural Networks.
[0005] The technical problem of the present invention is solved by the following technical solutions:
[0006] A lens evaluation and image restoration method for a machine vision measurement system, firstly evaluating the lens distortion, i.e. using CNN to estimate the distortion parameters, and then using the obtained distortion parameters to restore the distorted image;
[0007] The evaluation of lens distortion includes obtaining a data set and evaluating distortion parameters:
[0008] The acquisition of the data set comprises the following specific steps: first, the image acquisition device lens of the machine vision measurement system is used to convert the captured target into an image signal, which is transmitted to the image processing system of the machine vision measurement system, and the image processing system converts the image signal into a digital signal; the image system operates on these signals to extract the characteristics of the target; finally, the results are output according to the preset tolerance and other conditions, and the results include: size, angle, offset, number, qualified / unqualified, and present / absent; by studying how the machine vision measurement system forms an image, the imaging model of the machine vision measurement system is simulated by Matlab programming, and the imaging of different machine vision measurement systems is simulated in the program by continuously changing the parameters related to the lens manufacturing accuracy and the assembly deviation factor, so as to obtain 10,000 images as the data set for CNN training;
[0009] The evaluation of the distortion parameters is specifically performed as follows: regressing the data set in the Tensorflow framework environment provided by Google, solving the factors affecting the machine vision measurement system into distortion parameters. The factors affecting the machine vision measurement system are the lens manufacturing accuracy and the deviation of the assembly process. The lens manufacturing accuracy causes radial distortion of the system lens, and the deviation of the assembly process causes tangential distortion of the lens. There are three distortion parameters representing radial distortion, namely k1, k2, and k3, and two distortion parameters representing tangential distortion, namely p1 and p2. Therefore, solving the factors affecting the machine vision measurement system into distortion parameters is to estimate the five parameters of k1, k2, k3, p1, and p2. The specific steps of this process are as follows:
[0010] 1) Divide the data set into training set, validation set and test set according to the ratio of 6:2:2, and put the images corresponding to the labels generated in the MATLAB program into a .txt document. This step is labeling. Compress the images and labels according to the training set, validation set and test set, and upload them to Google Drive;
[0011] 2) Import the required tensorflow and numpy data packages, find a usable CPU, and mount Google colab on Google Cloud Disk;
[0012] 3) Load and visualize data labels. First, construct the file path names of the training set, validation set, test set, and labels. Then use ImageDataGenerator to load the images and check the images and labels. To prevent data overfitting, perform data enhancement operations, flip the images horizontally, rotate them randomly, and then define the batch size as 20.
[0013] 4) Build a convolutional neural network and compile the model: the optimizer uses adam and the loss function is the cross entropy function;
[0014] 5) Use the built convolutional neural network to train the data set. First define epoch and save the model parameters every 20 cycles. Then check the training accuracy and verification accuracy. Stop training when the training accuracy and verification accuracy curves coincide.
[0015] 6) Input the test set to verify the model effect;
[0016] The use of the obtained distortion parameters to restore the distorted image refers to restoring the image to the state before distortion based on the distortion parameters; the undistorted coordinates (u, v) of the pixel in the uOv coordinate system fall on (ui, vi) of the uOv coordinate system after radial distortion and tangential distortion. That is, the relationship between the real image imgR and the distorted image imgD is:
[0017] imgR(u,v)=imgD(ui,vi)
[0018] What is known is the distorted image. To obtain an undistorted image, we need to deduce its mapping relationship through the distortion model. Through the formula, we can find all imgR(u,v). The implementation process is to traverse the points of the output image. For the generated 64P distorted image, we traverse from point (0,0) to point (64,64), row by row, and find the pixel value of the original image point (ui,vi) corresponding to the output point (u,v) in turn, and then assign the value of (ui,vi) to (u,v). If the calculated corresponding original image point (ui,vi) is not an integer, use quadratic linear interpolation to calculate this point, and then assign it to (u,v). After completing all traversals, we get the image before distortion.
[0019] Beneficial effects:
[0020] 1. A CNN-based machine vision measurement system lens evaluation and recovery method of the present invention first evaluates the factors that cause lens distortion of the core component of the system, namely, the deviation of lens manufacturing accuracy and assembly process. CNN is used to evaluate these two factors, namely, the five parameters k1, k2, k3, p1, and p2 are estimated. The present invention uses a standard template as the subject of the machine vision measurement system. Because the manufacturing accuracy and assembly error of the lens are different, the degree of image distortion obtained by the system is different. CNN is used to regress the distorted image to obtain these five distortion parameters, that is, the factors affecting the lens distortion are solved into distortion parameters. The distortion parameters obtained in real time are then used to perform a transformation opposite to the distortion to eliminate image distortion, so that the machine vision measurement system can obtain a more realistic image at a lower cost. CNN is first used to estimate the distortion parameters, and then the distortion parameters are used to restore the image, so that the machine vision measurement system can obtain an image that expresses the true form of the subject and meets the actual task requirements.
[0021] 2. The traditional method only considers radial distortion, or considers less the order of radial distortion parameters, and ignores the radial distortion coefficient k3. This shows that the traditional method is inaccurate in estimating the lens distortion parameters. Since both tangential distortion and radial distortion will affect the imaging of the machine vision measurement system, the incomplete estimation of parameters will not be able to meet the actual needs of image recovery accuracy. The present invention uses a standard template as the subject of the machine vision measurement system. Because the manufacturing accuracy and assembly errors of the lens are different, the degree of image distortion obtained by the system is different. Using images with different degrees of distortion, CNN is used to estimate all distortion parameters, and then the image distortion is further eliminated, so that the machine vision measurement system can accurately image.
[0022] 3. The distorted image obtained by the system can be directly used to regress the distorted image in real time using the CNN model to obtain the distortion parameters, and then perform the inverse transformation of the distortion to obtain the normal image. It is not necessary to first know other parameters of the lens like the traditional method, and then use mathematical tools to calculate the distortion parameters. The distortion parameters cannot be obtained directly, and some parameters are ignored. The parameters calculated by mathematical tools are not accurate, so the image restoration accuracy is not high. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a nonlinear model of the lens imaging of the machine vision measurement system of the present invention.
[0024] Figure 2 It is a standard template for the system subject of the present invention.
[0025] Figure 3 It is a schematic diagram of the CNN model structure of the present invention.
[0026] Figure 4The figure is a schematic diagram of the comparison before and after the partial image restoration using distortion parameters in the present invention.
[0027] Figure 5 The present invention is a flowchart of the lens evaluation and image restoration method using this system. DETAILED DESCRIPTION
[0028] Embodiment 1 Nonlinear model of lens imaging of the machine vision measurement system of the present invention
[0029] The nonlinear model of the system lens imaging of the machine vision measurement system lens evaluation and restoration method based on CNN of the present invention is as follows Figure 1 As shown, in the nonlinear imaging model, the lens implements the following transformation: world coordinate system (using (Xw, Yw, Zw) to represent its coordinate value) -> camera coordinate system (using (Xc, Yc, Zc) to represent its coordinate value) -> image coordinate system (using (x, y) to represent its coordinate value) -> pixel coordinate system (using (u, v) to represent its coordinate value). By studying the transfer function of the system object imaging onto the target surface, preparation is made for using MATLAB programming to simulate the process and generate images representing different degrees of distortion as a data set. By continuously changing the system lens manufacturing accuracy and the correlation coefficient of assembly process deviation to simulate the impact of these two factors on the system, the degree of distortion of the generated images is also different. The 10,000 images generated are used as a data set for CNN training;
[0030] The transfer function of the object image to the target surface of the machine vision measurement system is:
[0031]
[0032] Example 2: Standard template of the present invention as a system object
[0033] The standard template of the system object of the present invention is as follows Figure 2 As shown in the figure, the standard template is a checkerboard image generated by MATLAB programming, using a 6×6 grid layout, and the image pixels are 64×64pixels. The image is a grayscale image. The specific program is as follows:
[0034] J = checkerboard(60,3,3);
[0035] J(J>0)=1
[0036] figure
[0037] imshow(J)
[0038] saveas(gca,'checkerboard','jpg')
[0039] Example 3 Programming of the MALAB simulation lens manufacturing accuracy and assembly process deviation on the imaging of the machine vision measurement system of the present invention
[0040] The program design of the MALAB simulation lens manufacturing accuracy and assembly process deviation on the imaging of the machine vision measurement system is as follows:
[0041]
[0042]
[0043]
[0044] In the program, the standard template is first read in, and then the system lens manufacturing accuracy and assembly process deviation correlation coefficient are continuously changed to simulate the impact of these two factors on the system, and images with different degrees of distortion are generated. The generated 10,000 images are used as the data set for CNN training. Finally, LABEL is used in the program to generate the label of the image.
[0045] Example 4 Specific implementation method of labeling a data set for estimating distortion parameters of CNN according to the present invention
[0046] The labels corresponding to the partially distorted images of the present invention are as follows:
[0047]
[0048]
[0049] To estimate the distortion parameters using CNN, you need to label the image first. The label is the value of k1, k2, k3, p1, and p2. The label is placed in a .txt file in the above format. The first line of the label is the label of image 0, and so on. In this way, the image and the label correspond one to one.
[0050] Example 5 Schematic diagram of the CNN model structure of the present invention
[0051] The schematic diagram of the CNN model structure of the present invention is as follows Figure 3As shown, the model is a convolutional neural network composed of three convolutional layers, three pooling layers, two fully connected layers and one output layer. The prepared data set is input into the model for training (the specific steps are shown in the content of the invention), and the output can obtain the five parameter values of k1, k2, p1, p2, and k3 (generally, the parameter k3 is placed after p1 and p2). The trained model can be used to evaluate the lens distortion of other machine vision measurement systems in real time. The model.predict function can be called to perform the evaluation. This method has high accuracy and efficiency and meets the task requirements of the actual machine vision measurement system. The obtained k1, k2, p1, p2, and k3 parameters can be prepared for distorted image restoration.
[0052] Example 6 Schematic diagram of comparison before and after partial image restoration using distortion parameters in the present invention
[0053] The present invention uses distortion parameters to perform partial image restoration before and after comparison. Figure 4 As shown in the figure, the top five images are distorted images obtained by the system, and the last five images are normal images restored using distortion parameters. The images obtained by the machine vision measurement system in the task are input into the trained model in real time to obtain the distortion parameters. Then, a transformation opposite to the distortion is performed to eliminate the image distortion, so that the machine vision measurement system can obtain a more realistic image at a lower cost. This method saves manpower and material resources and has higher accuracy.
[0054] The specific steps are: the undistorted coordinates (u, v) in the pixel coordinate system (uOv coordinate system) fall on (ui, vi) in the uOv coordinate system after radial distortion and tangential distortion. That is, the relationship between the real image imgR and the distorted image imgD is:
[0055] imgR(u,v)=imgD(ui,vi)
[0056] What is known is the distorted image. To obtain an undistorted image, its mapping relationship must be deduced through the distortion model. Use the formula to find all imgR(u,v). The implementation process is to traverse the points of the output image. For the generated 64P distorted image, traverse from point (0,0) to point (64,64), row by row, find the pixel value of the original image point (ui,vi) corresponding to the output point (u,v) in turn, and then assign the value of (ui,vi) to (u,v). If the calculated corresponding original image point (ui,vi) is not an integer, use quadratic linear interpolation to calculate this point and then assign it to (u,v). After completing all traversals, the output image is obtained.
[0057] The flow chart of the complete operation process of the present invention is as follows Figure 5 shown.
[0058] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some of the technical features therein by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. In the above embodiments, the writing of the specific program scripts involved belongs to the conventional technology in the field. On the basis of the design ideas given in the present invention, those skilled in the art can choose the corresponding programming language according to their own programming habits.
Claims
1. A lens evaluation and image restoration method for a machine vision measurement system, firstly evaluating the lens distortion, i.e. using CNN to estimate the distortion parameters, and then using the obtained distortion parameters to restore the distorted image; The evaluation of lens distortion includes obtaining a data set and evaluating distortion parameters: The acquisition of the data set is specifically carried out as follows: first, the image acquisition device lens of the machine vision measurement system converts the captured target into an image signal, which is then transmitted to the image processing system of the machine vision measurement system. The image processing system converts the image signal into a digital signal. ; The image system operates on these signals to extract the characteristics of the target; finally, according to the preset tolerance and other conditions, the output results include: Size, angle, offset, number, pass / fail, presence / absence; By studying how machine vision measurement systems form images, Matlab programming is used to simulate the imaging model of machine vision measurement systems. In the program, the imaging of different machine vision measurement systems is simulated by constantly changing the parameters related to lens manufacturing accuracy and assembly deviation factors. 10,000 images are obtained as a data set for CNN training. The evaluation of the distortion parameters is specifically performed as follows: regressing the data set in the Tensorflow framework environment provided by Google, solving the factors affecting the machine vision measurement system into distortion parameters. The factors affecting the machine vision measurement system are the lens manufacturing accuracy and the deviation of the assembly process. The lens manufacturing accuracy causes radial distortion of the system lens, and the deviation of the assembly process causes tangential distortion of the lens. There are three distortion parameters representing radial distortion, namely k1, k2, and k3, and two distortion parameters representing tangential distortion, namely p1 and p2. Therefore, solving the factors affecting the machine vision measurement system into distortion parameters is to estimate the five parameters of k1, k2, k3, p1, and p2. The specific steps of this process are as follows: 1) Divide the data set into training set, validation set and test set according to the ratio of 6:2:2, and put the images corresponding to the labels generated in the MATLAB program into a .txt document. This step is labeling. Compress the images and labels according to the training set, validation set and test set, and upload them to Google Drive; 2) Import the required tensorflow and numpy data packages, find a usable CPU, and mount Google colab on Google Cloud Disk; 3) Load and visualize data labels. First, construct the file path names of the training set, validation set, test set, and labels. Then use ImageDataGenerator to load the images and check the images and labels. To prevent data overfitting, perform data enhancement operations, flip the images horizontally, rotate them randomly, and then define the batch size as 20. 4) Build a convolutional neural network and compile the model: the optimizer uses adam and the loss function is the cross entropy function; 5) Use the built convolutional neural network to train the data set. First define epoch and save the model parameters every 20 cycles. Then check the training accuracy and verification accuracy. Stop training when the training accuracy and verification accuracy curves coincide. 6) Input the test set to verify the model effect; The use of the obtained distortion parameters to restore the distorted image refers to restoring the image to the state before distortion based on the distortion parameters; the undistorted coordinates (u, v) of the pixel in the uOv coordinate system fall on (ui, vi) of the uOv coordinate system after radial distortion and tangential distortion. That is, the relationship between the real image imgR and the distorted image imgD is: imgR(u,v)=imgD(ui,vi) What is known is the distorted image. To obtain an undistorted image, we need to deduce its mapping relationship through the distortion model. Through the formula, we can find all imgR(u,v). The implementation process is to traverse the points of the output image. For the generated 64P distorted image, we traverse from point (0,0) to point (64,64), row by row, and find the pixel value of the original image point (ui,vi) corresponding to the output point (u,v) in turn, and then assign the value of (ui,vi) to (u,v). If the calculated corresponding original image point (ui,vi) is not an integer, use quadratic linear interpolation to calculate this point, and then assign it to (u,v). After completing all traversals, we get the image before distortion.
