A method and system for industrial manufacturing general defect detection
By combining baseline image construction and ORB-RANSAC registration algorithm with ResNet-50 feature extraction network, high-precision industrial defect detection with a small number of samples is achieved, solving the problems of high training cost and slow adaptation of traditional models, and adapting to small and medium batch multi-category production.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN ZHISOFT TECH CO LTD
- Filing Date
- 2026-03-30
- Publication Date
- 2026-08-04
AI Technical Summary
Traditional AI visual inspection models cannot be effectively trained in industrial scenarios where defect samples are scarce. Furthermore, when product models are updated, a large number of samples need to be collected and retrained, resulting in high costs and long training cycles, making it difficult to adapt to the flexible needs of small-batch, multi-category production.
The method employs a baseline image for construction and to-be-detected region calibration, combined with an image registration algorithm that integrates ORB feature point matching and RANSAC spatial correction. It utilizes a ResNet-50 feature extraction network and cosine similarity calculation to achieve rapid detection with a small number of positive and negative samples, requiring only 20-30 positive samples and 10-20 negative samples.
It reduces the cost of sample collection and labeling, improves detection accuracy, meets the flexible needs of small-batch, multi-category production, and eliminates the need to retrain the model when product models are updated.
Smart Images

Figure CN122510152A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial inspection, specifically a general defect detection method and system for industrial manufacturing. Background Technology
[0002] Currently in the industrial field, traditional AI visual defect detection solutions are the mainstream technology for achieving automated product defect detection. The core logic of this technology is as follows: first, a large number of labeled samples are collected (usually hundreds to thousands of labeled images containing various defects), then the detection model is trained based on these samples, and after training, the product image to be tested is input into the model, and the model identifies the defect features in the image to complete the detection.
[0003] However, this existing technology has obvious drawbacks and limitations, as follows: 1. The accuracy of traditional AI visual inspection models depends entirely on large-scale labeled samples. However, in actual industrial scenarios, defect samples for high-value precision parts and new mass-produced products are naturally scarce. In some scenarios, it is even impossible to collect enough defect samples, which makes it impossible for the model to complete effective training and the inspection solution to be implemented. 2. When product models are updated or testing standards are adjusted, it is necessary to collect a large number of new samples and conduct full model training. The training cycle usually takes 1-7 days, which is not only time-consuming, but also incurs high costs for sample collection, annotation and model optimization. 3. For small-batch, multi-category production models, traditional solutions are difficult to adapt quickly to the testing needs of different product categories due to the high costs of sample collection and model training, and cannot meet the testing requirements of flexible production. Summary of the Invention
[0004] The purpose of this invention is to provide a general defect detection method for industrial manufacturing to solve the problems in the prior art.
[0005] The objective of this invention can be achieved through the following technical solutions: A general defect detection method for industrial manufacturing includes the following steps: S1. Construction of the baseline image and calibration of the region to be detected, the specific steps are as follows: S11. Select a product image with no defects, light intensity of 500-1000 lux, no obstruction, and no reflection as the reference image. The image resolution is ≥1920×1080 pixels, and the detail clarity of the area to be inspected is ≥300 DPI. S12. Engineers manually select rectangular regions to be detected. The minimum size of a single region is ≥50×50 pixels, and the distance between adjacent regions is ≥10 pixels. 1-10 regions to be detected can be selected in the same image. The shape of the selection includes rectangles, circles, and polygons with more than four sides. S13. Automatically identify the pixel coordinates of the selected area using a pixel coordinate traversal algorithm. The coordinate extraction error is ≤1 pixel. Generate a coordinate file containing the area number, coordinate range, and selection timestamp. S14. Associate and store the reference image with the coordinate file. The storage media include local SSD, mechanical hard disk, and cloud server storage. S2. Positive and negative sample storage and extraction of the region to be detected, the specific steps are as follows: S21. Select 10-30 positive samples and use an image registration and alignment model with ORB feature point matching and RANSAC spatial correction. Based on the coordinate file in S1, automatically crop the area to be detected using a rectangular cropping algorithm. The cropped edges are free of jagged edges and stretching distortion. Generate an image file and store it together with the coordinate file. S22. Select 10-20 negative samples containing clear defects. Use an image registration and alignment model with ORB feature point matching and RANSAC spatial correction. Based on the coordinate file in S1, automatically crop the area to be detected using a rectangular cropping algorithm. The cropped edges are free of jagged edges and stretching distortion. Generate an image file and store it together with the coordinate file. S3. Image acquisition, the specific steps are as follows: S31. Real-time images are acquired through an industrial camera. The images are clear, unobstructed, and free of reflections, and the shooting environment is consistent with the reference image. S32. Align the detection area of the image to be tested with the detection area of the reference image at the pixel level; based on the coordinate file in S1, extract the image of the detection area through a cropping algorithm within a limited range, and the size and position of the extracted area are consistent with the image in the sample library; S4. Similarity calculation and result output, the specific steps are as follows: S41. Similarity calculation is performed using a ResNet-50 feature extraction network in conjunction with a cosine similarity calculation module. First, a 2048-dimensional feature vector is extracted through the ResNet-50 network, and then the cosine similarity between the image to be tested and the sample image is calculated. S42. If all areas to be inspected meet the defect-free condition, output a qualified signal and inspection report; if any area to be inspected does not meet the defect-free condition, output a non-qualified signal and inspection report. The non-qualified inspection report includes the defect area number, defect type, similarity data and defect image, and automatically stores the image to be inspected and the processing data. The storage retention time is ≥90 days, and the storage media includes local SSD and cloud server storage, which supports traceability query.
[0006] Preferably, the specific steps of the image registration and alignment model in step S2, which combines ORB feature point matching with RANSAC spatial correction, are as follows: first, extract ≥500 key feature points from a single image using the ORB algorithm; then, filter matching feature points using a Hamming distance ≤50 as a threshold; and finally, eliminate shooting angle deviation and placement position deviation using the RANSAC algorithm, resulting in a pixel deviation ≤1 pixel after registration.
[0007] Preferably, the defect types in step 22 include scratches, cracks, stains, deformation, missing parts, extraneous materials, dimensional deviations, and assembly misalignments, and the defect area falls entirely within the area to be inspected, with a defect area ≥ 5×5 pixels.
[0008] Preferably, in step S42, if the number of matched feature points is less than 300, an abnormal detection signal is output, and the image is automatically re-acquired. If the failure still occurs after three attempts, an alarm is triggered. The alarm methods include audible and visual alarms, SMS notifications, and system pop-up alarms.
[0009] Preferably, the ResNet-50 feature vector extraction operation in step S41 is as follows: S411. The cropped image of the region to be detected is normalized to a size of 224×224 pixels. Bilinear interpolation algorithm is used to adjust the size to avoid image distortion. At the same time, normalization processing is performed to map the RGB channel value of each pixel of the image to the [0, 1] interval to eliminate the influence of subtle differences in illumination intensity on feature extraction. Finally, Gaussian noise suppression with a mean of 0 and a variance of 0.01 is added to improve the anti-interference ability of feature extraction. S412. Based on the ImageNet dataset, pre-trained weights are loaded, core parameters of convolutional and pooling layers are retained, the parameters of the first 10 layers are frozen to avoid overfitting, and the parameters of the last 10 layers are fine-tuned to adapt to industrial defect detection scenarios. The network input is set to 224×224×3 and the output is a 2048-dimensional feature vector. The activation function is ReLU to avoid the gradient vanishing problem. S413. Five sets of convolutional blocks consisting of one convolutional layer, a batch normalization layer, and a ReLU activation layer are used to progressively extract features from the bottom to the top layers of the image. The first two convolutional blocks extract basic features such as edges and textures, while the third to fifth convolutional blocks extract core features such as defect contours and gray-level abrupt changes. Each set of convolutional blocks uses a 3×3 convolutional kernel with a stride of 1 and a padding mode of SAME to ensure that the feature map size matches the input size and reduce feature loss. S414. Residual connections are set between each group of convolutional blocks through shortcut paths, and the input features are directly superimposed on the output features of the convolution operation. This solves the gradient vanishing problem in deep network training, ensures that the core defect features of the high-level layers are not weakened, and improves the integrity of feature extraction. S415. After the first group of convolutional blocks, a max pooling layer is set, and after the last group of convolutional blocks, a global average pooling layer is set to compress the high-level feature map into a 1×1×2048 feature matrix, avoid redundant feature interference, and improve computational efficiency. S416. Perform L2 normalization on the 2048-dimensional feature matrix output by the global average pooling layer to make the L2 norm of the feature vector 1, unify the feature vector scale, ensure that the feature vectors of different images are comparable, and lay the foundation for subsequent similarity calculation. S417. Associate and store the standardized 2048-dimensional feature vector with the corresponding image and region number.
[0010] Preferably, the associated storage method in step S417 is saved using AES-256 encryption, which supports quick access for similarity calculation and subsequent source tracing query.
[0011] Preferably, the detailed calculation process of cosine similarity in step S4 is as follows: S421. Synchronously retrieve the 2048-dimensional feature vector of the image to be tested and the 2048-dimensional feature vector of a single sample image from the storage unit. The vector to be tested is vector A, and the vector of the sample image is vector B. Ensure that the two sets of vectors have the same dimension and uniform scale. S422. Calculate the dot product of vectors A and B using the following formula:
[0012] in Let be the i-th eigenvalue of vector A. Let be the i-th eigenvalue of vector B. The calculation precision is retained to 6 decimal places to avoid the accumulation of calculation errors. S423. Because L2 standardization was completed in advance, the magnitudes of vectors A and B are both 1. No additional calculation is needed, so the magnitude calculation is skipped directly, which improves computational efficiency and avoids the error introduced by the magnitude calculation. S424. Calculate the final result using the cosine similarity formula. The formula is as follows:
[0013] Since the modulus length is 1, it can be simplified to:
[0014] The calculation result takes values in the range [0, 1] and is rounded to 4 decimal places. S425. For the image of the region to be tested, perform batch similarity calculations with all positive and negative samples in the sample library. After each set of calculations is completed, the results are cached and the highest similarity, lowest similarity, and corresponding sample information are recorded synchronously for subsequent judgment rule matching. After the calculation is completed, the temporary calculation data is automatically cleaned up to release memory resources and ensure the continuous and efficient operation of the system. S426. The preset positive sample similarity threshold is 0.90. If 80% of the positive samples have a similarity ≥ the threshold, the similarity with all negative samples is ≤ 0.80, and the difference between the highest similarity with positive samples and the highest similarity with negative samples is ≥ 0.1, then there is no defect.
[0015] This invention also discloses a general-purpose defect detection system for industrial manufacturing, used in the aforementioned detection method. It comprises a reference image calibration module, a sample processing and storage module, an image registration and alignment module, and a similarity calculation and result output module. The modules interact with each other via TCP / IP protocol, and the specific interaction process is as follows: The reference image calibration module outputs a reference image and a coordinate file in a defined format from the sample processing and storage module. The sample processing and storage module outputs a reference image in a defined format to the image registration and alignment module; The image registration and alignment module outputs the registered sample image and registration error data in a defined format to the sample processing and storage module. The sample processing and storage module outputs positive / negative sample images and feature vector data to the similarity calculation and result output module. The similarity calculation and result output module receives sample data from the sample processing and storage module and the image of the region to be tested from the image registration and alignment module, and outputs detection result signals, detection reports, and alarm signals.
[0016] The beneficial effects of this invention are: 1. It can be deployed with only 20-30 positive samples and 10-20 negative samples, reducing the cost of sample collection and labeling by more than 80% and solving the detection problem in scenarios where defective samples are scarce; 2. The core registration algorithm has an error of ≤1 pixel, and the core similarity calculation model effectively improves the accuracy of defect detection. 3. When updating product models, only the baseline image and sample library need to be replaced, without retraining the model, which meets the flexible production needs of small and medium batches of multiple categories. Attached Figure Description
[0017] The invention will now be further described with reference to the accompanying drawings.
[0018] Figure 1 This is a flowchart of the baseline image construction and detection region calibration of the present invention; Figure 2This is a flowchart of the positive and negative sample storage and detection area extraction process of the present invention; Figure 3 This is a flowchart of the process for acquiring the image to be tested, calculating similarity, and outputting results according to the present invention. Detailed Implementation
[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] Reference Figures 1-3 A general defect detection method for industrial manufacturing includes the following steps: S1. Baseline Image Construction and Region to be Detected Labelling: The goal is to establish a baseline image of the product and identify the key regions that need to be detected, providing a standard for subsequent sample comparison and region to be detected extraction. The specific steps are as follows: S11. Select a product image that is defect-free, with an illumination intensity of 500-1000 lux, no obstruction, and no reflection as the reference image. The image resolution should be ≥1920×1080 pixels, the detail clarity of the area to be tested should be ≥300 DPI, and the image should be completely consistent with the shooting distance (30-50cm) and camera parameters (focal length, exposure time) of the subsequent samples and the product to be tested. S12. Engineers manually select rectangular regions to be detected. The minimum size of a single region is ≥50×50 pixels, and the distance between adjacent regions is ≥10 pixels. 1-10 regions to be detected can be selected in the same image. The selection shape includes, but is not limited to, rectangles, circles, and polygons (with ≥4 sides). S13. Automatically identify the pixel coordinates of the selected area using a pixel coordinate traversal algorithm (format: X_start-X_end, Y_start-Y_end), with a coordinate extraction error ≤ 1 pixel, and generate a coordinate file. The file format includes, but is not limited to, JSON, XML, and CSV, and includes the area number, coordinate range, and selection timestamp. S14. The reference image and coordinate file are associated and stored using the naming rule "reference image name_coordinate file". The storage media include, but are not limited to, local SSD, mechanical hard drive, and cloud server storage. The storage path is fixed as " / detection system / reference data / " and read / write permissions are set for encryption protection. The encryption methods include, but are not limited to, AES-256 and RSA-2048 encryption. S2. Positive and negative sample storage and detection region extraction: The purpose is to build a small sample library and extract images from the positive and negative samples that correspond to the baseline detection region, providing a reference for subsequent similarity comparison. The sample library size is limited to 10-30 positive samples and 10-20 negative samples, with a total of ≤50 images. The samples must be completely identical to the baseline image in terms of shooting environment and resolution. The specific steps are as follows: S21. Select 10-30 positive samples and use an image registration and alignment model with ORB feature point matching and RANSAC spatial correction. Based on the coordinate file in S1, automatically crop the area to be detected using a rectangular cropping algorithm. The cropped edges are free of jagged edges and stretching distortion. Generate an image file and store it in " / detection system / sample library / positive samples / " in association with the coordinate file. The storage medium includes, but is not limited to, local SSD and cloud server storage. Record the sample collection time and product batch information. The specific steps of the image registration and alignment model with ORB feature point matching and RANSAC spatial correction are as follows: First, extract ≥500 key feature points from a single image using the ORB algorithm. Then, filter the matching feature points with a Hamming distance ≤50 as the threshold. Finally, use the RANSAC algorithm to eliminate shooting angle deviation (≤±5°) and placement position deviation (≤±10mm). After registration, the pixel deviation is ≤1 pixel. Feature point matching algorithms include, but are not limited to, ORB, SIFT, and SURF algorithms. Spatial correction algorithms include, but are not limited to, RANSAC and LMEDS algorithms. S22. Select 10-20 negative samples. These negative samples should contain clearly defined defects, including scratches, cracks, stains, deformation, missing parts, extraneous materials, dimensional deviations, and assembly misalignments. The defect area should completely fall within the area to be detected, with a defect area ≥ 5×5 pixels. Use an image registration and alignment model based on ORB feature point matching and RANSAC spatial correction. Based on the coordinate file in S1, automatically crop the area to be detected using a rectangular cropping algorithm. The cropped edges should be smooth and free of jagged edges and stretching distortion. Generate an image file and store it in association with the coordinate file. Name the file "Negative Sample_Serial Number_". The "Region ID_Defect Type" is stored in " / Detection System / Sample Library / Negative Sample / ", and the storage medium includes but is not limited to local SSD and cloud server storage. It is also associated with the defect location coordinates and defect size. The specific steps of the image registration and alignment model with ORB feature point matching and RANSAC spatial correction are as follows: First, extract ≥500 key feature points from a single image using the ORB algorithm. Then, filter matching feature points with a Hamming distance ≤50 as the threshold. Finally, eliminate shooting angle deviation and placement position deviation using the RANSAC algorithm. After registration, the pixel deviation is ≤1 pixel. S3. Image acquisition, the specific steps are as follows: S31. Acquire real-time images using an industrial camera (resolution ≥ 1920×1080 pixels, frame rate ≥ 30fps, shutter speed ≤ 1 / 1000s). The images are free from blur, obstruction, and reflection. The shooting environment is consistent with the reference image. The image acquisition device includes, but is not limited to, industrial CCD cameras, CMOS cameras, and line scan cameras. S32. Align the detection area of the image to be tested with the detection area of the reference image at the pixel level; based on the coordinate file in S1, extract the image of the detection area through a cropping algorithm within a limited range, and the size and position of the extracted area are consistent with the image in the sample library; S4. Similarity calculation and result output, the specific steps are as follows: S41. Similarity calculation is performed using a ResNet-50 feature extraction network in conjunction with a cosine similarity calculation module. First, a 2048-dimensional feature vector is extracted through the ResNet-50 network, and then the cosine similarity between the image to be tested and the sample image is calculated (the value range is 0-1, and the calculation accuracy is ≤0.0001). The feature extraction network includes, but is not limited to, ResNet-50, ResNet-101, and EfficientNet-B3. The similarity calculation method includes, but is not limited to, cosine similarity, Euclidean distance, and Pearson correlation coefficient. The ResNet-50 feature vector extraction process is as follows: S411. The cropped image of the region to be detected is normalized to a size of 224×224 pixels. Bilinear interpolation is used to adjust the size to avoid image distortion. At the same time, normalization is performed to map the RGB channel value of each pixel to the [0, 1] interval (calculation formula: normalized value = (original pixel value - minimum channel value) / (maximum channel value - minimum channel value)) to eliminate the influence of subtle differences in illumination intensity on feature extraction. Finally, Gaussian noise suppression with a mean of 0 and a variance of 0.01 is added to improve the anti-interference ability of feature extraction. S412. Based on the ImageNet dataset, pre-trained weights are loaded, core parameters of convolutional and pooling layers are retained, the parameters of the first 10 layers are frozen to avoid overfitting, and the parameters of the last 10 layers are fine-tuned to adapt to industrial defect detection scenarios. The network input is set to 224×224×3 (width×height×number of channels), and the output is a 2048-dimensional feature vector. The activation function is ReLU to avoid the gradient vanishing problem. S413. Five sets of convolutional blocks consisting of one convolutional layer, a batch normalization layer, and a ReLU activation layer are used to progressively extract features from the bottom to the top layers of the image. The first two convolutional blocks extract basic features such as edges and textures, while the third to fifth convolutional blocks extract core features such as defect contours and gray-level abrupt changes. Each set of convolutional blocks uses a 3×3 convolutional kernel with a stride of 1 and a padding mode of SAME to ensure that the feature map size matches the input size and reduce feature loss. S414. Residual connections are set between each group of convolutional blocks through shortcut paths, and the input features are directly superimposed on the output features of the convolution operation. This solves the gradient vanishing problem in deep network training, ensures that the core defect features of the high-level layers are not weakened, and improves the integrity of feature extraction. S415. After the first group of convolutional blocks, a max pooling layer (pooling kernel 2×2, stride 2) is set, and after the last group of convolutional blocks, a global average pooling layer is set to compress the high-level feature map into a 1×1×2048 feature matrix, avoid redundant feature interference, and improve computational efficiency. S416. Perform L2 normalization on the 2048-dimensional feature matrix output by the global average pooling layer to make the L2 norm of the feature vector 1 (calculation formula: normalized feature value = original feature value / √(sum of squares of all feature values)). This unifies the feature vector scale, ensures the comparability of feature vectors from different images, and lays the foundation for subsequent similarity calculation. S417. The standardized 2048-dimensional feature vector is associated with the corresponding image (sample / image to be tested) and region number and stored. The associated storage method uses AES-256 encryption to save the data, which supports quick access for similarity calculation and subsequent source tracing query.
[0021] Detailed calculation process of cosine similarity in step S4: S421. Synchronously retrieve the 2048-dimensional feature vector of the image to be tested and the 2048-dimensional feature vector of a single sample image from the storage unit. The vector to be tested is vector A, and the vector of the sample image is vector B. Ensure that the two sets of vectors have the same dimension and uniform scale. S422. Calculate the dot product of vectors A and B using the following formula:
[0022] in Let be the i-th eigenvalue of vector A. Let be the i-th eigenvalue of vector B. The calculation precision is retained to 6 decimal places to avoid the accumulation of calculation errors. S423. Due to the early completion of L2 normalization, the magnitudes of vectors A and B are both 1. No additional calculations are needed; the modulus calculation is skipped directly, improving computational efficiency and avoiding errors introduced by the modulus calculation. S424. Calculate the final result using the cosine similarity formula. The formula is as follows:
[0023] Since the modulus length is 1, it can be simplified to:
[0024] The calculation result takes values in the range [0, 1] and is rounded to 4 decimal places. S425. For the image of the region to be tested, perform batch similarity calculations with all positive and negative samples in the sample library. After each set of calculations is completed, the results are cached and the highest similarity, lowest similarity, and corresponding sample information are recorded synchronously for subsequent judgment rule matching. After the calculation is completed, the temporary calculation data is automatically cleaned up to release memory resources and ensure the continuous and efficient operation of the system. S426. The preset positive sample similarity threshold is 0.90. If 80% of the positive samples have a similarity ≥ the threshold, the similarity with all negative samples is ≤ 0.80, and the difference between the highest similarity with positive samples and the highest similarity with negative samples is ≥ 0.1, then there is no defect.
[0025] S42. If all areas to be inspected meet the defect-free condition, a qualified signal and inspection report will be output. If any area to be inspected does not meet the defect-free condition, a non-qualified signal and inspection report will be output. The non-qualified inspection report includes the defect area number, defect type, similarity data, and defect image. The test image and processing data will be automatically stored for ≥90 days. The storage media include local SSD and cloud server storage. Traceability query is supported. If the number of matching feature points is <300, an abnormal detection signal will be output, and the image will be automatically re-acquired. If it still fails after three attempts, an alarm will be triggered. The alarm methods include audible and visual alarms, SMS notifications, and system pop-up alarms.
[0026] This invention also discloses a general-purpose defect detection system for industrial manufacturing, used in the aforementioned detection method. It comprises a reference image calibration module, a sample processing and storage module, an image registration and alignment module, and a similarity calculation and result output module. The modules interact with each other via the TCP / IP protocol. The hardware of the reference image calibration module is a display terminal (resolution ≥ 1920×1080 pixels) or a touch operation device. The hardware types include, but are not limited to, desktop computers, laptops, and industrial tablets. The software functions include image import / preview, zoom in / out / pan, selection function, real-time coordinate display, coordinate file generation / saving / export, and calibration result verification (automatic detection of the rationality of the selected area).
[0027] The hardware standard for the sample processing and storage module is as follows: Intel Core i7-12700H, AMD Ryzen 7 5800H, Intel Core i7-13700H; software functions include sample import / verification (detecting resolution and shooting environment consistency), registration and alignment result reception, cropping processing, sample library management (retrieval / update / deletion / backup), and encrypted data storage.
[0028] The hardware standards for the image registration and alignment module are: processor ≥ Intel Core i7-12700H, graphics card ≥ NVIDIA RTX 3060 (VRAM ≥ 6GB), memory ≥ 16GB, and graphics card models include but are not limited to NVIDIA RTX 3060, NVIDIA RTX 4060, and AMD Radeon RX 6700M; the software functions are image reception, feature point extraction, spatial correction, registration error calculation, and post-registration image output. The hardware standard for the similarity calculation and result output module is: processor ≥ Intel Core i9-12900H, graphics card ≥ NVIDIA RTX 3070 (VRAM ≥ 8GB), memory ≥ 32GB. Processor models include, but are not limited to, Intel Core i9-12900H, AMD Ryzen 9 5900HX, and Intel Core i9-13900H. The software functions include feature vector extraction, similarity calculation, judgment rule execution, result signal output (digital signal), detection report generation, data storage and traceability, and alarm prompts.
[0029] The specific interaction process is as follows: The reference image calibration module outputs a reference image and a coordinate file in a defined format from the sample processing and storage module. The sample processing and storage module outputs a reference image in a defined format to the image registration and alignment module; The image registration and alignment module outputs the registered sample image and registration error data in a defined format to the sample processing and storage module. The sample processing and storage module outputs positive / negative sample images and feature vector data to the similarity calculation and result output module. The similarity calculation and result output module receives sample data from the sample processing and storage module and the image of the region to be tested from the image registration and alignment module, and outputs detection result signals, detection reports, and alarm signals.
[0030] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the claimed invention.
Claims
1. A general defect detection method for industrial manufacturing, characterized in that, Includes the following steps: S1. Construction of the baseline image and calibration of the region to be detected, the specific steps are as follows: S11. Select a product image with no defects, light intensity of 500-1000 lux, no obstruction, and no reflection as the reference image. The image resolution is ≥1920×1080 pixels, and the detail clarity of the area to be inspected is ≥300 DPI. S12. Engineers manually select rectangular regions to be detected. The minimum size of a single region is ≥50×50 pixels, and the distance between adjacent regions is ≥10 pixels. 1-10 regions to be detected can be selected in the same image. The shape of the selection includes rectangles, circles, and polygons with more than four sides. S13. Automatically identify the pixel coordinates of the selected area using a pixel coordinate traversal algorithm. The coordinate extraction error is ≤1 pixel. Generate a coordinate file containing the area number, coordinate range, and selection timestamp. S14. Associate and store the reference image with the coordinate file. The storage media include local SSD, mechanical hard disk, and cloud server storage. S2. Positive and negative sample storage and extraction of the region to be detected, the specific steps are as follows: S21. Select 10-30 positive samples and use an image registration and alignment model with ORB feature point matching and RANSAC spatial correction. Based on the coordinate file in S1, automatically crop the area to be detected using a rectangular cropping algorithm. The cropped edges are free of jagged edges and stretching distortion. Generate an image file and store it together with the coordinate file. S22. Select 10-20 negative samples containing clear defects. Use an image registration and alignment model with ORB feature point matching and RANSAC spatial correction. Based on the coordinate file in S1, automatically crop the area to be detected using a rectangular cropping algorithm. The cropped edges are free of jagged edges and stretching distortion. Generate an image file and store it together with the coordinate file. S3. Image acquisition, the specific steps are as follows: S31. Real-time images are acquired through an industrial camera. The images are clear, unobstructed, and free of reflections, and the shooting environment is consistent with the reference image. S32. Align the detection area of the image to be tested with the detection area of the reference image at the pixel level; based on the coordinate file in S1, extract the image of the detection area through a cropping algorithm within a limited range, and the size and position of the extracted area are consistent with the image in the sample library; S4. Similarity calculation and result output, the specific steps are as follows: S41. Similarity calculation is performed using a ResNet-50 feature extraction network in conjunction with a cosine similarity calculation module. First, a 2048-dimensional feature vector is extracted through the ResNet-50 network, and then the cosine similarity between the image to be tested and the sample image is calculated. S42. If all areas to be inspected meet the defect-free condition, output a qualified signal and inspection report; if any area to be inspected does not meet the defect-free condition, output a non-qualified signal and inspection report. The non-qualified inspection report includes the defect area number, defect type, similarity data and defect image, and automatically stores the image to be inspected and the processing data. The storage retention time is ≥90 days, and the storage media includes local SSD and cloud server storage, which supports traceability query.
2. The general defect detection method for industrial manufacturing according to claim 1, characterized in that, The specific steps of the image registration and alignment model in step S2, which combines ORB feature point matching with RANSAC spatial correction, are as follows: first, extract ≥500 key feature points from a single image using the ORB algorithm; then, filter matching feature points using a Hamming distance ≤50 as a threshold; finally, eliminate shooting angle deviation and placement deviation using the RANSAC algorithm, resulting in a pixel deviation ≤1 pixel after registration.
3. The general defect detection method for industrial manufacturing according to claim 1, characterized in that, The defect types in step 22 include scratches, cracks, stains, deformation, missing parts, extraneous materials, dimensional deviations, and assembly misalignments, and the defect area must fall completely within the area to be inspected, with a defect area ≥ 5×5 pixels.
4. The general defect detection method for industrial manufacturing according to claim 1, characterized in that, If the number of matched feature points is less than 300 in step S42, an abnormal detection signal is output, and the image is automatically re-acquired. If the detection fails after three attempts, an alarm is triggered. The alarm methods include audible and visual alarms, SMS notifications, and system pop-up alarms.
5. The general defect detection method for industrial manufacturing according to claim 1, characterized in that, The ResNet-50 feature vector extraction process in step S41 is as follows: S411. The cropped image of the region to be detected is normalized to a size of 224×224 pixels. Bilinear interpolation algorithm is used to adjust the size to avoid image distortion. At the same time, normalization processing is performed to map the RGB channel value of each pixel of the image to the [0, 1] interval to eliminate the influence of subtle differences in illumination intensity on feature extraction. Finally, Gaussian noise suppression with a mean of 0 and a variance of 0.01 is added to improve the anti-interference ability of feature extraction. S412. Based on the ImageNet dataset, pre-trained weights are loaded, core parameters of convolutional and pooling layers are retained, the parameters of the first 10 layers are frozen to avoid overfitting, and the parameters of the last 10 layers are fine-tuned to adapt to industrial defect detection scenarios. The network input is set to 224×224×3 and the output is a 2048-dimensional feature vector. The activation function is ReLU to avoid the gradient vanishing problem. S413. Five sets of convolutional blocks consisting of one convolutional layer, a batch normalization layer, and a ReLU activation layer are used to progressively extract features from the bottom to the top layers of the image. The first two convolutional blocks extract basic features such as edges and textures, while the third to fifth convolutional blocks extract core features such as defect contours and gray-level abrupt changes. Each set of convolutional blocks uses a 3×3 convolutional kernel with a stride of 1 and a padding mode of SAME to ensure that the feature map size matches the input size and reduce feature loss. S414. Residual connections are set between each group of convolutional blocks through shortcut paths, and the input features are directly superimposed on the output features of the convolution operation. This solves the gradient vanishing problem in deep network training, ensures that the core defect features of the high-level layers are not weakened, and improves the integrity of feature extraction. S415. After the first group of convolutional blocks, a max pooling layer is set, and after the last group of convolutional blocks, a global average pooling layer is set to compress the high-level feature map into a 1×1×2048 feature matrix, avoid redundant feature interference, and improve computational efficiency. S416. Perform L2 normalization on the 2048-dimensional feature matrix output by the global average pooling layer to make the L2 norm of the feature vector 1, unify the feature vector scale, ensure that the feature vectors of different images are comparable, and lay the foundation for subsequent similarity calculation. S417. Associate and store the standardized 2048-dimensional feature vector with the corresponding image and region number.
6. The general defect detection method for industrial manufacturing according to claim 5, characterized in that, The associated storage method in step S417 is saved using AES-256 encryption, which supports quick access for similarity calculation and subsequent source tracing query.
7. The general defect detection method for industrial manufacturing according to claim 1, characterized in that, Detailed calculation process of cosine similarity in step S4: S421. Synchronously retrieve the 2048-dimensional feature vector of the image to be tested and the 2048-dimensional feature vector of a single sample image from the storage unit. The vector to be tested is vector A, and the vector of the sample image is vector B. Ensure that the two sets of vectors have the same dimension and uniform scale. S422. Calculate the dot product of vectors A and B using the following formula:
8. Among them Let be the i-th eigenvalue of vector A. Let be the i-th eigenvalue of vector B. The calculation precision is retained to 6 decimal places to avoid the accumulation of calculation errors. S423. Because L2 standardization was completed in advance, the magnitudes of vectors A and B are both 1. No additional calculation is needed, so the magnitude calculation is skipped directly, which improves computational efficiency and avoids the error introduced by the magnitude calculation. S424. Calculate the final result using the cosine similarity formula. The formula is as follows:
9. Since the modulus length is 1, it simplifies to:
10. The calculation result should take values in the range [0, 1] and be rounded to four decimal places. S425. For the image of the region to be tested, perform batch similarity calculations with all positive and negative samples in the sample library. After each set of calculations is completed, the results are cached and the highest similarity, lowest similarity, and corresponding sample information are recorded synchronously for subsequent judgment rule matching. After the calculation is completed, the temporary calculation data is automatically cleaned up to release memory resources and ensure the continuous and efficient operation of the system. S426. The preset positive sample similarity threshold is 0.
90. If 80% of the positive samples have a similarity ≥ the threshold, the similarity with all negative samples is ≤ 0.80, and the difference between the highest similarity with positive samples and the highest similarity with negative samples is ≥ 0.1, then there is no defect.
11. A general-purpose defect detection system for industrial manufacturing, used in the detection method as described in any one of claims 1-7, characterized in that, It consists of a baseline image calibration module, a sample processing and storage module, an image registration and alignment module, and a similarity calculation and result output module. The modules interact with each other via TCP / IP protocol. The specific interaction process is as follows: The reference image calibration module outputs a reference image and a coordinate file in a defined format from the sample processing and storage module. The sample processing and storage module outputs a reference image in a defined format to the image registration and alignment module; The image registration and alignment module outputs the registered sample image and registration error data in a defined format to the sample processing and storage module. The sample processing and storage module outputs positive / negative sample images and feature vector data to the similarity calculation and result output module. The similarity calculation and result output module receives sample data from the sample processing and storage module and the image of the region to be tested from the image registration and alignment module, and outputs detection result signals, detection reports, and alarm signals.