The sample data sets are created first. Then, the neural network model is trained using the training data set. Based on the training model, the detection of defect stripe can be carried on. First, a structured light stripe is selected. The structured light stripe cross-section shown in
Figure 8 is intercepted from the selected stripe and input into the quality evaluation algorithm. Then, the stripe cross-section is transformed into the grayscale distribution graph shown in
Figure 9. Finally, the grayscale distribution curve is input into the trained neural network model, and the quality evaluation result of the structured light stripe is output. The above quality evaluation steps are summarized in
Figure 10.
4.2. Model Training
In this paper, we use the Adam optimizer because it combines the advantages of both AdaGrad and RMSProp optimization algorithms, featuring simple implementation, efficient computation, low memory requirements, stable parameters, and an automatic adjustment of learning rate [
40]. During the training process, the role of the Adam optimizer is to change the trainable parameters in a way that minimizes the loss function in order to obtain the optimal solution of the model.
In addition, binary cross-entropy is used as a loss function to measure the performance of neural networks. Binary cross-entropy is a commonly used loss function in binary classification tasks, and the expression is shown below.
where y is the binary label 0 or 1; p(y) is the probability that the output belongs to label y. As a loss function, the binary cross-entropy is used to judge how well a binary classification model predicts the outcome. For example, for a label y of 1, if the predicted value p(y) tends to 1, then the value of the loss function should tend to 0. Conversely, if the predicted value p(y) tends to 0 at this point, then the value of the loss function should be very large.
The residual neural network model was trained, and the experimental environment was specified as follows.
Operating system: Windows 10
CPU: Intel (R) Core (TM) i5-11300H
RAM: 16. 0 GB
First, to further verify the performance of the residual neural network with different layers in this study, this paper first conducted a test training of the dataset with 34-layer, 50-layer, and 101-layer ResNets, respectively. The initial learning rate of the algorithm and its exponential decay rate were set to 10
−4 and 0.9, respectively. The network input size was 480 × 320, the batch size was set to 20, the epoch was set to 15. After 15 generations of training, the performance of different layer residual neural network models was tested and compared, as shown in
Table 5.
Top-1 accuracy is the accuracy the category ranked first in probability with the actual result. As can be seen in
Table 5, the top-1 accuracy of the 50-layer ResNet is significantly improved compared to the 34-layer ResNet. Compared with the 50-layer ResNet, the top-1 accuracy of the 101-layer ResNet is slightly improved. However, its training time consumption is greatly increased. This also confirms the analysis in
Table 2 for the performance of different layers of residual neural networks.
Therefore, in this paper, we choose to continue training the model with a 50-layer residual neural network. The initial learning rate of the algorithm and its exponential decay rate were set to 10−4 and 0.9, respectively. The network input size is 480 × 320, the batch size is set to 20, the epoch is set to 60, and the current phase of training is stopped when the loss is no longer decreasing. After testing, this can ensure a better training effect based on this hardware configuration.
As shown in
Figure 12, with the loss of the training set and the val loss of the validation set gradually decreasing, the loss tends to stabilize after 60 iterations, and the fluctuation is around 0.124 and 0.121, respectively. It can be seen that the loss at the end of training converged, which means the model achieved a high classification accuracy in the test set.
After testing, the Top-1 accuracy of the neural network model trained in this paper is 95.27%.
4.3. Testing and Evaluation
To test the performance of the method, a standard sphere with a diameter of 50.80(+1.50/−1.00) mm, a flat board with flatness of 15 μm, and a standard cylinder with a diameter of 68.00 mm were measured by the structured light system. The testing steps of the method are shown in
Figure 13. First, the stripe pattern was projected on the subject and photographed, and then the 3D information of the subject was calculated. The structured light stripe cross-section was input into the model trained above to determine whether the stripe was defective or not. Then, the 3D point cloud corresponding to the stripe region with defects was removed. Finally, the measurement errors with and without processing were calculated and compared.
The principle of the method proposed in this paper is to evaluate the stripe quality according to the grayscale distribution of the structured light stripe cross-section. The grayscale distributions in the dataset include the ones of stripes on many different typical materials and shapes of objects in actual measurement processes. In order to test the generalization performance, this paper tested objects such as a steel ball and a flat board which are not included in the training dataset.
The measurement results of the spherical surface are shown in
Figure 14.
Figure 14a shows the modulated pattern on a standard ball.
Figure 14b shows the 3D point cloud of the ball, and
Figure 14c,d shows the concentration areas of large errors in the data. The ball in
Figure 14b is obtained by fitting the measurement data to a sphere. Although the intensity of
Figure 14c is high, the skewness coefficient of the stripe is high because of specular reflection. In
Figure 14d, the noise is largely due to the low intensity of the stripe. The measurement error of the ball is defined as the difference of the fitted radius and the distance between the measurement 3D point and the fitted center of the ball, which can be defined as:
where d is the actual distance from the sphere to the center of the sphere; d’ is the distance of each point of the 3D point cloud from the center of the fitted sphere. Since the gray distribution of the structured light stripes cross-section corresponding to points with large measurement errors in the point cloud tends to be degraded, the points with large measurement errors are considered defective.
The stripe cross-sections are intercepted in
Figure 14a and input into the prediction algorithm. The algorithm uses the model trained in
Section 4.2 as the prediction model to transform the cross-sectional images into grayscale curves and perform prediction, and the results are shown in
Figure 15. The grayscale distribution of the defective stripes in
Figure 15a–d comes from the irregular regions in
Figure 14c,d, and the grayscale distribution of the defect-free stripes in
Figure 15e–h comes from the region with better stripe quality in
Figure 14a. According to the prediction results, the stripe cross-sections at the locations corresponding to the irregular regions in
Figure 14c,d both have serious defects and are evaluated as “bad” by the prediction algorithm. In addition, the stripe cross-sections intercepted in regions with a good-quality of stripe are all evaluated as defect-free by the prediction algorithm. This is consistent with the conclusions obtained through the criteria for judging the quality of stripe cross-sections in
Section 3.2, as expected.
The measurement errors of the points corresponding to each stripe cross-section in
Figure 15 in the 3D point cloud are shown in
Table 6. It can be seen that during the evaluation of stripe quality, stripe cross-sections evaluated as defective have large measurement errors in their corresponding area. On the contrary, the points corresponding to the defect-free stripe sections tend to have smaller measurement errors. The results verified the prediction results.
The quality of the stripes in
Figure 14a is examined by the method proposed in this paper and in Ref. [
19]. The corresponding defective points are found in the 3D point cloud of
Figure 14b and removed, respectively, according to the two methods. The measurement error before and after processing is then calculated for each point in the point cloud according to Equation (2). The measurement errors before and after processing are shown in
Table 7. It can be seen that the measurement error of the stripes is significantly reduced after being processed by the method proposed in this paper. Therefore, compared with the method of Ref. [
19], the measurement error is smaller after the processing of the method in this paper.
For the flat board,
Figure 16a,b shows the captured image and 3D points measurement results of flat board. The large error points are mainly distributed at the edges of the board, caused by the asymmetry of the gray distribution of the stripes, as shown in
Figure 16a. The stripe cross-sections of the 3D points corresponding to the 2D coordinates in the irregular region are input into the prediction algorithm, and the results are shown in
Figure 17. According to the predicted results in
Figure 17a,b, the structural light stripe cross-sections at the broken points at the edges of the flat board in
Figure 16a are all severely defective and are evaluated as defective by the prediction algorithm. In contrast, according to the predicted results in
Figure 17c,d, the structured light stripe cross-sections intercepted at the center of the flat board surface have a uniform grayscale distribution and are evaluated as defect-free by the prediction algorithm. Therefore, the results meet the established expectation.
Similarly, the stripe cross-sections in the edge region of the flat board in
Figure 16a are separately input into the prediction algorithm. The points corresponding to the cross-sections with large errors evaluated by the algorithm are removed from the point cloud map shown in
Figure 16b. The measurement error information of the edges of the flat board before and after processing are summarized in
Table 8. The measurement error is defined as the relative distance of the points on the point cloud from the fitted plane. It can be seen that the measurement error for the flat board is also significantly reduced after processing by the method proposed in this paper.
For the cylinder,
Figure 18a,b shows the captured images and 3D point measurement results of the cylinder. As shown in
Figure 18a, the large error points are mainly distributed in the blackened parts of the cylinder and the edges of the cylinder. The stripe cross-sections intercepted in the irregular region and the regular region in
Figure 18a are input into the prediction algorithm separately, and the results are shown in
Figure 19. According to the prediction results in
Figure 19a,b, both the points at the edge of the cylinder and the cross-sections of the structured light stripes in the blackened part are all severely defective. According to the prediction results in
Figure 19c,d, the stripe cross-sections in the regions with more regular stripes have a uniform grayscale distribution and are evaluated as defect-free by the prediction algorithm.
The stripe sections on the cylinder in
Figure 18a are intercepted and input into the prediction algorithm separately. The points corresponding to the cross-sections with large errors evaluated by the algorithm are removed from the point cloud map shown in
Figure 18b. The measurement error information before and after processing is shown in
Table 9. The measurement error is defined as the absolute value of the difference between the distance from the point cloud on the cylinder to the fitted axis and the fitted radius of the cylinder.
As can be seen from
Table 7,
Table 8 and
Table 9, the method proposed in this paper can accurately recognize the large error data. After removing the large error data, the maximum measurement error and the average measurement error of the stripes are reduced significantly. Compared with the method in Ref. [
19], the average measurement error is lower after removing large error data using the method proposed in this paper. Since it does not need to calculate the evaluation parameters and set the thresholds of the parameters, it is much faster and more convenient. The comparison between the method proposed in this paper and the method proposed in Ref. [
19] is shown in
Table 10.