Defect detection method and device, electronic equipment and computer readable storage medium
By preprocessing and feature extraction of the object detection image, combined with the feature fusion technology of the training model, the problem of low detection accuracy caused by low contrast and uneven grayscale in the prior art is solved, and the accuracy of defect detection is improved.
Patent Information
- Application Number
- CN202510779968.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-06-12
AI Technical Summary
The existing workpiece defect detection methods are difficult to accurately identify defects when processing images with low contrast, uneven grayscale distribution or blurred boundaries, resulting in low detection accuracy.
By acquiring the object detection image and preprocessing it, the trained defect detection model is used to extract the object detection image and the preprocessed image, and fuse the combined features to output defect detection results, including technical means such as contrast enhancement, grayscale uniformization and feature fusion.
It improves the accuracy of defect detection, reduces the impact of image problems on detection, and enhances the detection ability of complex defects.
Smart Images

Figure CN120411071A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and particularly to a defect detection method, device, electronic device, and computer-readable storage medium. Background Art
[0002] In the existing workpiece defect detection, when detecting defects in the X-ray image of a steering knuckle casting, when there are image problems such as low contrast, uneven gray-scale distribution, or blurred boundaries in the regions corresponding to some defects in the image, it is difficult to be accurately identified by the existing defect detection methods, and the detection accuracy is low. Summary of the Invention
[0003] The main object of the present invention is to propose a defect detection method, device, electronic device, and computer-readable storage medium, aiming to solve the problem of low defect detection accuracy in the existing technology.
[0004] To achieve the above object, the present invention provides a defect detection method, and the method includes the steps of: Obtain a target detection image of a target workpiece, and preprocess the target detection image to obtain a preprocessed image; Perform defect detection on the target detection image and the preprocessed image through a trained defect detection model. Among them, at the feature extraction level of the trained defect detection model, extract joint features from the target detection image and the preprocessed image; Output a defect detection result through the trained defect detection model based on the joint features obtained at each level.
[0005] Optionally, the preprocessing the target detection image to obtain a preprocessed image includes: Obtain the original contrast of the target detection image; Obtain a contrast threshold, and determine whether the original contrast is less than the contrast threshold; If the original contrast is less than the contrast threshold, enhance the contrast of the target detection image to obtain the preprocessed image, where the contrast of the preprocessed image is greater than or equal to the contrast threshold.
[0006] Optionally, the preprocessing the target detection image to obtain a preprocessed image includes: Obtain the original gray-scale variance of the target detection image; Obtain a gray-scale variance threshold, and determine whether the original gray-scale variance is greater than the gray-scale variance threshold; If the original gray-scale variance is greater than the gray-scale variance threshold, eliminate the local gray-scale difference of the target detection image to obtain the preprocessed image.
[0007] Optionally, before obtaining the contrast threshold, the following steps are included: Obtain first historical undetected images, and determine the historical contrast corresponding to each of the first historical undetected images; Take the maximum of the historical contrasts as the reference contrast; Determine the contrast threshold according to the reference contrast, where the contrast threshold is greater than the reference contrast.
[0008] Optionally, the step of extracting joint features from the target detection image and the preprocessed image includes: Extract original image features from the target detection image; Extract preprocessing features from the preprocessed image; Obtain a scale factor, and perform feature fusion on the original image features and the preprocessing features based on the scale factor to obtain the joint features.
[0009] Optionally, before performing defect detection on the target detection image and the preprocessed image through a trained defect detection model, the following steps are included: Obtain an initial defect detection model, where the defect detection model includes an auxiliary decoding head, and an atrous spatial pyramid pooling layer is arranged in the auxiliary decoding head; Obtain defect detection training samples, and train the initial defect detection model through the defect detection training samples to obtain a trained defect detection model.
[0010] Optionally, the defect detection model includes a dropout layer, and the step of performing defect detection on the target detection image and the preprocessed image through the trained defect detection model includes: Obtain the number of real-time workpiece types and the number of dataset categories corresponding to the defect detection model; Determine a target discard probability corresponding to the number of real-time workpiece types according to the number of dataset categories, where the target discard probability is negatively correlated with the number of real-time workpiece types; Set the discard probability of the dropout layer to the target discard probability.
[0011] To achieve the above object, the present invention further provides a defect detection device, where the defect detection device includes: A first acquisition module, configured to acquire a target detection image of a target workpiece, and preprocess the target detection image to obtain a preprocessed image; The first detection module is used to perform defect detection on the target detection image and the preprocessed image through a trained defect detection model. Among them, at the feature extraction level of the trained defect detection model, feature extraction is performed on the target detection image and the preprocessed image to obtain joint features; The first execution module is used to output a defect detection result based on the joint features obtained at each level through the trained defect detection model.
[0012] To achieve the above object, the present invention also provides an electronic device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps of the above-mentioned defect detection method are implemented.
[0013] To achieve the above object, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned defect detection method are implemented.
[0014] A defect detection method, device, electronic device, and computer-readable storage medium provided by the present invention. A target detection image of a target workpiece is obtained, and the target detection image is preprocessed to obtain a preprocessed image; the target detection image and the preprocessed image are subjected to defect detection through a trained defect detection model. Among them, at the feature extraction level of the trained defect detection model, feature extraction is performed on the target detection image and the preprocessed image to obtain joint features; a defect detection result is output based on the joint features obtained at each level through the trained defect detection model. By obtaining the preprocessed image corresponding to the target detection image, the image problems in the target detection image are reduced. By separately performing feature extraction on the target detection image and the preprocessed image and obtaining joint features, the joint features can simultaneously reflect the original defect situation of the target detection image and the defect situation after enhancement of the preprocessed image, thereby being able to reduce the impact of image problems on defect detection and improve the detection accuracy. Description of the Drawings
[0015] The drawings here are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present invention and used together with the specification to explain the principles of the present invention.
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0017] Figure 1 It is a schematic flowchart of the first embodiment of the defect detection method of the present invention; Figure 2 It is a schematic diagram of the module structure of the electronic device of the present invention. Detailed implementation manners
[0018] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. In order to enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0019] The present invention provides a defect detection method. Referring to Figure 1 , Figure 1 which is a schematic flowchart of the first embodiment of the defect detection method of the present invention, the method includes the steps: Step S10, obtaining a target detection image of a target workpiece and preprocessing the target detection image to obtain a preprocessed image; The target workpiece is the workpiece that needs to be defect-detected; the specific type of the target workpiece can be set based on actual needs. In this embodiment and subsequent embodiments, the target workpiece is taken as an example of a steering knuckle casting for illustration.
[0020] The target detection image is an image obtained by image acquisition of the target workpiece; the specific image acquisition method and form can be set based on actual needs. For example, the target detection image can be an RGB image, an infrared image, or an X-ray image. In this embodiment, the target detection image is taken as an X-ray image for illustration.
[0021] Preprocessing is to adjust the image parameters of the target detection image to obtain a clearer preprocessed image; the specific preprocessing method can be set based on actual needs. For example, for an X-ray image, there may be problems such as low contrast and uneven gray distribution. Therefore, preprocessing methods such as contrast enhancement and gray level uniformity can be set to obtain the preprocessed image.
[0022] Step S20, performing defect detection on the target detection image and the preprocessed image through a trained defect detection model. Among them, at the feature extraction level of the trained defect detection model, feature extraction is performed on the target detection image and the preprocessed image to obtain joint features; Step S30: Based on the joint features obtained at each level by the trained defect detection model, output the defect detection result.
[0023] The defect detection model is used to detect defects in the target detection image.
[0024] The specific type of the defect detection model can be set according to actual needs. For example, a semantic segmentation model. In this embodiment, a semantic segmentation model with ConvNeXt as the backbone network is used as the defect detection model.
[0025] In this embodiment, the target detection image and the preprocessed image are encoded in a two-way manner, and the features extracted from the target detection image and the preprocessed image are fused by the trained defect detection model to obtain joint features. The joint features are obtained by the combined action of the features of the target detection image and the preprocessed image. Therefore, the joint features can reflect the defect features in both the target detection image and the preprocessed image at the same time; through the joint features, the detection ability for complex defects can be enhanced, thereby improving the detection accuracy.
[0026] The feature extraction level is the layer in the defect detection model that extracts features from the image; the specific feature extraction level can be set according to actual needs; for example, the defect detection model can include four stage modules. The first stage: sample and normalize the input image through a 4×4 convolution, reduce the resolution to 1 / 4 and expand the number of channels; the second stage: sequentially perform a 7×7 depthwise separable convolution, channel normalization, 1x1 convolution expansion (MLP ratio expansion), GELU (Gaussian Error Linear Units) activation, 1x1 convolution contraction, and fuse the input and output through a residual connection and a dropout layer. Finally, perform downsampling through a 2×2 convolution, reduce the resolution to 1 / 8 and expand the number of channels; the third stage: perform the same operations as the second stage, and finally perform downsampling through a 2×2 convolution, reduce the resolution to 1 / 16 and expand the number of channels; the fourth stage: perform the same operations as the second stage, and finally perform downsampling through a 2×2 convolution, reduce the resolution to 1 / 32 and expand the number of channels; the output is a global semantic feature with 1024 channels.
[0027] For example, in the first convolutional layer, features are extracted from and fused for the target detection image and the preprocessed image respectively to obtain the corresponding joint features, and the joint features are output to subsequent layers for convolution to further obtain the joint features corresponding to each level until the global semantic feature is finally output. The defect detection result is obtained based on the global semantic feature; the defect detection result can include whether there are defects, defect types, sizes, positions, images, etc.
[0028] In this embodiment, the preprocessed image corresponding to the target detection image is obtained to reduce the image problems in the target detection image. By respectively extracting features from the target detection image and the preprocessed image and obtaining the combined features, the combined features can simultaneously reflect the original defect situation of the target detection image and the defect situation after enhancement of the preprocessed image, so as to reduce the impact of image problems on defect detection and improve the detection accuracy.
[0029] Further, in the second embodiment of the defect detection method of the present invention proposed based on the first embodiment of the present invention, the step S10 includes the steps: Step S11, obtaining the original contrast of the target detection image; Step S12, obtaining a contrast threshold and determining whether the original contrast is less than the contrast threshold; Step S13, if the original contrast is less than the contrast threshold, performing contrast enhancement on the target detection image to obtain the preprocessed image, wherein the contrast of the preprocessed image is greater than or equal to the contrast threshold.
[0030] If the original contrast is greater than or equal to the contrast threshold, no contrast enhancement is performed on the target detection image.
[0031] The original contrast is the actual contrast of the target detection image.
[0032] The contrast threshold is the minimum allowable contrast of the target detection image; it can be understood that when the original contrast of the target detection image is too small, the contrast between the defects and the background in the target detection image is not obvious, it is more difficult to identify the defects from the image, and at the same time, the details of the picture are severely lost, which will also affect the accuracy of defect detection. Therefore, in this embodiment, a contrast threshold is set to judge the original contrast situation of the target detection image. When it is detected that the original contrast is too small, contrast enhancement is performed on the target detection image so that the contrast of the preprocessed image obtained after contrast enhancement can reach the contrast threshold, so that the contrast of the preprocessed image can meet the requirements of defect detection.
[0033] The specific value of the contrast threshold can be set based on actual needs.
[0034] Further, the step S10 includes the steps: Step S14, obtaining the original gray variance of the target detection image; Step S15, obtaining a gray variance threshold and determining whether the original gray variance is greater than the gray variance threshold; Step S16: If the original gray variance is greater than the gray variance threshold, eliminate the local gray difference of the target detection image to obtain the preprocessed image.
[0035] If the original gray variance is less than or equal to the gray variance threshold, do not eliminate the local gray difference of the target detection image.
[0036] The original gray variance is the actual gray variance of the target detection image; the gray variance can be calculated from the gray levels of each pixel in the target detection image.
[0037] The gray variance threshold is the maximum allowable gray variance of the target detection image. It can be understood that when the original gray variance of the target detection image is too large, there will be a problem of uneven gray distribution in the target detection image, making it difficult to identify defects from the image. Therefore, in this embodiment, a gray variance threshold is set to judge the original gray variance of the target detection image. When it is detected that the original gray variance is too large, the local gray difference of the target detection image is eliminated so that the gray variance of the obtained preprocessed image after elimination can be less than the gray variance threshold, thereby enabling the gray variance of the preprocessed image to meet the requirements of defect detection.
[0038] The specific method for eliminating the local gray difference is as follows:
[0039] Among them, I1 is the pixel gray value obtained after pixel elimination; (x, y) is the coordinate of the pixel in the target detection image; I is the gray value of the pixel in the target detection image; μ is the local mean; σ is the standard deviation, and ε is a constant.
[0040] When calculating the local mean, the target detection image can be divided into small regions, and the size of the region is determined according to the set sliding window size. The local mean is the average value of the pixel values in the small region.
[0041] The specific value of the gray variance threshold can be set based on actual needs.
[0042] It should be noted that the specific operations of preprocessing can include multiple types. For example, by judging the above contrast threshold and gray variance threshold for the target detection image, and determining whether contrast enhancement and local gray difference elimination are required based on the specific judgment results. For example, when the actual contrast of the target detection image is less than the contrast threshold and the actual gray variance is greater than the gray variance threshold, contrast enhancement and local gray difference elimination are performed on the target detection image to obtain the preprocessed image.
[0043] Further, before step S12, it includes: Step S121, obtain the first historical undetected images, and determine the historical contrast corresponding to each of the first historical undetected images; Step S122, use the maximum of the historical contrasts as the reference contrast; Step S123, determine the contrast threshold according to the reference contrast, where the contrast threshold is greater than the reference contrast.
[0044] The first historical undetected images are the images that are determined to be undetected due to low contrast after defect detection on the production line; it can be understood that the first historical undetected images are updated in real time based on the defect detection method of the present application in the production line application; the first historical undetected images can be determined by manual sampling inspection.
[0045] The historical contrast is the actual contrast of the first historical undetected image.
[0046] Determine the maximum value in the historical contrasts as the reference contrast; it can be understood that since the first historical undetected images are all due to low contrast, therefore, the maximum value in the historical contrasts has a high probability of being the contrast critical value that can be detected and undetected. Therefore, in this embodiment, the contrast threshold is determined by the reference contrast, and the contrast threshold is greater than the reference contrast, so that the contrast threshold can be greater than the contrast critical value that can be detected and undetected, improving the optimization effect for images with low contrast. The relative size between the specific contrast threshold and the reference contrast can be set based on actual needs, such as setting the contrast threshold to 1.2 times the reference contrast.
[0047] Further, before the step S15, it includes: Step S151, obtain the second historical undetected images, and determine the historical gray variance corresponding to each of the second historical undetected images; Step S152, use the minimum of the historical gray variances as the reference gray variance; Step S153, use the reference gray variance as the gray variance threshold.
[0048] The second historical undetected images are the images that are determined to be undetected due to high gray variance after defect detection on the production line; it can be understood that the second historical undetected images are updated in real time based on the defect detection method of the present application in the production line application; the second historical undetected images can be determined by manual sampling inspection.
[0049] The historical gray variance is the actual gray variance of the second historical undetected image.
[0050] Determine the minimum value in the historical grayscale variance as the reference grayscale variance. It can be understood that since the second historical undetected images are all caused by a relatively high grayscale variance, therefore, there is a high probability that the minimum value in the historical grayscale variance is the grayscale variance critical value that can be detected and undetected. Therefore, in this embodiment, the reference grayscale variance is used as the grayscale variance threshold, so that the grayscale variance threshold can reach the grayscale variance critical value of detection and undetected, and improve the optimization effect for images with a relatively high grayscale variance.
[0051] Further, in the third embodiment of the defect detection method of the present invention proposed based on the first embodiment of the present invention, the step S20 includes the steps: Step S21, extract features from the target detection image to obtain the original image features; Step S22, extract features from the preprocessed image to obtain the preprocessing features; Step S23, obtain the proportionality coefficient, and perform feature fusion on the original image features and the preprocessing features based on the proportionality coefficient to obtain the combined features.
[0052] The original image features are the image features obtained by extracting features from the target detection image.
[0053] The preprocessing features are the image features obtained by extracting features from the preprocessed image.
[0054] It can be understood that the original image features reflect the defect situation in the target detection image and are more inclined to the actual acquisition of the real situation; the preprocessing features reflect the defect situation in the preprocessed image and are more inclined to the situation of the clear image; therefore, by fusing the original image features and the preprocessing features, the combined features that reflect both the real situation and the clear situation can be obtained. Therefore, based on the combined features, the detection accuracy can be improved.
[0055] Specifically, the feature fusion operation can be:
[0056] Where, T is the combined feature; T1 is the original image feature; T2 is the preprocessing feature; a is the proportionality coefficient.
[0057] The proportionality coefficient is used to indicate the influence of the original image features on the combined features. It can be understood that the larger the proportionality coefficient, the more the original image features can be highlighted, and the features of low-contrast and uneven grayscale distribution images can be better retained; while the smaller the proportionality coefficient, the more the preprocessing image features can be highlighted, and the features of low-contrast and uneven grayscale distribution images can be better eliminated; the proportionality coefficient can be set based on the actual application scenario and optimization needs, such as 50%.
[0058] Further, in the fourth embodiment of the defect detection method of the present invention proposed based on the first embodiment of the present invention, before the step S20, the following steps are included: Step S40, obtaining an initial defect detection model, where the defect detection model includes an auxiliary decoding head, and an atrous spatial pyramid pooling layer is arranged in the auxiliary decoding head; Step S50, obtaining defect detection training samples, and training the initial defect detection model with the defect detection training samples to obtain a trained defect detection model.
[0059] The auxiliary decoding head processes the features output by the first to fourth stages in the defect detection model through the FCNHead structure; under conventional sampling, local detail features will be lost, resulting in low detection accuracy of the defect detection model for small defects. Therefore, in this embodiment, an ASPP (Atrous Spatial Pyramid Pooling) is set in the auxiliary decoding head. ASPP is implemented in the multi-scale context extraction stage after feature mapping, captures semantic information with different receptive fields through parallel dilated convolutions, and finally outputs a segmentation prediction map matching the input resolution through 1×1 convolution and upsampling to assist the training of the main decoding head; the dilated convolution of ASPP can expand the receptive field without reducing the resolution, retain spatial details, and improve the detection ability for small defects.
[0060] The defect detection training samples are used to train the defect detection model; the specific acquisition method of the defect detection training samples can be set based on actual needs. For example, X-ray images of various types of steering knuckle castings on the production line are collected, and defect detection training samples are obtained through manual defect annotation.
[0061] The specific settings in model training can be set based on actual needs, such as the loss function, the number of iterations, etc.
[0062] After obtaining the trained defect detection model, the defect detection model can be converted into the tensorrt acceleration format and deployed to the production line for defect detection; Tensorrt is a high-performance deep learning inference optimization library, which improves the inference speed of the model through technologies such as optimizing graph computing and reducing memory occupancy. After converting the trained model into an engine file through Tensorrt, it can run efficiently on the GPU.
[0063] Further, in the fifth embodiment of the defect detection method of the present invention proposed based on the first embodiment of the present invention, the defect detection model includes a dropout layer, and the step S20 includes the following steps: Step S24, obtaining the number of real-time workpiece types and the number of dataset categories corresponding to the defect detection model; Step S25: Determine the target discard probability corresponding to the number of real-time workpiece types according to the number of dataset categories, where the target discard probability is negatively correlated with the number of real-time workpiece types. Step S26: Set the discard probability of the discard layer to the target discard probability.
[0064] The discard layer is used to randomly discard a part of neurons to prevent the model from overfitting.
[0065] The number of dataset categories is the number of categories included in the dataset corresponding to the pre-trained model adopted by the defect detection model. For example, if a pre-trained model on the ADE20K dataset is used, and the ADE20K dataset contains 150 categories, so the corresponding number of dataset categories is 150.
[0066] The number of real-time workpiece types is the number of models of workpieces that need to be processed on the current production line, such as the number of models of steering knuckle castings included on the current production line. In this embodiment, the target discard probability is set to be negatively correlated with the number of real-time workpiece types. When the number of models of steering knuckle castings is less than the number of dataset categories, the fewer the number of models of steering knuckle castings, the more features the dataset has relatively. At this time, the neuron discard probability is greater, and relatively more dataset features are discarded, so that the features of the steering knuckle castings can be highlighted more. When the number of models of steering knuckle castings is more than the number of dataset categories: At this time, the discard probability is small and set to a fixed value, which can ensure that fewer features of the steering knuckle castings are discarded; specifically:
[0067] Among them, p1 is the target discard probability, n is the number of real-time workpiece types, and C1 is the number of dataset categories.
[0068] Taking the ADE20K dataset as an example, C1 is 150. The number of models of steering knuckle castings is small and less than 150. It can be seen from the above formula that the smaller n is, the greater the probability p1 is, and more neurons are discarded. From the perspective of categories, in this case, the number of models of steering knuckle castings is less than the number of categories in the ADE20K dataset. So discarding more neurons is equivalent to discarding more features of the dataset and fewer features of the steering knuckle castings, that is, highlighting the defect features of the steering knuckle castings.
[0069] The number of models of steering knuckle castings is large and greater than 150. In this case, the probability p1 directly jumps to 0.1, that is, a fixed number of neurons are discarded less. From the perspective of categories, in this case, the number of models of steering knuckle castings is already greater than the number of categories in the ADE20K dataset. Discarding neurons in this case will result in more features of the steering knuckle castings being discarded compared to the dataset features. So setting the probability to 0.1 can retain the defect features of the steering knuckle castings and ensure the detection accuracy.
[0070] Generally speaking, by adopting the optimized discard layer, the defect features of the knuckle casting can be better extracted during training, and the detection accuracy of the model can be improved.
[0071] It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that this application is not limited by the described action sequence, because according to this application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0072] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of this application, in essence, or the part that makes a contribution to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions for causing a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in various embodiments of this application.
[0073] This application also provides a defect detection device for implementing the above defect detection method. The defect detection device includes: A first acquisition module, configured to acquire a target detection image of a target workpiece and preprocess the target detection image to obtain a preprocessed image; A first detection module, configured to perform defect detection on the target detection image and the preprocessed image through a trained defect detection model. Among them, at the feature extraction level of the trained defect detection model, feature extraction is performed on the target detection image and the preprocessed image to obtain joint features; A first execution module, configured to output a defect detection result based on the joint features obtained at each level through the trained defect detection model.
[0074] This defect detection device reduces the image problems in the target detection image by acquiring the preprocessed image corresponding to the target detection image. By separately performing feature extraction on the target detection image and the preprocessed image and obtaining joint features, the joint features can simultaneously reflect the original defect situation of the target detection image and the defect situation after enhancement of the preprocessed image, so as to reduce the impact of image problems on defect detection and improve the detection accuracy.
[0075] It should be noted that the first acquisition module in this embodiment can be used to execute step S10 in the embodiment of the present application, the first detection module in this embodiment can be used to execute step S20 in the embodiment of the present application, and the first execution module in this embodiment can be used to execute step S30 in the embodiment of the present application.
[0076] Further, the first acquisition module includes: A first acquisition unit, configured to acquire the original contrast of the target detection image; A second acquisition unit, configured to acquire a contrast threshold and determine whether the original contrast is less than the contrast threshold; A first execution unit, configured to, if the original contrast is less than the contrast threshold, perform contrast enhancement on the target detection image to obtain the preprocessed image, where the contrast of the preprocessed image is greater than or equal to the contrast threshold.
[0077] Further, the first acquisition module includes: A third acquisition unit, configured to acquire the original gray variance of the target detection image; A fourth acquisition unit, configured to acquire a gray variance threshold and determine whether the original gray variance is greater than the gray variance threshold; A second execution unit, configured to, if the original gray variance is greater than the gray variance threshold, eliminate the local gray difference of the target detection image to obtain the preprocessed image.
[0078] Further, before acquiring the contrast threshold, it includes: A first acquisition subunit, configured to acquire first historical missed detection images and determine the historical contrasts corresponding to the first historical missed detection images; A first execution subunit, configured to use the maximum of the historical contrasts as a reference contrast; A first determination subunit, configured to determine the contrast threshold according to the reference contrast, where the contrast threshold is greater than the reference contrast.
[0079] Further, the first detection module includes: A first extraction unit, configured to extract original image features from the target detection image; A second extraction unit, configured to extract preprocessing features from the preprocessed image; A fifth acquisition unit, configured to acquire a proportionality coefficient and perform feature fusion on the original image features and the preprocessing features based on the proportionality coefficient to obtain the combined features.
[0080] Further, the device further includes: A second acquisition module, configured to acquire an initial defect detection model, where the defect detection model includes an auxiliary decoding head, and a dilated spatial pyramid pooling layer is arranged in the auxiliary decoding head; A third acquisition module, configured to acquire defect detection training samples, and train the initial defect detection model with the defect detection training samples to obtain a trained defect detection model.
[0081] Further, the defect detection model includes a dropout layer, and the first detection module includes: A sixth acquisition unit, configured to acquire the number of real-time workpiece types and the number of dataset categories corresponding to the defect detection model; A first determination unit, configured to determine a target discard probability corresponding to the number of real-time workpiece types according to the number of dataset categories, where the target discard probability is negatively correlated with the number of real-time workpiece types; A first setting unit, configured to set the discard probability of the dropout layer to the target discard probability.
[0082] Refer to Figure 2 , in terms of hardware structure, the electronic device may include components such as a communication module 10, a memory 20, and a processor 30. In the electronic device, the processor 30 is respectively connected to the memory 20 and the communication module 10. A computer program is stored on the memory 20 and is simultaneously executed by the processor 30. When the computer program is executed, the steps of the above method embodiment are implemented.
[0083] The communication module 10 can be connected to an external communication device through a network. The communication module 10 can receive requests sent by the external communication device, and can also send requests, instructions, and information to the external communication device. The external communication device can be other electronic devices, servers, or Internet of Things devices, such as a TV, etc.
[0084] The memory 20 can be used to store software programs and various data. The memory 20 mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as obtaining a target detection image of a target workpiece), etc.; the data storage area can include a database, and the data storage area can store data or information created according to the use of the system. In addition, the memory 20 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0085] The processor 30 is the control center of the electronic device, connecting various parts of the entire electronic device through various interfaces and circuits. By running or executing software programs and / or modules stored in the memory 20, and by calling the data stored in the memory 20, it executes various functions of the electronic device and processes data, thereby monitoring the entire electronic device. The processor 30 may include one or more processing units; optionally, the processor 30 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 30 either.
[0086] Although Figure 2 not shown, the above-mentioned electronic device may further include a circuit control module, which is used to connect to the power supply to ensure the normal operation of other components. Those skilled in the art can understand that Figure 2 the structure of the electronic device shown in
[0087] does not constitute a limitation on the electronic device, and it may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements. Figure 2 The present invention also proposes a computer-readable storage medium, on which a computer program is stored. The computer-readable storage medium may be the memory 20 in the
[0088] electronic device, or at least one of ROM (Read-Only Memory), RAM (Random Access Memory), magnetic disk, and optical disk. The computer-readable storage medium includes several instructions for causing a terminal device with a processor (which may be a TV, a car, a mobile phone, a computer, a server, a terminal, or a network device, etc.) to execute the methods described in various embodiments of the present invention.
[0089] In the description of this specification, the description referring to terms such as "one embodiment", "some embodiments", "examples", "specific examples", or "some examples", etc. means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0090] Although the embodiments of the present invention have been shown and described above, the scope of protection of the present invention is not limited thereto. It can be understood that the above embodiments are exemplary and should not be construed as limitations on the present invention. Those of ordinary skill in the art can make changes, modifications, and substitutions to the above embodiments within the scope of the present invention, and these changes, modifications, and substitutions should all be covered by the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A defect detection method, characterized in that, The defect detection method includes: Obtaining a target detection image of a target workpiece, and preprocessing the target detection image to obtain a preprocessed image; Performing defect detection on the target detection image and the preprocessed image through a trained defect detection model. Wherein, at the feature extraction level of the trained defect detection model, feature extraction is performed on the target detection image and the preprocessed image to obtain joint features; Outputting a defect detection result based on the joint features obtained at each level through the trained defect detection model.
2. The defect detection method according to claim 1, characterized in that, The preprocessing the target detection image to obtain a preprocessed image includes: Obtaining the original contrast of the target detection image; Obtaining a contrast threshold, and determining whether the original contrast is less than the contrast threshold; If the original contrast is less than the contrast threshold, enhancing the contrast of the target detection image to obtain the preprocessed image, wherein the contrast of the preprocessed image is greater than or equal to the contrast threshold.
3. The defect detection method according to claim 2, wherein Before obtaining the contrast threshold includes: Obtaining first historical missed detection images, and determining the historical contrasts corresponding to the first historical missed detection images; Taking the maximum of the historical contrasts as a reference contrast; Determining the contrast threshold according to the reference contrast, wherein the contrast threshold is greater than the reference contrast.
4. The defect detection method according to claim 1, wherein The preprocessing the target detection image to obtain a preprocessed image includes: Obtaining the original gray variance of the target detection image; Obtaining a gray variance threshold, and determining whether the original gray variance is greater than the gray variance threshold; If the original gray variance is greater than the gray variance threshold, eliminating the local gray difference of the target detection image to obtain the preprocessed image.
5. The defect detection method according to claim 1, characterized in that, The performing feature extraction on the target detection image and the preprocessed image to obtain joint features includes: Performing feature extraction on the target detection image to obtain original image features; Performing feature extraction on the preprocessed image to obtain preprocessing features; Obtaining a scale factor, and performing feature fusion on the original image features and the preprocessing features based on the scale factor to obtain the joint features.
6. The defect detection method according to claim 1, wherein Before performing defect detection on the target detection image and the preprocessed image through a trained defect detection model includes: Obtaining an initial defect detection model, wherein the defect detection model includes an auxiliary decoding head, and a dilated spatial pyramid pooling layer is arranged in the auxiliary decoding head; Obtaining defect detection training samples, and training the initial defect detection model through the defect detection training samples to obtain a trained defect detection model.
7. The defect detection method according to claim 1, characterized in that The defect detection model includes a dropout layer, and the performing defect detection on the target detection image and the preprocessed image through a trained defect detection model includes: Obtaining the number of real-time workpiece types and the number of dataset categories corresponding to the defect detection model; Determining a target discard probability corresponding to the number of real-time workpiece types according to the number of dataset categories, wherein the target discard probability is negatively correlated with the number of real-time workpiece types; Set the discard probability of the discard layer to the target discard probability.
8. A defect detection device, characterized in that, The defect detection device includes: A first acquisition module, configured to acquire a target detection image of a target workpiece, and perform preprocessing on the target detection image to obtain a preprocessed image; A first detection module, configured to perform defect detection on the target detection image and the preprocessed image through a trained defect detection model. Wherein, at the feature extraction level of the trained defect detection model, feature extraction is performed on the target detection image and the preprocessed image to obtain a joint feature; A first execution module, configured to output a defect detection result based on the joint features obtained at each level through the trained defect detection model.
9. An electronic device, characterized in that, The electronic device includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps of the defect detection method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium. When the computer program is executed by the processor, the steps of the defect detection method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Training method of image segmentation model, image segmentation method, device thereof and equipment
CN113516665A
Railway vehicle running gear welding seam detection method and system
CN113744224A
Remote sensing image classification method and device and electronic equipment
CN118247538A
Defect classification method and system for semiconductor chip and readable storage medium
CN119313623A