Workpiece size measuring method based on machine vision
By using VGG16 network, scale enhancement and high-frequency enhancement technologies in machine vision workpiece dimension measurement methods, the impact of lighting, noise and scale changes on measurements in industrial environments is solved, and more accurate and efficient workpiece dimension measurement is achieved.
Patent Information
- Application Number
- CN202311084004.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-28
- Publication Date
- 2025-03-04
AI Technical Summary
In industrial environments, changes in lighting conditions, noise interference, diversity in workpiece shape and size, as well as real-time and speed requirements, lead to limited accuracy and efficiency of traditional workpiece dimensional measurement methods.
Using machine vision-based workpiece size measurement method, the industrial camera is calibrated, and initial features of different resolutions are extracted using the VGG16 network, scale enhancement and high-frequency enhancement are performed, and parallel processing and filter technology is combined to reduce noise interference and improve image quality.
More accurate measurements of workpieces of different sizes and shapes are achieved, reducing the impact of lighting changes and noise interference, improving the real-time and efficiency of measurements, and saving computing resources.
Smart Images

Figure CN119559232A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of machine vision, in particular to a workpiece size measurement method based on machine vision. Background Art
[0002] Workpiece dimension measurement is a vital technology in industrial production and manufacturing processes. It involves the ability to accurately measure and evaluate the size, length, width, height and other key features of workpieces. The background of this technology stems from the continuous improvement of industrial quality control and precision requirements. In traditional workpiece dimension measurement, manual measuring tools such as calipers, gauges and scales are usually used. However, this method has problems such as human error, slow measurement speed and high operator skill requirements. With the advancement of science and technology, the application of automation and machine vision technology has gradually become the mainstream of workpiece dimension measurement. Machine vision technology combines knowledge in fields such as image processing, pattern recognition and machine learning, and can extract the size and feature information of workpieces from images or videos. In addition, the development of technologies such as machine learning and deep learning has also provided new possibilities for workpiece dimension measurement. By training models, computers can learn and identify the size and features of workpieces to achieve an automated and efficient measurement process. However, when using machine vision technology to measure workpiece dimensions in an industrial environment, there are still some problems and challenges:
[0003] Changing lighting conditions: Lighting conditions in industrial environments may be unstable, such as strong light, shadows, reflections, etc., which may cause image quality degradation and affect the accuracy of dimensional measurement.
[0004] Noise interference: Noise interference is a common problem in industrial environments. Various noises will have a negative impact on image quality, such as reducing image clarity, blurring edges, and causing loss of details. These problems will affect the dimensional measurement results.
[0005] Workpieces come in a variety of shapes and sizes: Workpieces in industrial production come in a variety of shapes and sizes, involving different geometric shapes and size ranges. This poses a challenge to algorithm and system design, which needs to be able to adapt to and handle the measurement requirements of various workpiece shapes and sizes.
[0006] Real-time and speed requirements: In industrial production, dimensional measurement usually requires real-time and high speed. Therefore, machine vision systems and algorithms need to be able to quickly process images and extract dimensional information to meet the needs of real-time monitoring and control.
[0007] Data processing and algorithm complexity: Extracting workpiece size information from images involves complex computing algorithms such as image processing, feature extraction, edge detection, and image registration. Processing large amounts of image data and the implementation of real-time algorithms may place demands on computing resources and system performance. Summary of the invention
[0008] In order to solve the above-mentioned shortcomings and difficulties, the present invention provides a workpiece size measurement method based on machine vision.
[0009] The technical solution adopted by the present invention to achieve the above-mentioned purpose is:
[0010] A method for measuring workpiece size based on machine vision comprises the following steps:
[0011] 1) Calibrate the industrial camera and use the calibrated industrial camera to capture the image of the workpiece to be tested;
[0012] 2) Use the VGG16 network to extract the initial features of the image at 5 different resolutions;
[0013] 3) The initial features are scale-enhanced with the same resolution and different resolutions to obtain input features;
[0014] 4) Perform high-frequency enhanced noise filtering on the input features respectively, and fuse them with the input features to obtain high-frequency features;
[0015] 5) Repeat steps 3) and 4) to upsample the high-frequency features of all stages to the size of the original workpiece image, fuse the high-frequency features of all stages by splicing, and then pass a 1×1 convolution layer to reduce the number of channels to 1 to obtain the workpiece edge;
[0016] 6) Use an external rectangular frame to surround the edge of the workpiece, convert the length and width of the external rectangle with the calibration file to obtain the actual size of the workpiece to be measured.
[0017] The step 3) comprises the following steps:
[0018] 3.1) Input the initial features of each stage into five different dilated convolutions to learn the initial features at the same resolution in parallel;
[0019] 3.2) Combine and fuse the five features;
[0020] 3.3) The fused features are passed through three consecutive 3×3 convolutional layers and one 1×1 convolutional layer to reduce the number of channels to 1 and obtain the fused features;
[0021] 3.4) The original features are added to the fused features through a residual connection to obtain enhanced features, completing feature scale enhancement at the same resolution;
[0022] 3.5) Upsample the enhanced features of the last four stages respectively to restore them to the size of the previous stage of the current stage;
[0023] 3.6) Add the upsampled features of the current stage to the enhanced features of the previous stage to obtain the input features, completing feature scale enhancement at different resolutions.
[0024] The algorithm for feature scale enhancement at the same resolution is:
[0025] X i =D(X,r k )
[0026] X′=δ[Concat(X1,X2,X3,X4,X5)]·w
[0027] Y=X′+X
[0028] Among them, X i represents the features after dilated convolution, D represents the features input into dilated convolution for processing, X represents the initial features, r k represents the dilation rate of the dilated convolution, r k The value range of is {1, 4, 8, 12, 16}, δ is three consecutive 3×3 convolutional layers, w is a 1×1 convolutional layer, Y is the feature after scale enhancement at the same resolution, X′ is the fused feature, and Y is the enhanced feature.
[0029] The algorithm for feature scale enhancement at different resolutions is:
[0030] Y′=Y i +Up(Y i+1 )
[0031] Among them, Y′ is the input feature, Y i is the enhanced feature at the same resolution at different stages, Y i+1 It is the enhanced feature of the next stage, and Up means upsampling.
[0032] The step 4) comprises the following steps:
[0033] 4.1) The input features are average pooled and max pooled respectively to obtain two feature maps, which are concatenated together and subjected to three 3×3 convolution operations and a softmax operation to complete the high-frequency processing of the input features;
[0034] 4.2) Use a two-layer fully connected network as a filter to filter the input features;
[0035] 4.3) Multiply the filter weight, high-frequency weight, and input feature to obtain enhanced features;
[0036] 4.4) Through residual connection, the input features are fused with the enhanced features to obtain high-frequency features. The algorithm for high-frequency enhancement and noise filtering is:
[0037] X′=Concat[AvgPool(X),MaxPool(X)]
[0038] W = softmax(δ(X′))
[0039] G(X)=Filter(X)
[0040] Z=G(X)·X·W
[0041] Z′=Z+X
[0042] Among them, X represents the input feature, AvgPool represents average pooling, MaxPool represents maximum pooling, X′ is the fused feature after average pooling and maximum pooling, δ is 3 consecutive 3×3 convolutional layers, W is the weight after high-frequency enhancement, G(X) is the filtering weight, Z represents the feature after high-frequency enhancement and noise filtering, and Z′ is the high-frequency feature.
[0043] The step 6) is specifically as follows: multiplying the pixel size of the circumscribed rectangular frame by the calibration data to obtain the real size of the workpiece.
[0044] A workpiece size measurement system based on machine vision, comprising:
[0045] An image acquisition module is used to calibrate the industrial camera and use the calibrated industrial camera to capture the image of the workpiece to be tested;
[0046] The feature extraction module is used to extract the initial features of the image at 5 different resolutions using the VGG16 network;
[0047] The scale enhancement module is used to perform scale enhancement of the initial features with the same resolution and different resolutions to obtain input features;
[0048] The high-frequency enhancement module is used to perform high-frequency enhancement noise filtering on the input features respectively, and fuse them with the input features to obtain high-frequency features;
[0049] The feature fusion module is used to upsample the high-frequency features of all stages to the size of the original workpiece image, fuse the high-frequency features of all stages by splicing, and then pass a 1×1 convolution layer to reduce the number of channels to 1 to obtain the industrial edge;
[0050] The parameter conversion module is used to enclose the industrial edge with an external rectangular frame, convert the length and width of the external rectangle with the calibration file, and obtain the actual size of the workpiece to be measured.
[0051] A workpiece size measurement system based on machine vision comprises a memory and a processor; the memory is used to store a computer program; the processor is used to implement a workpiece size measurement method based on machine vision when executing the computer program.
[0052] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, a workpiece dimension measurement method based on machine vision is implemented.
[0053] The present invention has the following beneficial effects and advantages:
[0054] 1. It can more accurately measure the dimensions of workpieces of different sizes and shapes. The method of the present invention performs scale enhancement on the initial features from two aspects: the same resolution and different resolutions, so that the detection network can adapt to the change of scale, thereby more accurately measuring the dimensions of the workpiece.
[0055] 2. Reduce the influence of illumination changes on the detection results. The method of the present invention proposes a high-frequency enhancement technology to enhance the high-frequency signal in the feature, thereby making the edge of the workpiece clearer.
[0056] 3. Reduced noise interference: The method of the present invention filters the noise in the feature through a filter, making the detected edge more complete and accurate.
[0057] 4. It saves computing resources and improves detection efficiency. The method of the present invention uses parallel processing to perform high-frequency enhancement and noise filtering at the same time, helping the model to adaptively learn the importance of each feature, greatly reducing redundant information and strengthening important information, thereby improving the expression of features. At the same time, due to the advantages of parallel processing, this method can more efficiently utilize computing resources when processing large amounts of data, thereby improving overall processing speed and efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 It is a module flow chart of the method of the present invention;
[0059] Figure 2 It is the overall model structure diagram;
[0060] Figure 3 Enhanced images of the same resolution scale;
[0061] Figure 4 This is a high frequency enhancement diagram. DETAILED DESCRIPTION
[0062] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.
[0063] A method for measuring workpiece size based on machine vision comprises the following steps:
[0064] 1. Calibrate industrial cameras;
[0065] 2. Use an industrial camera to photograph the workpiece to be tested;
[0066] 3. Using the VGG16 network as the backbone network, we get 5 initial features with different resolutions;
[0067] 4. Scale enhancement of basic features from the two aspects of the same resolution and different resolutions;
[0068] 5. Enhance the high frequency of features and filter out noise to increase the weight of edge information;
[0069] 6. Output the edge of the workpiece;
[0070] 7. Draw a circumscribed rectangle based on the edge;
[0071] 8. The actual size of the workpiece is obtained by converting the length and width of the circumscribed rectangle with the calibration file.
[0072] The algorithm for scale enhancement between the same resolutions is:
[0073] X i =D(X,r k )
[0074] X′=δ[Concat(X1,X2,X3,X4,X5)]·w
[0075] Y=X′+X
[0076] Among them, X i represents the features after dilated convolution, D represents the features input into dilated convolution for processing, X represents the initial features, r k represents the dilation rate of the dilated convolution, r k The value range is {1, 4, 8, 12, 16}. δ is three consecutive 3×3 convolutional layers, w is a 1×1 convolutional layer used to change the number of feature channels, and Y is the feature after scale enhancement at the same resolution.
[0077] The algorithm for scale enhancement between different resolutions is
[0078] Y′=Y i +Up(Y i+1 )
[0079] Among them, Y′ is the fusion feature of the same resolution and different resolution features after scale enhancement, Y i is the enhanced feature at the same resolution at different stages, Y i+1 It is the enhanced feature of the next stage, and Up means upsampling.
[0080] The algorithm for high frequency enhancement and noise filtering is:
[0081] X′=Concat[AvgPool(X),MaxPool(X)]
[0082] W = softmax(δ(X′))
[0083] G(X)=Filter(X)
[0084] Z=G(X)·X·W
[0085] Z′=Z+X
[0086] Among them, X represents the initial input features, AvgPool represents average pooling, MaxPool represents maximum pooling, X′ is the fused features after average pooling and maximum pooling, δ is 3 consecutive 3×3 convolutional layers, W is the weight after high-frequency enhancement, G(X) is the filtering weight, Z represents the features after high-frequency enhancement and noise filtering, and Z′ is the final enhanced feature.
[0087] Example
[0088] like Figure 1 and Figure 2 As shown, the method of the present invention comprises the following steps:
[0089] 1. Use Zhang Zhengyou calibration method to calibrate the industrial camera to be used.
[0090] 2. Use the calibrated industrial camera to capture workpiece images.
[0091] 3. Input the collected images into the measurement system. In the measurement system, the collected images will first be input into a VGG16 network for processing. In VGG16, there are 5 pooling layers, and the output of each pooling layer will be used as a new feature. Therefore, after VGG16 processing, 5 features of different resolutions will be obtained, representing basic information of different scales. By inputting the image into the VGG16 network, the measurement system obtains 5 feature representations of different resolutions. These features provide information at multiple scales, from lower-level edges and textures to higher-level object shapes and structures. At the same time, it provides valuable input for subsequent size measurement algorithms.
[0092] 4. After using VGG16 to extract rich original features, the initial features of 5 different resolutions will be input into the scale enhancement module. The scale enhancement module consists of two parts, namely scale enhancement at the same resolution and scale enhancement between different resolutions. The first is scale enhancement at the same resolution. In this process, the output features of each stage will be input into 5 different magnifications of dilated convolutions to learn the input features at the same resolution in parallel, and then these 5 features will be spliced and fused to enhance the network's perception of size changes. Next, three consecutive 3×3 convolutional layers are used to learn the multi-scale information in the fused features, and a 1×1 convolutional layer is used to reduce the number of channels to 1. Finally, the original features are added to the fused features through a residual connection to obtain the final enhanced features, such as Figure 3 shown.
[0093] 5. After scaling the features at the same resolution, you need to scale the features between different resolutions. First, you need to upsample the features of the last four stages to restore them to the size of the previous stage. Then add the upsampled features to the enhanced features of the previous stage to get the final enhanced features.
[0094] 6. After scale enhancement, average pooling and maximum pooling are used to mine edge information in the features. The two feature maps are concatenated together and subjected to three 3×3 convolution operations and a softmax operation to enhance the high-frequency information in the fused features. Figure 4 .
[0095] 7. While performing high-frequency enhancement, a two-layer fully connected network is used as a filter to filter out noise. Then, the filter weights and high-frequency weights are multiplied with the input features to obtain the enhanced features. Finally, the input features are fused with the enhanced features through residual connections.
[0096] 8. Upsample the features of all stages to the size of the original image, fuse the features of all stages by splicing, and then pass a 1×1 convolution layer to reduce the number of channels to 1 to obtain the final fusion result. Visualize the fusion result to output a clear artifact edge. (The model has been trained on the BSDS500 dataset)
[0097] 9. Use an outer rectangular frame to enclose the edges.
[0098] 10. Multiply the pixel size of the circumscribed rectangle by the calibration data to obtain the actual size of the workpiece.
[0099] The size measurement method of the present invention can not only improve the performance and efficiency of the model, but also provide corresponding solutions for the influence of illumination, noise and scale changes, thereby further improving the accuracy of size measurement.
[0100] In response to scale changes, the method of the present invention can learn and fuse features of different scales through the design of a scale enhancement module, thereby enhancing the network's ability to perceive size changes and ensuring that size measurement can maintain a high accuracy at different scales.
[0101] The method of the present invention adopts high-frequency enhancement when processing illumination changes, so as to make the edge part of the image more prominent and reduce the influence of illumination changes on edge detection.
[0102] For noise processing, the method of the present invention adds a filter to reduce noise interference in the image, thereby improving the accuracy and stability of size measurement.
[0103] The size measurement method of the present invention effectively improves the accuracy of size measurement by comprehensively coping with the influence of factors such as illumination, noise and scale change, and has high performance and efficiency in practical applications.
Claims
1. A workpiece size measurement method based on machine vision, characterized in that: The following steps are involved: 1) Calibrate the industrial camera and use the calibrated industrial camera to capture the image of the workpiece to be tested; 2) Use the VGG16 network to extract the initial features of the image at 5 different resolutions; 3) The initial features are scale-enhanced with the same resolution and different resolutions to obtain input features; 4) Perform high-frequency enhanced noise filtering on the input features respectively, and fuse them with the input features to obtain high-frequency features; 5) Repeat steps 3) and 4) to upsample the high-frequency features of all stages to the size of the original workpiece image, fuse the high-frequency features of all stages by splicing, and then pass a 1×1 convolution layer to reduce the number of channels to 1 to obtain the workpiece edge; 6) Use an external rectangular frame to surround the edge of the workpiece, convert the length and width of the external rectangle with the calibration file to obtain the actual size of the workpiece to be measured.
2. The method for measuring workpiece size based on machine vision according to claim 1, characterized in that: The step 3) comprises the following steps: 3.1) Input the initial features of each stage into five different dilated convolutions to learn the initial features at the same resolution in parallel; 3.2) Combine and fuse the five features; 3.3) The fused features are passed through three consecutive 3×3 convolutional layers and one 1×1 convolutional layer to reduce the number of channels to 1 and obtain the fused features; 3.4) The original features are added to the fused features through a residual connection to obtain enhanced features, completing feature scale enhancement at the same resolution; 3.5) Upsample the enhanced features of the last four stages respectively to restore them to the size of the previous stage of the current stage; 3.6) Add the upsampled features of the current stage to the enhanced features of the previous stage to obtain the input features, completing feature scale enhancement at different resolutions.
3. The method for measuring workpiece size based on machine vision according to claim 2, characterized in that: The algorithm for feature scale enhancement at the same resolution is: X i =D(X,r k ) X′=δ[Concat(X1,X2,X3,X4,X5)]·w Y=X′+X Among them, X i represents the features after dilated convolution, D represents the features input into dilated convolution for processing, X represents the initial features, r k represents the dilation rate of the dilated convolution, r k The value range of is {1, 4, 8, 12, 16}, δ is three consecutive 3×3 convolutional layers, w is a 1×1 convolutional layer, Y is the feature after scale enhancement at the same resolution, X′ is the fused feature, and Y is the enhanced feature.
4. The method for measuring workpiece size based on machine vision according to claim 2, characterized in that: The algorithm for feature scale enhancement at different resolutions is: And′=And i +Up(Y i+1 ) Among them, Y′ is the input feature, Y i is the enhanced feature at the same resolution at different stages, Y i+1 It is the enhanced feature of the next stage, and Up means upsampling.
5. The method for measuring workpiece size based on machine vision according to claim 1, characterized in that: The step 4) comprises the following steps: 4.1) The input features are average pooled and max pooled respectively to obtain two feature maps, which are concatenated together and subjected to three 3×3 convolution operations and a softmax operation to complete the high-frequency processing of the input features; 4.2) Use a two-layer fully connected network as a filter to filter the input features; 4.3) Multiply the filter weight, high-frequency weight, and input feature to obtain enhanced features; 4.4) Through residual connection, the input features are fused with the enhanced features to obtain high-frequency features.
6. A method for measuring workpiece size based on machine vision according to claim 5, characterized in that: The algorithm for high frequency enhancement and noise filtering is: X′=Concat[AvgPool(X),MaxPool(X)] W = softmax(δ(X′)) G(X)=Filter(X) Z=G(X)·X·W Z′=Z+X Among them, X represents the input feature, AvgPool represents average pooling, MaxPool represents maximum pooling, X′ is the fused feature after average pooling and maximum pooling, δ is 3 consecutive 3×3 convolutional layers, W is the weight after high-frequency enhancement, G(X) is the filtering weight, Z represents the feature after high-frequency enhancement and noise filtering, and Z′ is the high-frequency feature.
7. The method for measuring workpiece size based on machine vision according to claim 1, characterized in that: The step 6) is specifically as follows: multiplying the pixel size of the circumscribed rectangular frame by the calibration data to obtain the real size of the workpiece.
8. A workpiece size measurement system based on machine vision, characterized in that: include: An image acquisition module is used to calibrate the industrial camera and use the calibrated industrial camera to capture the image of the workpiece to be tested; The feature extraction module is used to extract the initial features of the image at 5 different resolutions using the VGG16 network; The scale enhancement module is used to perform scale enhancement of the initial features with the same resolution and different resolutions to obtain input features; The high-frequency enhancement module is used to perform high-frequency enhancement noise filtering on the input features respectively, and fuse them with the input features to obtain high-frequency features; The feature fusion module is used to upsample the high-frequency features of all stages to the size of the original workpiece image, fuse the high-frequency features of all stages by splicing, and then pass a 1×1 convolution layer to reduce the number of channels to 1 to obtain the industrial edge; The parameter conversion module is used to enclose the industrial edge with an external rectangular frame, convert the length and width of the external rectangle with the calibration file, and obtain the actual size of the workpiece to be measured.
9. A workpiece size measurement system based on machine vision, characterized in that: including memory and processor; The memory is used to store a computer program; the processor is used to implement a workpiece size measurement method based on machine vision as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, a workpiece size measurement method based on machine vision as described in any one of claims 1 to 7 is implemented.