Steel tape surface defect detection method and system and readable storage medium
By combining the twin contrast deep network with multi-scale segmentation and post-processing optimization, the problem of traditional methods being sensitive to illumination changes and background noise is solved, and high-precision and high-efficiency surface defect detection of steel tapes is achieved, improving the detection rate and robustness of minor defects.
Patent Information
- Application Number
- CN202510832473.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-20
- Publication Date
- 2025-10-03
AI Technical Summary
Traditional steel tape surface defect detection methods are sensitive to lighting changes and background noise, have poor adaptability, insufficient detection capabilities, and poor generalization. Deep learning models have difficulty extracting tiny defect features and have high computational complexity and a high false detection rate.
The twin contrast deep network is adopted, through a weight-shared dual-branch convolutional neural network and U-Net network, combined with multi-scale segmentation and post-processing optimization, to extract the difference features between the template image and the image to be inspected, perform connected domain analysis and grayscale contrast secondary verification, and output the defect detection location.
It achieves high-precision and high-efficiency defect detection, significantly improves the detection rate of tiny defects, reduces computing costs, and improves robustness and detection accuracy.
Smart Images

Figure CN120747461A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision and industrial inspection technology, and more specifically, to a method, system and readable storage medium for detecting surface defects of a steel tape measure. Background Art
[0002] Traditional steel tape surface defect detection mainly relies on machine vision algorithms, such as edge detection, threshold segmentation, and morphological operations. However, these methods have the following limitations:
[0003] 1. Parameter sensitivity: Traditional algorithms require manual setting of a large number of parameters (such as thresholds, filter sizes, etc.), are sensitive to factors such as lighting changes and background noise, have poor adaptability, and have high maintenance costs.
[0004] 2. Insufficient detection capabilities: Traditional algorithms are prone to missing or misdetecting tiny defects (such as scratches and pits) or defects against complex texture backgrounds, making it difficult to meet the accuracy requirements of industrial scenarios.
[0005] 3. Poor generalization: Algorithm parameters need to be readjusted for tape measures of different models or production batches, resulting in a lack of universality.
[0006] In recent years, deep learning technology has demonstrated significant advantages in defect detection due to its powerful feature extraction and end-to-end learning capabilities. However, existing deep learning models (such as CNN and YOLO) have the following problems in steel tape inspection:
[0007] 1. Weak defect features: The defects on the tape measure surface are small in size and have low contrast with the background, making it difficult for ordinary networks to effectively extract defect features.
[0008] 2. High computational complexity: Directly inputting high-resolution images into the model will result in high consumption of computing resources and it is difficult to meet the needs of real-time detection.
[0009] 3. High false detection rate: There are a large number of similar textures or noise interference in industrial scenes, and the defect mask output by a single model may contain false detection areas. Summary of the Invention
[0010] The purpose of the present invention is to provide a method, system and readable storage medium for detecting surface defects of a steel tape measure, which are particularly suitable for scenarios of high-precision and high-efficiency automated detection of tape measure defects.
[0011] A first aspect of the present invention provides a method for detecting surface defects of a steel tape measure, which is applied to a twin comparison deep network and includes the following steps:
[0012] Receive the template image of the steel tape measure and the image to be inspected;
[0013] Obtaining an initial defect mask based on the template image and the image to be inspected;
[0014] Flipping the image to be inspected horizontally and combining it with the template image to obtain a flip mask;
[0015] Obtaining a defect mask based on the initial defect mask and the flip mask;
[0016] Connected domain analysis and grayscale contrast are performed based on the defect mask to perform secondary verification and output the defect detection position.
[0017] In this solution, the twin contrast deep network specifically includes:
[0018] An input layer, configured to receive an image and perform pixel normalization, the received image including the template image and the image to be inspected;
[0019] A feature extraction module, used to extract a feature map of a received image;
[0020] The difference calculation module is used to calculate the absolute value difference of the feature map pixel by pixel to obtain the difference feature map;
[0021] The defect segmentation module is used to perform pixel-level segmentation on the difference feature map to obtain a defect mask;
[0022] The output layer is used to output the defect detection location based on the defect mask.
[0023] In this solution, the feature extraction module and the difference calculation module adopt a two-branch convolutional neural network with shared weights, and the difference calculation module performs feature amplification and dimensionality reduction through convolution operation after calculating the difference feature map, and the defect segmentation module adopts U-Net network for pixel-level segmentation.
[0024] In this solution, the shared weights in the weight-sharing dual-branch convolutional neural network are obtained through contrastive learning pre-training, specifically including:
[0025] Input a pair of defect-free template images and extract feature maps respectively through a two-branch convolutional neural network with shared weights;
[0026] Minimize the difference loss of the feature maps output by the two branches, where the difference loss is calculated by the mean square error or L1 norm;
[0027] Cosine similarity is used as the optimization objective to maximize the similarity of the feature vectors of the two branches and constrain the consistency of the dual-branch features in the vector space.
[0028] In this solution, the U-Net network specifically includes:
[0029] The encoder corresponds to four levels of downsampling, each level contains two convolutional layers, and the number of channels is 8, 16, 32, and 64 respectively;
[0030] The decoder corresponds to four levels of upsampling, and each level fuses shallow features through transposed convolution and skip connection;
[0031] The output layer, including 1×1 convolution and Sigmoid activation function, is used to generate binary mask data.
[0032] In this solution, connected domain analysis and grayscale contrast are performed based on the defect mask to output the defect detection location. Specifically, the following steps are performed:
[0033] Identifying candidate regions of the defect mask based on eight-neighborhood traversal;
[0034] Performing area filtering and morphological closing operations based on the candidate regions to complete connected domain analysis;
[0035] During the secondary verification, the grayscale difference between the candidate area and the matching template is calculated, wherein the candidate area with a grayscale difference greater than a preset threshold is extracted as the defect detection position.
[0036] A second aspect of the present invention further provides a steel tape measure surface defect detection system, comprising a memory and a processor, wherein the memory comprises a steel tape measure surface defect detection method program, and when the steel tape measure surface defect detection method program is executed by the processor, the following steps are implemented:
[0037] Receive the template image of the steel tape measure and the image to be inspected;
[0038] Obtaining an initial defect mask based on the template image and the image to be inspected;
[0039] Flipping the image to be inspected horizontally and combining it with the template image to obtain a flip mask;
[0040] Obtaining a defect mask based on the initial defect mask and the flip mask;
[0041] Connected domain analysis and grayscale contrast are performed based on the defect mask to perform secondary verification and output the defect detection position.
[0042] In this solution, the twin contrast deep network specifically includes:
[0043] An input layer, configured to receive an image and perform pixel normalization, the received image including the template image and the image to be inspected;
[0044] A feature extraction module, used to extract a feature map of a received image;
[0045] The difference calculation module is used to calculate the absolute value difference of the feature map pixel by pixel to obtain the difference feature map;
[0046] The defect segmentation module is used to perform pixel-level segmentation on the difference feature map to obtain a defect mask;
[0047] The output layer is used to output the defect detection location based on the defect mask.
[0048] In this solution, the feature extraction module and the difference calculation module adopt a two-branch convolutional neural network with shared weights, and the difference calculation module performs feature amplification and dimensionality reduction through convolution operation after calculating the difference feature map, and the defect segmentation module adopts U-Net network for pixel-level segmentation.
[0049] In this solution, the shared weights in the weight-sharing dual-branch convolutional neural network are obtained through contrastive learning pre-training, specifically including:
[0050] Input a pair of defect-free template images and extract feature maps respectively through a two-branch convolutional neural network with shared weights;
[0051] Minimize the difference loss of the feature maps output by the two branches, where the difference loss is calculated by the mean square error or L1 norm;
[0052] Cosine similarity is used as the optimization objective to maximize the similarity of the feature vectors of the two branches and constrain the consistency of the dual-branch features in the vector space.
[0053] In this solution, the U-Net network specifically includes:
[0054] The encoder corresponds to four levels of downsampling, each level contains two convolutional layers, and the number of channels is 8, 16, 32, and 64 respectively;
[0055] The decoder corresponds to four levels of upsampling, and each level fuses shallow features through transposed convolution and skip connection;
[0056] The output layer, including 1×1 convolution and Sigmoid activation function, is used to generate binary mask data.
[0057] In this solution, connected domain analysis and grayscale contrast are performed based on the defect mask to output the defect detection location. Specifically, the following steps are performed:
[0058] Identifying candidate regions of the defect mask based on eight-neighborhood traversal;
[0059] Performing area filtering and morphological closing operations based on the candidate regions to complete connected domain analysis;
[0060] During the secondary verification, the grayscale difference between the candidate area and the matching template is calculated, wherein the candidate area with a grayscale difference greater than a preset threshold is extracted as the defect detection position.
[0061] The third aspect of the present invention provides a computer-readable storage medium, which includes a machine program for a method for detecting surface defects of a steel tape measure. When the program for detecting surface defects of a steel tape measure is executed by a processor, the steps of a method for detecting surface defects of a steel tape measure as described in any one of the above items are implemented.
[0062] The present invention discloses a method, system and readable storage medium for detecting surface defects of steel tape measures. The method extracts the difference features between the template image and the image to be inspected through a twin network structure, combines multi-scale segmentation and post-processing optimization, can achieve high-precision defect positioning, can significantly improve the detection rate of minor defects, and has low computational cost. Accuracy and efficiency can be balanced through shared weights and subgraph cutting. In addition, robustness is improved by suppressing complex interference through flipping fusion and secondary verification. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 A diagram showing the steps of a method for detecting surface defects of a steel tape measure according to the present invention is shown;
[0064] Figure 2 A flow chart of a method for detecting surface defects of a steel tape measure according to the present invention is shown;
[0065] Figure 3 A block diagram of a steel tape surface defect detection system according to the present invention is shown. DETAILED DESCRIPTION
[0066] In order to more clearly understand the above-mentioned objects, features and advantages of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that, in the absence of conflict, the embodiments of the present application and the features therein can be combined with each other.
[0067] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Therefore, the scope of protection of the present invention is not limited to the specific embodiments disclosed below.
[0068] This paper proposes a defect detection method that combines twin networks, multi-scale fusion and post-processing optimization to significantly improve detection accuracy and robustness. Figure 1 A step diagram of a method for detecting surface defects of a steel tape measure according to the present application is shown.
[0069] like Figure 1 As shown, the present application discloses a method for detecting surface defects of a steel tape measure, which is applied to a twin comparison deep network and includes the following steps:
[0070] S102, receiving a template image of a steel tape measure and an image to be inspected;
[0071] S104, obtaining an initial defect mask based on the template image and the image to be inspected;
[0072] S106, horizontally flipping the image to be inspected and combining it with the template image to obtain a flip mask;
[0073] S108, obtaining a defect mask based on the initial defect mask and the flip mask;
[0074] S110 , performing connected domain analysis and grayscale contrast secondary verification based on the defect mask to output a defect detection position.
[0075] It should be noted that, in this embodiment, the twin contrast deep network includes a dual-branch neural network and a U-Net network with shared weights, wherein Figure 2 As shown, the present application provides a flow chart of a method for detecting surface defects of steel tape measures. First, a dual-branch convolutional neural network with shared weights is used to extract the deep features of the template image and the image to be inspected respectively to generate a difference feature map. Then, the convolution layer is used to perform channel amplification and dimensionality reduction on the difference feature map to amplify the defect response. The U-Net network is used to perform pixel-level segmentation on the feature map after dimensionality reduction to output the initial defect mask. The image to be inspected is horizontally flipped and the above steps are repeated to obtain a flipped mask. After inversion, the average value is taken with the original mask to generate a final mask. Finally, the final mask is subjected to Blob connected domain analysis and traditional grayscale contrast secondary verification to output the defect position. Among them, the jump connection structure of the U-Net network can fuse shallow details and deep semantic information to improve the segmentation accuracy of small defects.
[0076] Furthermore, an initial defect mask Mask1 is obtained based on the template image and the image to be inspected. The image to be inspected is horizontally flipped and input into the network again to generate a flipped mask Mask2, which is then reversed back to the original coordinates to obtain Mask3. The final defect mask corresponds to the average value of Mask1 and Mask3 to eliminate edge false detection.
[0077] According to an embodiment of the present invention, the twin contrast deep network specifically includes:
[0078] An input layer, configured to receive an image and perform pixel normalization, the received image including the template image and the image to be inspected;
[0079] A feature extraction module, used to extract a feature map of a received image;
[0080] The difference calculation module is used to calculate the absolute value difference of the feature map pixel by pixel to obtain the difference feature map;
[0081] The defect segmentation module is used to perform pixel-level segmentation on the difference feature map to obtain a defect mask;
[0082] The output layer is used to output the defect detection location based on the defect mask.
[0083] It should be noted that, in this embodiment, the feature extraction module and the difference calculation module adopt a two-branch convolutional neural network with shared weights, and the difference calculation module performs feature amplification and dimensionality reduction through convolution operation after calculating the difference feature map, and the defect segmentation module adopts the U-Net network for pixel-level segmentation.
[0084] Furthermore, it should be noted that, in this embodiment, a two-branch convolutional neural network with shared weights is used to extract the deep features of the template image (defect-free standard image) and the image to be inspected, respectively. A two-branch convolutional structure with shared weights is used, and the input is a "256×256" RGB image. Through "5" layers of 3×3 convolution kernel stacking (each layer outputs a 4-channel feature map), each two layers are followed by a batch normalization layer and a ReLU activation function to gradually extract local detail features, and finally output a four-channel feature map, as shown in Table 1. The shared weight design ensures that the template image and the image to be inspected are encoded in the same feature space, reducing redundant calculations.
[0085] Table 1. Dual-branch convolutional structure with shared weights
[0086]
[0087] Furthermore, the feature maps of the template image and the image to be inspected are subtracted pixel by pixel to generate a difference feature map. Subsequently, feature amplification and dimensionality reduction are performed through a two-stage convolution operation (4→16→8 channels). A 3×3 convolution kernel is used to amplify the response of the defect area while suppressing background noise. The significance of the defect features is enhanced through channel adjustment and ReLU activation, providing high-contrast input for subsequent segmentation.
[0088] Furthermore, according to an embodiment of the present invention, the U-Net network specifically includes:
[0089] The encoder corresponds to four levels of downsampling, each level contains two convolutional layers, and the number of channels is 8, 16, 32, and 64 respectively;
[0090] The decoder corresponds to four levels of upsampling, and each level fuses shallow features through transposed convolution and skip connection;
[0091] The output layer, including 1×1 convolution and Sigmoid activation function, is used to generate binary mask data.
[0092] It should be noted that, in this embodiment, the defect segmentation module is used to perform pixel-level segmentation on the difference feature map to obtain a defect mask. Specifically, the U-Net network is used to perform pixel-level segmentation to generate the corresponding defect mask. Accordingly, the U-Net network includes an encoder, which corresponds to four levels of downsampling, each level contains two convolution layers, and the number of channels is "8, 16, 32, 64," respectively, and a decoder, which corresponds to four levels of upsampling, each level fuses shallow features through transposed convolution and jump connection, and an output layer, including 1×1 convolution and Sigmoid activation function, for generating binary mask data, that is, for generating the defect mask.
[0093] Furthermore, according to an embodiment of the present invention, a connected domain analysis and grayscale contrast secondary verification based on the defect mask are performed to output the defect detection position, specifically including:
[0094] Identifying candidate regions of the defect mask based on eight-neighborhood traversal;
[0095] Performing area filtering and morphological closing operations based on the candidate regions to complete connected domain analysis;
[0096] During the secondary verification, the grayscale difference between the candidate area and the matching template is calculated, wherein the candidate area with a grayscale difference greater than a preset threshold is extracted as the defect detection position.
[0097] It should be noted that, in this embodiment, after obtaining the defect mask, the final defect detection position must be output, which includes Blob connected domain analysis and a secondary verification process. Specifically, the mask is subjected to connected domain analysis, and the noise area with an area smaller than the set threshold is filtered out. The candidate defects are verified in combination with the traditional defect detection algorithm based on grayscale template matching to further reduce the false detection rate. Among them, Blob Connected Component Analysis is a basic technology in image processing, which is used to identify and mark interconnected pixel areas in an image. In this embodiment, it is used as a direct application, and the specific process will not be repeated.
[0098] According to an embodiment of the present invention, the shared weights in the weight-sharing dual-branch convolutional neural network are obtained through contrastive learning pre-training, specifically including:
[0099] Input a pair of defect-free template images and extract feature maps respectively through a two-branch convolutional neural network with shared weights;
[0100] Minimize the difference loss of the feature maps output by the two branches, where the difference loss is calculated by the mean square error or L1 norm;
[0101] Cosine similarity is used as the optimization objective to maximize the similarity of the feature vectors of the two branches and constrain the consistency of the dual-branch features in the vector space.
[0102] It should be noted that, in this embodiment, the shared weights in the weight-sharing dual-branch convolutional neural network are obtained through contrastive learning pre-training, and the twin contrastive deep network used in this embodiment is also trained, and the training steps are as follows:
[0103] 1. Data preparation and preprocessing
[0104] Data collection: Use industrial cameras to capture images of defect-free templates and samples with defects such as scratches and pits, covering different lighting, angles and background interference.
[0105] Data augmentation: Apply geometric transformations (flip, rotation), noise injection (Gaussian, salt and pepper noise), and brightness adjustment.
[0106] Dataset division: The training set and validation set are divided into a ratio of 7:3.
[0107] 2. Model training and optimization
[0108] Network initialization: input size 256×128×3, optimizer is Adam (learning rate 1e-4), loss function is Dice Loss+L1 Loss.
[0109] Training process: divided into two stages of training, the first stage is pre-training feature extraction layer, and the second stage is end-to-end fine-tuning.
[0110] Model evaluation: precision > 98%, recall > 95%, F1 Score > 96%.
[0111] Among them, when the twin contrast deep network training is completed, the corresponding shared weight dual-branch convolutional neural network training is also completed. Correspondingly, the shared weights are also obtained through contrastive learning pre-training. Specifically, when a pair of defect-free template images is input, the feature maps are extracted separately through the shared weight dual-branch convolutional neural network, thereby minimizing the difference loss of the feature maps output by the two branches. In the specific calculation, the difference loss can be calculated by mean square error or L1 norm. Finally, cosine similarity is used as the optimization target to maximize the similarity of the two-branch feature vectors to constrain the consistency of the dual-branch features in the vector space.
[0112] It is worth mentioning that when the input layer receives an image, it cuts the original high-resolution image into target sub-images, scales them to a uniform size, and then inputs them into the network.
[0113] It should be noted that, in this embodiment, the original high-resolution image (such as "320×2560") is cut into "320×512" sub-images, which are scaled to a uniform size (such as "160×256") before being input into the network.
[0114] Figure 3 A block diagram of a steel tape surface defect detection system according to the present invention is shown.
[0115] like Figure 3 As shown, the present invention discloses a steel tape surface defect detection system, including a memory and a processor. The memory includes a steel tape surface defect detection method program. When the steel tape surface defect detection method program is executed by the processor, the following steps are implemented:
[0116] Receive the template image of the steel tape measure and the image to be inspected;
[0117] Obtaining an initial defect mask based on the template image and the image to be inspected;
[0118] Flipping the image to be inspected horizontally and combining it with the template image to obtain a flip mask;
[0119] Obtaining a defect mask based on the initial defect mask and the flip mask;
[0120] Connected domain analysis and grayscale contrast are performed based on the defect mask to perform secondary verification and output the defect detection position.
[0121] It should be noted that, in this embodiment, the twin contrast deep network includes a dual-branch neural network and a U-Net network with shared weights, wherein Figure 2 As shown, the present application provides a flow chart of a method for detecting surface defects of steel tape measures. First, a dual-branch convolutional neural network with shared weights is used to extract the deep features of the template image and the image to be inspected respectively to generate a difference feature map. Then, the convolution layer is used to perform channel amplification and dimensionality reduction on the difference feature map to amplify the defect response. The U-Net network is used to perform pixel-level segmentation on the feature map after dimensionality reduction to output the initial defect mask. The image to be inspected is horizontally flipped and the above steps are repeated to obtain a flipped mask. After inversion, the average value is taken with the original mask to generate a final mask. Finally, the final mask is subjected to Blob connected domain analysis and traditional grayscale contrast secondary verification to output the defect position. Among them, the jump connection structure of the U-Net network can fuse shallow details and deep semantic information to improve the segmentation accuracy of small defects.
[0122] Furthermore, an initial defect mask Mask1 is obtained based on the template image and the image to be inspected. The image to be inspected is horizontally flipped and input into the network again to generate a flipped mask Mask2, which is then reversed back to the original coordinates to obtain Mask3. The final defect mask corresponds to the average value of Mask1 and Mask3 to eliminate edge false detection.
[0123] According to an embodiment of the present invention, the twin contrast deep network specifically includes:
[0124] An input layer, configured to receive an image and perform pixel normalization, the received image including the template image and the image to be inspected;
[0125] A feature extraction module, used to extract a feature map of a received image;
[0126] The difference calculation module is used to calculate the absolute value difference of the feature map pixel by pixel to obtain the difference feature map;
[0127] The defect segmentation module is used to perform pixel-level segmentation on the difference feature map to obtain a defect mask;
[0128] The output layer is used to output the defect detection location based on the defect mask.
[0129] It should be noted that, in this embodiment, the feature extraction module and the difference calculation module adopt a two-branch convolutional neural network with shared weights, and the difference calculation module performs feature amplification and dimensionality reduction through convolution operation after calculating the difference feature map, and the defect segmentation module adopts the U-Net network for pixel-level segmentation.
[0130] Furthermore, it should be noted that, in this embodiment, a two-branch convolutional neural network with shared weights is used to extract the deep features of the template image (defect-free standard image) and the image to be inspected, respectively. A two-branch convolutional structure with shared weights is used, and the input is a "256×256" RGB image. Through "5" layers of 3×3 convolution kernel stacking (each layer outputs a 4-channel feature map), each two layers are followed by a batch normalization layer and a ReLU activation function to gradually extract local detail features, and finally output a four-channel feature map, as shown in Table 1. The shared weight design ensures that the template image and the image to be inspected are encoded in the same feature space, reducing redundant calculations.
[0131] Furthermore, the feature maps of the template image and the image to be inspected are subtracted pixel by pixel to generate a difference feature map. Subsequently, feature amplification and dimensionality reduction are performed through a two-stage convolution operation (4→16→8 channels). A 3×3 convolution kernel is used to amplify the response of the defect area while suppressing background noise. The significance of the defect features is enhanced through channel adjustment and ReLU activation, providing high-contrast input for subsequent segmentation.
[0132] Furthermore, according to an embodiment of the present invention, the U-Net network specifically includes:
[0133] The encoder corresponds to four levels of downsampling, each level contains two convolutional layers, and the number of channels is 8, 16, 32, and 64 respectively;
[0134] The decoder corresponds to four levels of upsampling, and each level fuses shallow features through transposed convolution and skip connection;
[0135] The output layer, including 1×1 convolution and Sigmoid activation function, is used to generate binary mask data.
[0136] It should be noted that, in this embodiment, the defect segmentation module is used to perform pixel-level segmentation on the difference feature map to obtain a defect mask. Specifically, the U-Net network is used to perform pixel-level segmentation to generate the corresponding defect mask. Accordingly, the U-Net network includes an encoder, which corresponds to four levels of downsampling, each level contains two convolution layers, and the number of channels is "8, 16, 32, 64," respectively, and a decoder, which corresponds to four levels of upsampling, each level fuses shallow features through transposed convolution and jump connection, and an output layer, including 1×1 convolution and Sigmoid activation function, for generating binary mask data, that is, for generating the defect mask.
[0137] Furthermore, according to an embodiment of the present invention, a connected domain analysis and grayscale contrast secondary verification based on the defect mask are performed to output the defect detection position, specifically including:
[0138] Identifying candidate regions of the defect mask based on eight-neighborhood traversal;
[0139] Performing area filtering and morphological closing operations based on the candidate regions to complete connected domain analysis;
[0140] During the secondary verification, the grayscale difference between the candidate area and the matching template is calculated, wherein the candidate area with a grayscale difference greater than a preset threshold is extracted as the defect detection position.
[0141] It should be noted that, in this embodiment, after obtaining the defect mask, the final defect detection position must be output, which includes Blob connected domain analysis and a secondary verification process. Specifically, the mask is subjected to connected domain analysis, and the noise area with an area smaller than the set threshold is filtered out. The candidate defects are verified in combination with the traditional defect detection algorithm based on grayscale template matching to further reduce the false detection rate. Among them, Blob Connected Component Analysis is a basic technology in image processing, which is used to identify and mark interconnected pixel areas in an image. In this embodiment, it is used as a direct application, and the specific process will not be repeated.
[0142] According to an embodiment of the present invention, the shared weights in the weight-sharing dual-branch convolutional neural network are obtained through contrastive learning pre-training, specifically including:
[0143] Input a pair of defect-free template images and extract feature maps respectively through a two-branch convolutional neural network with shared weights;
[0144] Minimize the difference loss of the feature maps output by the two branches, where the difference loss is calculated by the mean square error or L1 norm;
[0145] Cosine similarity is used as the optimization objective to maximize the similarity of the feature vectors of the two branches and constrain the consistency of the dual-branch features in the vector space.
[0146] It should be noted that, in this embodiment, the shared weights in the weight-sharing dual-branch convolutional neural network are obtained through contrastive learning pre-training, and the twin contrastive deep network used in this embodiment is also trained, and the training steps are as follows:
[0147] 1. Data preparation and preprocessing
[0148] Data collection: Use industrial cameras to capture images of defect-free templates and samples with defects such as scratches and pits, covering different lighting, angles and background interference.
[0149] Data augmentation: Apply geometric transformations (flip, rotation), noise injection (Gaussian, salt and pepper noise), and brightness adjustment.
[0150] Dataset division: The training set and validation set are divided into a ratio of 7:3.
[0151] 2. Model training and optimization
[0152] Network initialization: input size 256×128×3, optimizer is Adam (learning rate 1e-4), loss function is Dice Loss+L1 Loss.
[0153] Training process: divided into two stages of training, the first stage is pre-training feature extraction layer, and the second stage is end-to-end fine-tuning.
[0154] Model evaluation: precision > 98%, recall > 95%, F1 Score > 96%.
[0155] Among them, when the twin contrast deep network training is completed, the corresponding shared weight dual-branch convolutional neural network training is also completed. Correspondingly, the shared weights are also obtained through contrastive learning pre-training. Specifically, when a pair of defect-free template images is input, the feature maps are extracted separately through the shared weight dual-branch convolutional neural network, thereby minimizing the difference loss of the feature maps output by the two branches. In the specific calculation, the difference loss can be calculated by mean square error or L1 norm. Finally, cosine similarity is used as the optimization target to maximize the similarity of the two-branch feature vectors to constrain the consistency of the dual-branch features in the vector space.
[0156] It is worth mentioning that when the input layer receives an image, it cuts the original high-resolution image into target sub-images, scales them to a uniform size, and then inputs them into the network.
[0157] It should be noted that, in this embodiment, the original high-resolution image (such as "320×2560") is cut into "320×512" sub-images, which are scaled to a uniform size (such as "160×256") before being input into the network.
[0158] The third aspect of the present invention provides a computer-readable storage medium, which includes a steel tape measure surface defect detection method program. When the steel tape measure surface defect detection method program is executed by a processor, the steps of a steel tape measure surface defect detection method as described in any one of the above items are implemented.
[0159] The present invention discloses a method, system and readable storage medium for detecting surface defects of steel tape measures. The method extracts the difference features between the template image and the image to be inspected through a twin network structure, combines multi-scale segmentation and post-processing optimization, can achieve high-precision defect positioning, can significantly improve the detection rate of minor defects, and has low computational cost. Accuracy and efficiency can be balanced through shared weights and subgraph cutting. In addition, robustness is improved by suppressing complex interference through flipping fusion and secondary verification.
[0160] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0161] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed across multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the scheme of this embodiment.
[0162] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0163] Those skilled in the art will appreciate that all or part of the steps of the above-mentioned method embodiments may be implemented by hardware associated with program instructions, and the aforementioned program may be stored in a computer-readable storage medium. When the program is executed, the program executes the steps of the above-mentioned method embodiments. The aforementioned storage medium includes various media that can store program codes, such as mobile storage devices, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.
[0164] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
Claims
1. A method for detecting surface defects of a steel tape, characterized in that: Applied to a twin contrast deep network, the method comprises the following steps: Receive the template image of the steel tape measure and the image to be inspected; Obtaining an initial defect mask based on the template image and the image to be inspected; Flipping the image to be inspected horizontally and combining it with the template image to obtain a flip mask; Obtaining a defect mask based on the initial defect mask and the flip mask; Connected domain analysis and grayscale contrast are performed based on the defect mask to perform secondary verification and output the defect detection position.
2. A method for detecting surface defects of a steel tape according to claim 1, characterized in that: The twin contrast deep network specifically includes: An input layer, configured to receive an image and perform pixel normalization, the received image including the template image and the image to be inspected; A feature extraction module, used to extract a feature map of a received image; The difference calculation module is used to calculate the absolute value difference of the feature map pixel by pixel to obtain the difference feature map; The defect segmentation module is used to perform pixel-level segmentation on the difference feature map to obtain a defect mask; The output layer is used to output the defect detection location based on the defect mask.
3. A method for detecting surface defects of a steel tape according to claim 2, characterized in that: The feature extraction module and the difference calculation module adopt a dual-branch convolutional neural network with shared weights, and the difference calculation module performs feature amplification and dimensionality reduction through convolution operations after calculating the difference feature map, and the defect segmentation module adopts a U-Net network for pixel-level segmentation.
4. A method for detecting surface defects of a steel tape according to claim 3, characterized in that: The shared weights in the weight-sharing dual-branch convolutional neural network are obtained through contrastive learning pre-training, specifically including: Input a pair of defect-free template images and extract feature maps respectively through a two-branch convolutional neural network with shared weights; Minimize the difference loss of the feature maps output by the two branches, where the difference loss is calculated by the mean square error or L1 norm; Cosine similarity is used as the optimization objective to maximize the similarity of the feature vectors of the two branches and constrain the consistency of the dual-branch features in the vector space.
5. A method for detecting surface defects of a steel tape according to claim 4, characterized in that: The U-Net network specifically includes: The encoder corresponds to four levels of downsampling, each level contains two convolutional layers, and the number of channels is 8, 16, 32, and 64 respectively; The decoder corresponds to four levels of upsampling, and each level fuses shallow features through transposed convolution and skip connection; The output layer, including 1×1 convolution and Sigmoid activation function, is used to generate binary mask data.
6. A method for detecting surface defects of a steel tape according to claim 5, characterized in that: Connected domain analysis and grayscale contrast are performed based on the defect mask to perform secondary verification and output the defect detection location, specifically including: Identifying candidate regions of the defect mask based on eight-neighborhood traversal; Performing area filtering and morphological closing operations based on the candidate regions to complete connected domain analysis; During the secondary verification, the grayscale difference between the candidate area and the matching template is calculated, wherein the candidate area with a grayscale difference greater than a preset threshold is extracted as the defect detection position.
7. A steel tape surface defect detection system, characterized in that: The invention comprises a memory and a processor, wherein the memory comprises a method program for detecting surface defects of a steel tape measure, and when the method program for detecting surface defects of a steel tape measure is executed by the processor, the following steps are implemented: Receive the template image of the steel tape measure and the image to be inspected; Obtaining an initial defect mask based on the template image and the image to be inspected; Flipping the image to be inspected horizontally and combining it with the template image to obtain a flip mask; Obtaining a defect mask based on the initial defect mask and the flip mask; Connected domain analysis and grayscale contrast are performed based on the defect mask to perform secondary verification and output the defect detection position.
8. The steel tape surface defect detection system according to claim 7, characterized in that: The twin contrast deep network specifically includes: An input layer, configured to receive an image and perform pixel normalization, the received image including the template image and the image to be inspected; A feature extraction module, used to extract a feature map of a received image; The difference calculation module is used to calculate the absolute value difference of the feature map pixel by pixel to obtain the difference feature map; The defect segmentation module is used to perform pixel-level segmentation on the difference feature map to obtain a defect mask; The output layer is used to output the defect detection location based on the defect mask.
9. The steel tape surface defect detection system according to claim 8, characterized in that: The feature extraction module adopts a two-branch convolutional neural network with shared weights, and the difference calculation module performs feature amplification and dimensionality reduction through convolution operation after calculating the difference feature map. The shared weights in the two-branch convolutional neural network with shared weights are obtained through contrastive learning pre-training, specifically including: Input a pair of defect-free template images and extract feature maps respectively through a two-branch convolutional neural network with shared weights; Minimize the difference loss of the feature maps output by the two branches, where the difference loss is calculated by the mean square error or L1 norm; Cosine similarity is used as the optimization objective to maximize the similarity of the feature vectors of the two branches and constrain the consistency of the dual-branch features in the vector space.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a steel tape measure surface defect detection method program. When the steel tape measure surface defect detection method program is executed by a processor, the steps of a steel tape measure surface defect detection method as described in any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Ancient building image change detection method based on computer vision
CN122135216A
Computer vision-based image change detection method for ancient buildings
CN122135216B