Detection method, device and equipment based on visual detection defects and storage medium
By preprocessing the image data and using the improved YOLO model, combining SIoU and Focal Loss loss functions, the problem of low defect detection accuracy in the prior art is solved, and the accuracy and positioning accuracy of defect detection are improved.
Patent Information
- Application Number
- CN202411153579.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2044-08-21
AI Technical Summary
Existing deep learning-based defect detection methods have low accuracy when dealing with complex scenarios and unbalanced datasets, especially because the model does not pay enough attention to a few classes and has low positioning accuracy due to the small number of positive samples.
By preprocessing the image data, obtaining defect image data, and using the improved YOLO model for defect detection, SIoU and Focal Loss loss functions are introduced to improve positioning accuracy and category balance, and combined with data screening to improve the accuracy of detection results.
The accuracy and positioning accuracy of defect detection are improved, and the problems of category imbalance and insufficient positioning accuracy in the YOLO model are overcome, ensuring that the output surface defect detection results are highly accurate.
Smart Images

Figure CN119295369A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a detection method, device, equipment and storage medium based on visual detection of defects. Background Art
[0002] In the manufacturing industry, product defect detection is a critical link. Traditional manual inspection methods are inefficient and prone to errors. With the development of computer vision technology, automated visual inspection methods have gradually become mainstream. However, existing automated inspection methods still have challenges in dealing with complex scenes and unbalanced datasets.
[0003] In recent years, the rise of deep learning technology has brought revolutionary improvements to visual inspection. In particular, convolutional neural networks have achieved remarkable results in image recognition and classification tasks and have been widely used in the field of defect detection. However, in existing deep learning-based defect detection methods, the number of positive samples (defects) is usually far less than that of negative samples (no defects), resulting in insufficient attention to minority classes during model training, which in turn reduces the accuracy of defect detection. Existing deep learning-based methods also have problems such as low positioning accuracy that affect detection accuracy. It can be seen that existing deep learning-based methods still have the problem of low defect detection accuracy.
[0004] Therefore, how to improve the accuracy of defect detection is a problem that needs to be solved urgently. Summary of the invention
[0005] The main purpose of this application is to provide a detection method, device, equipment and storage medium based on visual detection of defects, aiming to solve the technical problem of how to improve the accuracy of defect detection.
[0006] To achieve the above objectives, the present application proposes a method for detecting defects based on visual detection, the method comprising:
[0007] Acquire image data to be processed and perform data preprocessing to obtain defect image data;
[0008] Performing defect detection processing on the defect image data based on a defect detection model to obtain surface defect detection data, wherein a loss function is added to the defect detection model, and the defect detection model is obtained by improving the YOLO (You Only Look Once) model;
[0009] The surface defect detection data is screened to obtain a surface defect detection result.
[0010] In one embodiment, the loss function includes a SIoU (Symmetric Intersection over Union) function, and the SIoU function is used to calculate the positioning loss. The step of performing defect detection processing on the image data based on the defect detection model includes:
[0011] Based on the defect image data, a predicted frame and a preset real frame are obtained;
[0012] The predicted box and the preset true box are compared by the SIoU function to obtain a SIoU loss value;
[0013] During defect detection processing, the loss weight of the SIoU loss value in the positioning loss calculation is increased.
[0014] In one embodiment, after the step of increasing the loss weight of the SIoU loss value in the positioning loss calculation, the step further includes:
[0015] Calculate the weight penalty term through the preset optimizer;
[0016] The SIoU loss value is optimized by using the weight penalty item to obtain the optimized SIoU loss value.
[0017] In one embodiment, the loss function includes a Focal Loss function, and the step of performing defect detection processing on the image data based on the defect detection model includes:
[0018] Calculate a binary cross entropy loss value based on the defect image data;
[0019] The true category probability is calculated by the binary cross entropy loss value;
[0020] A Focal Loss function is obtained by calculating the true category probability, wherein the Focal Loss function includes a first parameter and a second parameter, the first parameter and the second parameter are adjustable, the first parameter is a coefficient parameter, and the second parameter is an exponential parameter;
[0021] During defect detection processing, the defect image data is classified using the Focal Loss function.
[0022] In one embodiment, the surface defect detection data includes confidence, and the step of screening the surface defect detection data to obtain the surface defect detection result further includes:
[0023] If the confidence level of the surface defect detection data is higher than a first confidence level threshold, outputting the surface defect detection data as the surface defect detection result;
[0024] If the confidence of the surface defect detection data is higher than a second confidence threshold, the surface defect detection data is stored as data to be identified, and the second confidence threshold is lower than the first confidence threshold.
[0025] In one embodiment, the step of acquiring the image data to be processed and performing data preprocessing to obtain defect image data further includes:
[0026] Gray-scaling the image data to obtain gray-scale image data;
[0027] The grayscale image data is binarized to obtain the defect image data, wherein the defect image data is image data containing black and white pixels.
[0028] In one embodiment, the step of obtaining the image data to be processed further includes:
[0029] The product to be tested is illuminated by a light box, and image data of the product to be tested is acquired by a camera to obtain image data to be processed. The light box is composed of a box body, a light source and a light-transmitting panel.
[0030] In addition, to achieve the above-mentioned purpose, the present application also proposes a defect detection device, the defect detection device comprising:
[0031] A data acquisition module is used to acquire image data to be processed and perform data preprocessing to obtain defect image data;
[0032] A data processing module is used to perform defect detection processing on the defect image data based on a defect detection model to obtain surface defect detection data. A loss function is added to the defect detection model, and the defect detection model is obtained by improving the YOLO model.
[0033] The data screening module is used to screen the surface defect detection data to obtain the surface defect detection result.
[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes a defect detection device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the defect detection method based on visual detection as described above.
[0035] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the detection method based on visual detection of defects as described above are implemented.
[0036] The present application provides a detection method based on visual defect detection. The present application first obtains defect image data by preprocessing the image data to be processed, simplifies the image data, and improves the recognition of the image data, making the defect area in the image data more obvious, which is beneficial to subsequent defect detection; the defect image data is subjected to defect detection processing through an improved defect detection model to obtain surface defect detection data. Due to the use of the improved defect detection model, a loss function is added to solve the problem of category imbalance and positioning accuracy, thereby improving the accuracy of defect detection; finally, the surface defect detection data is screened to obtain the surface defect detection result, ensuring that the output surface defect detection result has high accuracy.
[0037] In summary, the present application overcomes the technical defects of category imbalance and insufficient positioning accuracy in the YOLO model by preprocessing the image data, performing defect detection processing on the defect image data through an improved defect detection model, and finally screening the results, thereby improving the accuracy of defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0040] Figure 1 A flow chart of an embodiment of a method for detecting defects based on visual detection provided by the present application;
[0041] Figure 2 A flow chart of an embodiment of a method for detecting defects based on visual detection provided by the present application;
[0042] Figure 3 A schematic diagram of a scene of a method for detecting defects based on visual detection provided in an embodiment of the present application;
[0043] Figure 4 This is a schematic diagram of the module structure of the defect detection device according to an embodiment of the present application;
[0044] Figure 5 Schematic diagram of the device structure of the hardware operating environment involved in the visual defect detection method in the embodiment of the present application.
[0045] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0046] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0047] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0048] The main solution of the embodiment of the present application is: obtaining the image data to be processed and performing data preprocessing to obtain defect image data; performing defect detection processing on the defect image data based on a defect detection model to obtain surface defect detection data, wherein a loss function is added to the defect detection model, and the defect detection model is obtained by improving the YOLO model; screening the surface defect detection data to obtain a surface defect detection result.
[0049] In the existing deep learning-based defect detection methods, the number of positive samples (defects) is usually far less than the number of negative samples (no defects), which leads to insufficient attention to minority classes during model training, thereby reducing the accuracy of defect detection. The existing deep learning-based methods also have problems such as low positioning accuracy that affect the detection accuracy. It can be seen that the existing deep learning-based methods still have the problem of low defect detection accuracy.
[0050] This application overcomes the technical defects of category imbalance and insufficient positioning accuracy in the YOLO model by preprocessing the image data, performing defect detection processing on the defect image data through an improved defect detection model, and finally screening the results, thereby improving the accuracy of defect detection.
[0051] In this embodiment, for ease of description, the following description is made with the defect detection device as the execution subject.
[0052] Based on this, the present application embodiment provides a detection method based on visual detection defects, referring to Figure 1 , Figure 1 It is a flow chart of an embodiment of a defect detection method based on visual detection in the present application.
[0053] In this embodiment, the defect detection method based on visual detection includes steps S10 to S30:
[0054] Step S10, acquiring image data to be processed and performing data preprocessing to obtain defect image data;
[0055] It should be noted that the image data to be processed refers to the original image information obtained by data collection of the product to be tested, that is, the image data that has not been processed, and the defective image data refers to the image information that has undergone data preprocessing.
[0056] It is understandable that, since the amount of data in the original image information is large, and the defects on the product to be tested are generally small, such as cracks, oil stains, etc. Therefore, the amount of calculation required for defect detection on the image data to be processed is large, and the accuracy cannot be guaranteed. Therefore, performing step S10 can reduce the amount of calculation required for defect detection and improve the quality of image data, thereby improving the accuracy of defect detection.
[0057] In a feasible implementation manner, the step of performing data preprocessing in step S10 may include steps A11 to A12:
[0058] Step A11, graying the image data to obtain grayscale image data;
[0059] It should be noted that grayscale image data refers to a data format into which the image data to be processed is converted. The pixel value of each pixel in the grayscale image data is expressed as a grayscale level. Generally, the pixel value varies from 0 (black) to 255 (white).
[0060] It can be understood that grayscale can be achieved through processing methods such as linear weighting, averaging method, brightness method, and contrast sensitivity method, and in defect detection, color information is basically not required. Therefore, the use of grayscale can reduce the amount of data processing and highlight defects such as scratches and wear.
[0061] Step A12, binarizing the grayscale image data to obtain defect image data, where the defect image data is image data containing black and white pixels.
[0062] It should be noted that the defective image data refers to image information after binarization processing, and binarization refers to the process of converting grayscale image data into black and white pixels.
[0063] It can be understood that in a binary image, white pixels usually represent the foreground (defects) and black pixels represent the background (non-defective areas). Alternatively, black can represent the foreground (defects) and white can represent the background (non-defective areas). This depends on the setting of the global threshold, which refers to whether it is set to the minimum threshold of white or black.
[0064] In a feasible embodiment, binarization is performed by Otsu's algorithm, and the histogram of grayscale image data, that is, the frequency of each grayscale level, is first calculated. Then, the calculation of the initial inter-class variance is performed, and the inter-class variance refers to the weighted sum of the variances of the foreground and the background after the image is divided into the foreground and the background using a certain threshold, and then different global thresholds are used to calculate the inter-class variance to find the best global threshold.
[0065] Through the method of this embodiment, dynamic control of the global threshold is achieved. Compared with a fixed global threshold, the defect detection method of this embodiment can better adapt to defect detection under various lighting conditions, thereby improving the robustness of the defect detection method of this embodiment. Through grayscale and binary processing, defects are highlighted in white or black, thereby making subsequent image analysis, such as feature extraction, measurement and classification, easier.
[0066] In a feasible implementation manner, the step of obtaining the image data to be processed in step S10 may include step B11:
[0067] Step B11, irradiating the product to be tested through a light box, and acquiring image data of the product to be tested through a camera to obtain image data to be processed. The light box consists of a box body, a light source and a light-transmitting panel.
[0068] It should be noted that a light box is a lighting device that is usually used in advertising, display, photography and other fields. It consists of a box, a light source and a light-transmitting panel. The working principle of the light box is to evenly illuminate the light on the light-transmitting panel through the light source, thereby producing bright and uniform light.
[0069] It is understandable that the light box contains multiple light sources, which facilitates preprocessing of image data. By adjusting the light source, the defects in the preprocessed defect image data can be made more accurate and obvious.
[0070] In this embodiment, the combination of a light box and a camera solves the problem of unclear defect display or unclear image after preprocessing, thereby improving the robustness and intelligence of the defect prediction and detection method of this embodiment.
[0071] Step S20, performing defect detection processing on the defect image data based on the defect detection model to obtain surface defect detection data, wherein a loss function is added to the defect detection model, and the defect detection model is obtained by improving the YOLO model;
[0072] It should be noted that defect detection processing refers to the data processing operation when the defect detection model performs defect detection, such as reducing the error of surface defect detection data through a loss function to reduce the complexity of the model. Surface defect detection data refers to the prediction box data containing defects obtained after defect detection processing.
[0073] It is understandable that the mainstream YOLO model uses the CIoU (Complete Intersection over Union) loss function to improve bounding box regression. The CIoU loss takes into account the alignment and scale of the bounding box and is an improvement on the traditional IoU (Intersection over Union) loss.
[0074] This embodiment optimizes the YOLO model in multiple aspects by introducing a new loss function into the YOLO model, such as classification loss and positioning loss, thereby improving the accuracy and speed of defect detection.
[0075] In a feasible implementation, the loss function includes a SIoU function, and step S20 may include steps C11 to C13:
[0076] Step C11, obtaining a predicted frame and a preset real frame based on the defect image data;
[0077] It should be noted that the prediction box refers to the predicted result of the defect location and range during defect detection, and the preset real box refers to the rectangular box manually drawn in the image by the data annotator.
[0078] In one feasible embodiment, during the model training phase, labelers can manually label preset true boxes. In another feasible embodiment, during the pipeline detection phase, the accuracy of the predicted boxes can be evaluated by pre-collecting labeled test sets or validation sets as preset true boxes.
[0079] Step C12, comparing the predicted box and the preset true box through the SIoU function to obtain the SIoU loss value;
[0080] It should be noted that the SIoU loss value refers to the loss value calculated by the SIoU function.
[0081] It can be understood that the SIoU function obtains the SIoU loss value by comprehensively calculating the angle, distance, shape, and IoU.
[0082] Step C13, during defect detection processing, increase the loss weight of the SIoU loss value in the positioning loss calculation.
[0083] It should be noted that the loss weight refers to the proportion of the SIoU loss value when calculating the positioning loss in the defect detection model.
[0084] It can be understood that adjusting the loss weight to 0.6 can ensure that while reducing the position error, it prevents the error from penalizing the more accurate prediction box. The more accurate prediction box is: the prediction box with error but does not affect the subsequent defect calculation.
[0085] In this embodiment, the prediction error is penalized by increasing the loss weight, which solves the problem of large difference between the predicted box and the actual defect position during defect detection, and can reduce the impact of position error on defect detection.
[0086] In a feasible implementation manner, step A13 further includes steps C130 to C131:
[0087] Step C130, calculating the weight penalty term by a preset optimizer;
[0088] Step C131, optimizing the SIoU loss value through the weight penalty term to obtain an optimized SIoU loss value.
[0089] It should be noted that the preset optimizer refers to the optimization algorithm instance configured before starting model training, such as SGD (Stochastic Gradient Descent), Adam (Adaptive Moment Estimation), RMSprop (Root Mean Square Propagation), etc. The weight penalty term refers to the parameter used to prevent overfitting, such as L2 regularization term, L1 regularization term, etc.
[0090] In a feasible embodiment, an Adam optimizer is created to call the trainable parameters in the defect detection model, the above trainable parameters are updated to optimize the loss weight, and the weight decay and learning rate are set, wherein the weight decay is set to 1e-5 and the learning rate is set to 0.001.
[0091] It is understood that the learning rate controls the step size of each trainable parameter update. A smaller learning rate may require more iterations to converge, while a larger learning rate may lead to an unstable training process. The weight decay term, also known as the L2 regularization term, prevents overfitting by adding a penalty term proportional to the square of the weight to the SIoU loss function.
[0092] This embodiment prevents overfitting of the defect detection model by introducing a weight penalty term, such as an L2 regularization term, into the SIoU function, and reduces the complexity of the defect detection model by adjusting the weight attenuation value.
[0093] In another feasible implementation, the loss function includes a Focal Loss function, and step S20 may include steps D11 to D14:
[0094] Step D11, calculating a binary classification cross entropy loss value based on the defect image data;
[0095] It should be noted that the binary cross entropy loss value is an indicator used to measure the difference between the predicted probability distribution of the binary classification model and the actual label distribution.
[0096] Step D12, calculating the true category probability through the binary cross entropy loss value;
[0097] It should be noted that the true category probability refers to the probability value of the target category (predicted box) calculated based on the true label (preset true box). In binary or multi-class classification problems, the true category probability is used to evaluate the accuracy of the model prediction and serves as the basis for calculating the loss function.
[0098] Step D13, obtaining a Focal Loss function by calculating the true category probability, wherein the Focal Loss function includes a first parameter and a second parameter, the first parameter and the second parameter are adjustable, the first parameter is a coefficient parameter, and the second parameter is an exponential parameter;
[0099] It should be noted that the Focal Loss function refers to a loss function used to solve the problem of class imbalance in defect detection.
[0100] It can be understood that the functional formula of the Focal Loss function is:
[0101]
[0102] Among them, α is the first parameter, γ is the second parameter, p is the true category probability, y refers to the category of the prediction box, y=1 is the prediction box containing the defect, and other y values are the prediction boxes that do not contain the defect.
[0103] Furthermore, the Focal Loss function is a loss function used to solve the problems of class imbalance and too many easy-to-classify samples in classification problems. By improving the cross entropy loss, the adjustment factor α×(1-p)γ is introduced to reduce the weight of easy-to-classify samples (image data without defects), so that the model pays more attention to difficult-to-classify samples (image data with defects) during training. When using the YOLO model for defect detection, since defects are a rare sample relative to the non-defective part, defects are equivalent to difficult-to-classify samples, and non-defective parts are equivalent to easy-to-classify samples.
[0104] Step D14, during defect detection processing, the defect image data is classified by using a Focal Loss function.
[0105] It can be understood that the classification of defective image data refers to weighting the defective and non-defective data in the defective image data. Defective data is a positive sample, and non-defective data is a negative sample. The defective image data contains multiple positive and negative samples. The Focal Loss function introduces an adjustment factor to reduce the weight of negative samples, so that the model pays more attention to positive samples that are difficult to classify during the training process. The penalty for positive samples can be strengthened by adjusting the parameters in Focal Loss (increasing the γ value and reducing the α value), thereby optimizing the overall performance of the model.
[0106] This embodiment solves the problem of class imbalance in defect prediction and detection by applying the Focal Loss function in the YOLO model, improves the attention of the defect detection method of this embodiment to the prediction box containing defects, and thus improves the accuracy of defect detection.
[0107] Step S30, screening the surface defect detection data to obtain the surface defect detection result.
[0108] It should be noted that the surface defect detection result refers to the surface defect detection data after screening.
[0109] This embodiment provides a detection method based on visual detection of defects, which overcomes the technical defects of category imbalance and insufficient positioning accuracy in the YOLO model by preprocessing the image data, performing defect detection processing on the defect image data through an improved defect detection model, and finally screening the results, thereby improving the accuracy of defect detection.
[0110] In a feasible implementation, the surface defect detection data includes confidence, such as Figure 2 , step S30 may include steps S21 to S22:
[0111] Step S21, if the confidence level of the surface defect detection data is higher than a first confidence level threshold, the surface defect detection data is output as a surface defect detection result;
[0112] It should be noted that the first confidence threshold refers to the surface defect detection data that is very certain for screening the improved defect detection model.
[0113] In a feasible implementation manner, the surface defect detection data includes three detected defects, wherein the confidence of one defect is lower than a first confidence threshold, and then only two defects with confidences higher than the first confidence threshold are output in the surface defect detection result.
[0114] Step S22: if the confidence of the surface defect detection data is higher than the second confidence threshold, the surface defect detection data is stored as data to be identified, and the second confidence threshold is less than the first confidence threshold.
[0115] It should be noted that the second confidence threshold refers to the surface defect detection data that the improved defect detection model is not sure about but may still be correct. The data to be screened refers to the surface defect detection data that the improved defect detection model is not sure about but may still be correct.
[0116] It is understandable that the data to be identified that are screened out by the second confidence threshold does not mean that the data to be identified is not a defect, but rather is uncertain data, and the data to be identified may be further identified later, such as re-detecting defects.
[0117] In a feasible embodiment, a scene classifier can be added to the improved defect detection model. The scene classifier outputs different first confidence thresholds and second confidence thresholds for different scenarios. The scene classifier determines the usage scenario through preset judgment conditions. The usage scenarios include scratch detection, oil stain detection, dent detection, etc. The usage scenario is determined by classifying the surface defect detection data, and the first confidence threshold and second confidence threshold corresponding to the scenario are used.
[0118] Through the mechanism of this embodiment, it is possible to enable the improved defect detection model to automatically and dynamically adjust the first confidence threshold and the second confidence threshold, thereby improving the generalization ability of the improved defect detection model and reducing overfitting.
[0119] For example, in order to help understand the implementation process of the detection method based on visual detection of defects obtained by combining this embodiment with the above embodiments, please refer to Figure 3 , Figure 3 A scene schematic diagram of a detection method based on visual detection of defects is provided, specifically:
[0120] The rectangular box is the prediction box, and the annotation of the prediction box is a combination of defect type and confidence level, where scratch represents scratches and oil represents oil stains.
[0121] It can be understood that the prediction box in the figure, i.e., the surface defect detection data, is screened by setting the first confidence threshold to 0.9 and the second confidence threshold to 0.4, wherein the confidence of the oil stain defect of Oil0.27 is lower than 0.4, which shows that the front camera in the mobile phone is misjudged as an oil stain defect. The surface defect detection data marked as Scratch0.87, Scratch0.83, and Scratch0.88 in the figure are output as surface defect detection results, and the surface defect detection data of Scratch0.43 and Scratch0.58 are used as data to be identified. The defect detection method in the above embodiment can be re-executed later to re-check the data to be identified to improve the accuracy of defect detection.
[0122] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the detection method of the present application based on visual detection of defects. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0123] This application also provides a defect detection device, please refer to Figure 4 , the defect detection device comprises:
[0124] The data acquisition module 10 is used to acquire the image data to be processed and perform data preprocessing to obtain defect image data;
[0125] The data processing module 20 is used to perform defect detection processing on the defect image data based on the defect detection model to obtain surface defect detection data. A loss function is added to the defect detection model, and the defect detection model is obtained by improving the YOLO model.
[0126] The data screening module 30 is used to screen the surface defect detection data to obtain a surface defect detection result.
[0127] Optionally, the loss function includes a SIoU function, and the SIoU function is used to calculate the positioning loss. The data processing module 20 is further used to:
[0128] Based on the defect image data, a predicted frame and a preset real frame are obtained;
[0129] The predicted box and the preset true box are compared by the SIoU function to obtain a SIoU loss value;
[0130] During defect detection processing, the loss weight of the SIoU loss value in the positioning loss calculation is increased.
[0131] Optionally, the data processing module 20 is further used for:
[0132] Calculate the weight penalty term through the preset optimizer;
[0133] The SIoU loss value is optimized by using the weight penalty item to obtain the optimized SIoU loss value.
[0134] Optionally, the loss function includes a Focal Loss function, and the data processing module 20 is further used for:
[0135] Calculate a binary cross entropy loss value based on the defect image data;
[0136] The true category probability is calculated by the binary cross entropy loss value;
[0137] A Focal Loss function is obtained by calculating the true category probability, wherein the Focal Loss function includes a first parameter and a second parameter, the first parameter and the second parameter are adjustable, the first parameter is a coefficient parameter, and the second parameter is an exponential parameter;
[0138] During defect detection processing, the defect image data is classified using the Focal Loss function.
[0139] Optionally, the surface defect detection data includes confidence, and the data screening module 30 is further used to:
[0140] If the confidence level of the surface defect detection data is higher than a first confidence level threshold, outputting the surface defect detection data as the surface defect detection result;
[0141] If the confidence of the surface defect detection data is higher than a second confidence threshold, the surface defect detection data is stored as data to be identified, and the second confidence threshold is lower than the first confidence threshold.
[0142] Optionally, the data acquisition module 10 is further used for:
[0143] Gray-scaling the image data to obtain gray-scale image data;
[0144] The grayscale image data is binarized to obtain the defect image data, wherein the defect image data is image data containing black and white pixels.
[0145] Optionally, the data acquisition module 10 is further used for:
[0146] The product to be tested is illuminated by a light box, and image data of the product to be tested is acquired by a camera to obtain image data to be processed. The light box is composed of a box body, a light source and a light-transmitting panel.
[0147] The defect detection device provided by the present application adopts the detection method based on visual defect detection in the above embodiment, which can solve the technical problem of how to improve the accuracy of defect detection. Compared with the prior art, the beneficial effects of the defect detection device provided by the present application are the same as the beneficial effects of the detection method based on visual defect detection provided by the above embodiment, and other technical features in the defect detection device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0148] Reference below Figure 5 , which shows a schematic diagram of the structure of a defect detection device suitable for implementing the embodiment of the present application. The defect detection device in the embodiment of the present application may include but is not limited to mobile terminals such as laptop computers, PADs (Portable Application Description: tablet computers), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The defect detection device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0149] like Figure 5 As shown, the defect detection device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the defect detection device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the defect detection device to communicate with other devices wirelessly or by wire to exchange data. Although the defect detection device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0150] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0151] The defect detection device provided by the present application adopts the detection method based on visual defect detection in the above embodiment, which can solve the technical problem of how to improve the accuracy of defect detection. Compared with the prior art, the beneficial effects of the defect detection device provided by the present application are the same as the beneficial effects of the detection method based on visual defect detection provided in the above embodiment, and other technical features in the defect detection device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0152] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0153] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0154] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the visual defect detection method in the above-mentioned embodiment.
[0155] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0156] The computer-readable storage medium may be included in the defect detection device; or may exist independently without being assembled into the defect detection device.
[0157] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the defect detection device, the defect detection device: obtains the image data to be processed and performs data preprocessing to obtain defect image data; performs defect detection processing on the defect image data based on a defect detection model to obtain surface defect detection data, wherein a loss function is added to the defect detection model, and the defect detection model is obtained by improving the YOLO model; and screens the surface defect detection data to obtain a surface defect detection result.
[0158] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0159] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0160] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0161] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned detection method based on visual detection of defects, and can solve the technical problem of how to improve the accuracy of defect detection. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the detection method based on visual detection of defects provided in the above-mentioned embodiment, and will not be repeated here.
[0162] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for detecting defects based on visual detection, characterized in that: The method includes: Acquire image data to be processed and perform data preprocessing to obtain defect image data; Perform defect detection processing on the defect image data based on a defect detection model to obtain surface defect detection data, wherein a loss function is added to the defect detection model, and the defect detection model is obtained by improving the YOLO model; The surface defect detection data is screened to obtain a surface defect detection result.
2. The method according to claim 1, characterized in that The loss function includes a SIoU function, and the SIoU function is used to calculate the positioning loss. The step of performing defect detection processing on the image data based on the defect detection model includes: Based on the defect image data, a predicted frame and a preset real frame are obtained; The predicted box and the preset true box are compared by the SIoU function to obtain a SIoU loss value; During defect detection processing, the loss weight of the SIoU loss value in the positioning loss calculation is increased.
3. The method according to claim 2, characterized in that After the step of comparing the predicted frame with the preset true frame by the SIoU function to obtain the SIoU loss value, the following step further includes: Calculate the weight penalty term through the preset optimizer; The SIoU loss value is optimized by using the weight penalty item to obtain the optimized SIoU loss value.
4. The method according to claim 1, characterized in that The loss function includes a FocalLoss function, and the step of performing defect detection processing on the image data based on the defect detection model includes: Calculate a binary cross entropy loss value based on the defect image data; The true category probability is calculated by the binary cross entropy loss value; A Focal Loss function is obtained by calculating the true category probability, wherein the Focal Loss function includes a first parameter and a second parameter, the first parameter and the second parameter are adjustable, the first parameter is a coefficient parameter, and the second parameter is an exponential parameter; During defect detection processing, the defect image data is classified using the Focal Loss function.
5. The method according to claim 1, characterized in that The surface defect detection data includes confidence, and the step of screening the surface defect detection data to obtain the surface defect detection result further includes: If the confidence level of the surface defect detection data is higher than a first confidence level threshold, outputting the surface defect detection data as the surface defect detection result; If the confidence of the surface defect detection data is higher than a second confidence threshold, the surface defect detection data is stored as data to be identified, and the second confidence threshold is lower than the first confidence threshold.
6. The method according to claim 1, characterized in that The step of acquiring the image data to be processed and performing data preprocessing to obtain defect image data also includes: Gray-scaling the image data to obtain gray-scale image data; The grayscale image data is binarized to obtain the defect image data, where the defect image data is image data containing black and white pixels.
7. The method according to claim 1, characterized in that The step of obtaining the image data to be processed also includes: The product to be tested is illuminated by a light box, and image data of the product to be tested is acquired by a camera to obtain image data to be processed. The light box is composed of a box body, a light source and a light-transmitting panel.
8. A defect detection device, characterized in that: The device comprises: A data acquisition module is used to acquire image data to be processed and perform data preprocessing to obtain defect image data; A data processing module is used to perform defect detection processing on the defect image data based on a defect detection model to obtain surface defect detection data. A loss function is added to the defect detection model, and the defect detection model is obtained by improving the YOLO model. The data screening module is used to screen the surface defect detection data to obtain the surface defect detection result.
9. A defect detection device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the defect detection method based on visual detection according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the detection method based on visual detection of defects as described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
A road ponding image detection and early warning method based on a hybrid model
CN109670404A
Insulator defect detection method based on improved YOLOv7
CN115731164A
Image defect target detection method and device, equipment and storage medium
CN118154529A
Wire rod surface defect detection method based on semi-supervised learning
CN118447322A
Workpiece material surface defect detection method based on YOLOv5 optimization model
CN118485649A