Defect detection method, electronic equipment, storage medium and program product
By performing frequency domain enhancement and differential operation on the surface of metal stamping parts, the problem of low detection accuracy of ordinary vision algorithms in low contrast scenes is solved, and efficient defect detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN ZHUOJIAN INTELLIGENT MANUFACTURING CO LTD
- Filing Date
- 2026-01-26
- Publication Date
- 2026-05-08
AI Technical Summary
In existing technologies, the detection accuracy of surface defects in metal stamping parts using ordinary vision algorithms is relatively low.
By performing frequency domain enhancement processing on the target detection area image, a defect feature enhancement image is generated, and differential operation processing is performed to improve the grayscale contrast between the defect and the background.
It improves the detection accuracy in scenes where the surface defects of the target object have low grayscale contrast with the background.
Smart Images

Figure CN121998942A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of machine vision and industrial inspection technology, and in particular to a defect detection method, electronic device, storage medium and program product. Background Technology
[0002] Metal stampings are widely used in industrial fields such as automotive parts, electronic components, and hardware accessories. During the stamping process, surface defects such as striped depressions and raised streaks can occur due to factors such as die wear, uneven stamping pressure distribution, and differences in material ductility, directly affecting the product's appearance and performance. Therefore, defect detection is a crucial aspect of industrial quality control. Currently, in some application scenarios, due to the influence of material characteristics and lighting system configuration, the grayscale values of metal stamping surface images are often relatively concentrated, resulting in indistinct transitions between surface defects and the background and extremely low contrast, posing a significant challenge to defect detection.
[0003] In related technologies, common visual algorithms are typically used to detect surface defects in metal stamping parts. Specifically, spatial domain filtering (such as mean filtering and median filtering) is first used to calculate the average or median value of neighborhood pixels directly within the pixel space of the original image of the metal stamping part surface to reduce image noise. Then, simple edge detection operators (such as Canny operators and Sobel operators) are used to calculate the gradient change of image pixel grayscale, capture and locate the edge positions of grayscale abrupt changes caused by defects in the image, thereby realizing the detection of surface defects in metal stamping parts.
[0004] However, the above-mentioned method of using ordinary vision algorithms to detect surface defects in metal stamping parts has a problem of low detection accuracy in scenarios where the grayscale contrast between the surface defects and the background of metal stamping parts is low. Summary of the Invention
[0005] This application provides a defect detection method, electronic device, storage medium, and program product to solve the problem in the related art that the method of detecting surface defects of metal stamping parts using ordinary vision algorithms has a low detection accuracy in scenarios where the grayscale contrast between the surface defects of metal stamping parts and the background is low.
[0006] In a first aspect, this application provides a defect detection method, comprising: acquiring a target detection area image on the surface of a target object; performing frequency domain enhancement processing on the target detection area image to generate a defect feature enhancement image; performing differential operation processing on the defect feature enhancement image and the target detection area image to generate a differential image; and detecting defects on the surface of the target object based on the differential image.
[0007] In one possible implementation, frequency domain enhancement processing is performed on the target detection region image to generate a defect feature enhancement image, including: performing a fast Fourier transform on the target detection region image to obtain a frequency domain image corresponding to the target detection region image; convolving the frequency domain image with a preset frequency domain Gaussian filter to obtain a convolved frequency domain image, wherein the smoothing coefficients of the preset frequency domain Gaussian filter in the principal direction and vertical direction are determined according to the gray-level distribution characteristics of the original image of the target object surface; and performing an inverse fast Fourier transform on the convolved frequency domain image to obtain the defect feature enhancement image.
[0008] In one possible implementation, a difference operation is performed on the defect feature enhancement image and the target detection region image to generate a difference image. This includes: for each first pixel in the defect feature enhancement image, selecting a second pixel in the target detection region image corresponding to the spatial pixel coordinates of the first pixel, and calculating the gray value of a third pixel in the difference image at the corresponding spatial pixel coordinates based on a preset difference operation formula, the gray value of the first pixel, and the gray value of the corresponding second pixel. The difference operation parameters in the preset difference operation formula are determined based on the gray distribution characteristics of the original image of the target object surface; and generating a difference image based on the gray values of all third pixels.
[0009] In one possible implementation, detecting defects on the surface of a target object based on a differential image includes: generating a defect determination image based on the differential image; determining whether defect lines exist in the defect determination image; in response to the presence of defect lines in the defect determination image, and at least one defect line having a length greater than or equal to a preset length threshold, determining that the surface of the target object has defects that do not meet preset requirements, and determining that the target object is unqualified; in response to the presence of defect lines in the defect determination image, and each defect line having a length less than the preset length threshold, determining that the surface of the target object does not have defects that do not meet preset requirements, and determining that the target object is qualified; in response to the absence of defect lines in the defect determination image, determining that the surface of the target object does not have defects that do not meet preset requirements, and determining that the target object is qualified.
[0010] In one possible implementation, generating a defect determination image based on the difference image includes: performing Gaussian smoothing on the difference image based on preset Gaussian smoothing parameters to obtain a denoised image; calculating the line response value of each pixel in the denoised image; and generating a defect determination image based on the line response values of all pixels in the denoised image.
[0011] In one possible implementation, generating a defect determination image based on the line response values of all pixels in the denoised image includes: generating a defect response image based on the line response values of all pixels in the denoised image; performing a double threshold filtering process on the defect response image to determine the pixel type of each pixel in the defect response image, wherein the pixel type includes target defect pixels, candidate defect pixels, and non-defect pixels; generating defect lines based on the target defect pixels and candidate defect pixels; and generating a defect determination image based on the defect lines and non-defect pixels.
[0012] In one possible implementation, obtaining the target detection region image on the surface of the target object includes: obtaining the original image of the target object surface; and performing image cropping on the original image to obtain the target detection region image.
[0013] Secondly, this application provides a defect detection device, comprising:
[0014] The acquisition module is used to acquire images of the target detection area on the surface of the target object;
[0015] The first processing module is used to perform frequency domain enhancement processing on the target detection area image to generate a defect feature enhanced image;
[0016] The second processing module is used to perform differential operations on the defect feature enhancement image and the target detection area image to generate a differential image;
[0017] The detection module is used to detect defects on the surface of a target object based on the differential image.
[0018] In one possible implementation, the first processing module is specifically used to: perform a fast Fourier transform on the target detection region image to obtain a frequency domain image corresponding to the target detection region image; convolve the frequency domain image with a preset frequency domain Gaussian filter to obtain a convolved frequency domain image, wherein the smoothing coefficients of the preset frequency domain Gaussian filter in the principal direction and vertical direction are determined according to the gray-level distribution characteristics of the original image of the target object surface; and perform an inverse fast Fourier transform on the convolved frequency domain image to obtain a defect feature enhancement image.
[0019] In one possible implementation, the second processing module is specifically used to: for each first pixel in the defect feature enhancement image, select a second pixel in the target detection region image corresponding to the spatial pixel coordinates of the first pixel, and calculate the gray value of a third pixel in the difference image at the corresponding spatial pixel coordinates based on a preset difference operation formula, the gray value of the first pixel, and the gray value of the corresponding second pixel, wherein the difference operation parameters in the preset difference operation formula are determined according to the gray distribution characteristics of the original image of the target object surface; and generate a difference image based on the gray values of all third pixels.
[0020] In one possible implementation, the detection module is specifically used to: generate a defect judgment image based on the differential image; determine whether defect lines exist in the defect judgment image; in response to the presence of defect lines in the defect judgment image, and at least one defect line having a length greater than or equal to a preset length threshold, determine that the surface of the target object has a defect that does not meet the preset requirements, and determine that the target object is unqualified; in response to the presence of defect lines in the defect judgment image, and each defect line having a length less than the preset length threshold, determine that the surface of the target object does not have a defect that does not meet the preset requirements, and determine that the target object is qualified; in response to the absence of defect lines in the defect judgment image, determine that the surface of the target object does not have a defect that does not meet the preset requirements, and determine that the target object is qualified.
[0021] In one possible implementation, the detection module is further configured to: perform Gaussian smoothing on the difference image based on preset Gaussian smoothing parameters to obtain a denoised image; calculate the line response value of each pixel in the denoised image; and generate a defect judgment image based on the line response values of all pixels in the denoised image.
[0022] In one possible implementation, the detection module is further configured to: generate a defect response image based on the line response values of all pixels in the denoised image; perform double threshold filtering on the defect response image to determine the pixel type of each pixel in the defect response image, wherein the pixel type includes target defect pixels, candidate defect pixels, and non-defect pixels; generate defect lines based on the target defect pixels and candidate defect pixels; and generate a defect determination image based on the defect lines and non-defect pixels.
[0023] In one possible implementation, the acquisition module is specifically used to: acquire the original image of the target object's surface; and perform image cropping on the original image to obtain the target detection region image.
[0024] Thirdly, this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0025] The memory stores instructions that the computer executes;
[0026] The processor executes computer execution instructions stored in memory to implement the defect detection method provided in the first aspect above.
[0027] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the defect detection method provided in the first aspect above.
[0028] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the defect detection method provided in the first aspect above.
[0029] This application provides a defect detection method, electronic device, storage medium, and program product. The defect detection method acquires an image of a target detection area on the surface of a target object, performs frequency domain enhancement processing on the target detection area image to generate a defect feature enhancement image, further performs differential operations on the defect feature enhancement image and the target detection area image to generate a difference image, and then detects defects on the surface of the target object based on the difference image. This application, by performing frequency domain enhancement processing on the target detection area image of the target object surface, achieves targeted suppression of background noise and enhancement of weak feature defects, separating the defects from background noise in the frequency domain. Further, by performing differential operations on the defect feature enhancement image and the target detection area image, and through grayscale difference amplification and offset adjustment, it improves the grayscale contrast between the defects and the background. By employing a combination of frequency domain enhancement processing and differential operation processing, the accuracy of defect detection is improved in scenes with low grayscale contrast between defects and the background on the target object surface. Attached Figure Description
[0030] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0031] Figure 1 Flowchart of the defect detection method provided in the embodiments of this application Figure 1 ;
[0032] Figure 2 A schematic diagram of a target detection region image provided in an embodiment of this application;
[0033] Figure 3 A schematic diagram of a differential image provided in an embodiment of this application;
[0034] Figure 4 Flowchart of the defect detection method provided in the embodiments of this application Figure 2 ;
[0035] Figure 5 A schematic diagram of a defect determination image provided in an embodiment of this application;
[0036] Figure 6 Flowchart of the defect detection method provided in the embodiments of this application Figure 3 ;
[0037] Figure 7 This is a schematic diagram of the defect detection device provided in the embodiments of this application;
[0038] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0039] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0040] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0041] In related technologies, the detection of surface defects in metal stamping parts mainly relies on methods such as manual inspection, conventional vision algorithms, and deep learning algorithms. Specifically:
[0042] 1) Manual inspection: Operators manually inspect the surface of metal stamping parts by visual inspection or with the help of magnifying glasses and other tools. However, this method relies on human experience and is greatly affected by subjectivity. In scenarios where the grayscale contrast between the surface defects of metal stamping parts and the background is low, slight concave and convex defects are easily missed or misdetected due to visual fatigue or light interference. It cannot guarantee the consistency and accuracy of inspection, and the inspection efficiency is low, making it difficult to adapt to large-scale industrial production.
[0043] 2) Common visual algorithms: First, spatial domain filtering (such as mean filtering and median filtering) is used to directly calculate the average or median value of the neighborhood pixels in the pixel space of the original image of the metal stamping part surface to reduce image noise. Then, simple edge detection operators (such as Canny operator and Sobel operator) are used to calculate the gradient change of image pixel gray level, capture and locate the edge position of gray level change caused by defects in the image, thereby realizing the detection of surface defects of metal stamping parts. However, this method is not optimized for gray level concentration and weak step defect scenes caused by material characteristics and light source system configuration. It cannot effectively amplify the gray level difference between defects and background, and thus it is difficult to accurately extract the concave and convex texture defect features from low contrast images. That is, it cannot effectively enhance defect features, and the defect extraction effect is poor. In the scenario where the gray level contrast between the surface defects of metal stamping parts and the background is low, there is a problem of low detection accuracy.
[0044] 3) Deep learning algorithm: First, a large number of surface images of metal stamping parts with and without defects are collected, and the defect locations and categories are manually labeled. Then, a deep learning algorithm (such as a convolutional neural network) model is selected, and the labeled data is input into the deep learning algorithm model for training. The deep learning algorithm model learns the feature differences between defective and normal areas, and a trained deep learning algorithm model is obtained. Finally, the image to be tested is input into the trained deep learning algorithm model for defect detection. The deep learning algorithm model outputs whether a defect exists and its location. However, this method is difficult to learn stable discriminative features because the grayscale difference between defective and normal areas in the scene is small and the feature recognition is low. Not only is the training cost high, but the defect detection accuracy and generalization are also insufficient, which cannot meet the practical needs of industrial batch inspection.
[0045] Therefore, there is an urgent need to provide an efficient defect detection method that is suitable for low-contrast scenarios.
[0046] Based on the technical problems existing in related technologies, the embodiments of this application perform frequency domain enhancement processing on the target detection area image of the target object surface to achieve targeted suppression of background noise and enhancement of weak feature defects, so that the defects are separated from the background noise in the frequency domain. Furthermore, by performing differential operation processing on the defect feature enhancement image and the target detection area image, the gray-level contrast between the defects and the background is improved through gray-level difference amplification and offset adjustment. By adopting a combination of frequency domain enhancement processing and differential operation processing, the accuracy of defect detection is improved in scenes where the gray-level contrast between the defects and the background on the target object surface is low.
[0047] The application scenarios of the embodiments of this application will be described below first.
[0048] The defect detection method provided in this application is applicable to automated detection of surface concave and convex defects in metal stamping parts, especially for complex visual conditions such as low contrast, concentrated image grayscale values (90-140 range), and weak step characteristics of defect features. Specifically, the defect detection method provided in this application can be applied to the detection of surface defects in automotive parts (such as door hinges and engine housings), electronic components (such as radiators and connector housings), and hardware accessories (such as screws and gears).
[0049] The technical solution of this application and how it solves the above-mentioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0050] Figure 1 Flowchart of the defect detection method provided in the embodiments of this application Figure 1.like Figure 1 As shown, a specific implementation of this defect detection method may include the following steps:
[0051] S101, acquire the target detection area image on the surface of the target object.
[0052] For example, the target object can be a metal stamping part with low grayscale contrast between surface defects and the background.
[0053] For example, the target detection region image can remove invalid edge regions and background interference from the surface of the target object, retaining only the valid surface region of the target object.
[0054] Understandably, detecting defects on the surface of a target object based on an image of the target detection region can not only effectively reduce the computational load of subsequent frequency domain enhancement and differential operation processing, but also reduce the impact of interference features on the detection results.
[0055] One possible implementation of this step is to use a camera to acquire the original image of the surface of the target object, and to preprocess the original image (such as image cropping) using a circular region of interest (ROI) with a radius of a preset number of pixels, retaining only the core area of the target object to be detected, and completely eliminating the interference of irrelevant areas such as image edges and device background, so as to obtain a target detection area image focused on the core area of the target object to be detected.
[0056] For example, the preset pixel size can be 620 pixels. This application does not limit the size of the preset pixel size; it can be determined based on the actual application requirements such as the size of the target object and the camera's imaging ratio.
[0057] Understandably, on the one hand, by setting the size of the preset pixels to be slightly smaller than the imaging diameter of the original image of the target object, it is ensured that the ROI can completely cover the core area to be detected of the target object, while removing irrelevant background such as equipment and conveyor belts at the edges of the image; on the other hand, the resolution of the original image and the imaging proportion of the target object determine that the radius of the preset pixels is the optimal value to adapt to the detection scenario, so that the ROI is neither too large and introduces unnecessary background interference, nor too small and misses some areas to be detected.
[0058] Figure 2 This is a schematic diagram of a target detection region image provided in an embodiment of this application. Figure 2 As shown, the target detection region image can be obtained by cropping the original image of the target object based on a ROI with a preset radius of pixels.
[0059] Understandable Figure 2This is merely a schematic diagram of the target detection region image. The shape and size of the target detection region image are not limited in this application embodiment, and can be determined according to the actual application requirements.
[0060] S102, perform frequency domain enhancement processing on the target detection area image to generate a defect feature enhanced image.
[0061] For example, the defect feature enhancement image can be an image obtained by suppressing background noise components that are different from the frequency band of the concave-convex texture defect in the target detection area image in the frequency domain, while enhancing the weak high-frequency features corresponding to the concave-convex texture defect.
[0062] Optionally, this step may include the following steps:
[0063] S1021, Perform a fast Fourier transform on the target detection region image to obtain the frequency domain image corresponding to the target detection region image.
[0064] It is understandable that the target detection region image is a spatial domain image.
[0065] For example, one possible implementation is to transform the target detection region image from the spatial domain to the frequency domain using a Fast Fourier Transform (FFT) to obtain the corresponding frequency domain image. The size of the transformed frequency domain image is the same as the size of the target detection region image.
[0066] S1022, perform convolution processing on the frequency domain image and a preset frequency domain Gaussian filter to obtain the convolved frequency domain image.
[0067] The smoothing coefficients of the preset frequency domain Gaussian filter in the main direction and vertical direction are determined based on the gray-scale distribution characteristics of the original image of the target object surface.
[0068] For example, the main direction can be the direction in which the surface texture of the target object most easily extends (such as along the texture direction of the stamping process of the target object), and the vertical direction can be the direction at 90° to the main direction. It can be understood that the combination of the main direction and the vertical direction can cover all possible distribution dimensions of defects on the surface of the target object.
[0069] For example, the smoothing coefficients of the preset frequency domain Gaussian filter can be the same or different in the principal direction and the vertical direction. This application does not limit this; the specific coefficients should be determined according to the actual application requirements based on the grayscale distribution characteristics of the original image of the target object's surface.
[0070] For example, when the gray values of the original image of the target object surface are concentrated between 90 and 140, that is, in a scene where the gray contrast between the target object surface defects and the background is low, the smoothing coefficient of the preset frequency domain Gaussian filter can be the same in the main direction and the vertical direction, both of which are 311.
[0071] It is understandable that when the gray values of the original image of the target object surface are concentrated between 90 and 140, by setting the smoothing coefficient of the preset frequency domain Gaussian filter to 311 in both the main direction and the vertical direction, it is possible to specifically suppress the components corresponding to background noise in the frequency domain, while strengthening the weak high-frequency domain features corresponding to the uneven texture defects.
[0072] For example, the size of the preset frequency domain Gaussian filter is the same as the size of the frequency domain image.
[0073] In this step, one possible implementation is as follows: for each pixel in the frequency domain image, multiply the frequency domain value corresponding to the pixel with the frequency domain value of the corresponding pixel in the preset frequency domain Gaussian filter to obtain the frequency domain value of the pixel after frequency domain enhancement, and then obtain the convolutional frequency domain image based on the frequency domain values of all pixels after frequency domain enhancement.
[0074] It is understandable that by convolving the frequency domain image with a preset frequency domain Gaussian filter, the frequency selectivity of the preset frequency domain Gaussian filter can be utilized to amplify the frequency domain difference between the defect and the background, thereby enhancing the weak high-frequency features of the defect.
[0075] S1023, perform inverse fast Fourier transform on the frequency domain image after convolution to obtain the defect feature enhancement image.
[0076] For example, one possible implementation is to use an inverse fast Fourier transform to convert the convolved frequency domain image from the frequency domain space to the spatial domain, thereby obtaining a defect feature enhancement image. The size of the defect feature enhancement image is consistent with the size of the target detection region image.
[0077] S103 performs differential processing on the defect feature enhancement image and the target detection area image to generate a differential image.
[0078] For example, in one possible implementation, a difference operation is performed on the gray values corresponding to pixels with the same spatial pixel coordinates in the defect feature enhancement image and the target detection region image to obtain the gray value corresponding to each pixel after the difference operation, and a difference image is generated based on the gray value corresponding to each pixel after the difference operation.
[0079] Figure 3 This is a schematic diagram of a differential image provided in an embodiment of this application. Compared to Figure 2 The target detection region image shown is from Figure 3 As can be seen from the image, the grayscale contrast between the defect and the background is significantly enhanced in the defect feature enhancement image, and the distinction between the concave and convex texture defects and the background is significantly improved.
[0080] S104, based on the differential image, detect defects on the surface of the target object.
[0081] For example, one possible implementation of this step is to use a straight line extraction method that is adapted to the grayscale contrast of the target object's surface defects and the background, extract defect lines based on the difference image, and further determine defects based on the line features of the defect lines, thereby realizing the detection of surface defects of the target object.
[0082] In this embodiment, frequency domain enhancement processing is performed on the target detection area image on the surface of the target object to achieve targeted suppression of background noise and enhancement of weak feature defects, so that the defects are separated from the background noise in the frequency domain. Furthermore, differential operation processing is performed on the defect feature enhancement image and the target detection area image. By amplifying the gray-level difference and adjusting the offset, the gray-level contrast between the defects and the background is improved. By adopting a combination of frequency domain enhancement processing and differential operation processing, the accuracy of defect detection is improved in scenes where the gray-level contrast between the defects and the background on the surface of the target object is low.
[0083] Optionally, step S103, which performs differential operations on the defect feature enhancement image and the target detection region image to generate a differential image, can be implemented as follows: For each first pixel in the defect feature enhancement image, a second pixel corresponding to the spatial pixel coordinates of the first pixel is selected in the target detection region image. Based on a preset differential operation formula, the gray value of the first pixel, and the gray value of the corresponding second pixel, the gray value of the third pixel in the corresponding spatial pixel coordinates in the differential image is calculated. The differential image is then generated based on the gray values of all third pixels. The differential operation parameters in the preset differential operation formula are determined based on the gray-level distribution characteristics of the original image of the target object's surface.
[0084] For example, the preset difference operation formula can be expressed by the following formula:
[0085]
[0086] in, This represents the gray value of the third pixel in the difference image. This represents the grayscale value of the second pixel in the target detection region image. This represents the grayscale value of the first pixel in the defect feature enhancement image. Indicates the scaling factor. This indicates the offset.
[0087] For example, the scaling factor and offset are the difference operation parameters in the preset difference operation formula.
[0088] For example, when the grayscale values of the original image of the target object's surface are concentrated between 90 and 140, i.e., in a scene where the grayscale contrast between the surface defects of the target object and the background is low, the scaling factor can be 2 and the offset can be 100. This application does not limit the magnitude of the scaling factor and offset; they can be determined based on the actual application requirements of the grayscale distribution characteristics of the original image of the target object's surface.
[0089] In this embodiment of the application, by amplifying and shifting the grayscale difference of pixels with the same spatial pixel coordinates in the defect feature enhancement image and the target detection area image, the distinction between low-contrast embossed defects and the background can be further improved, and the grayscale contrast between the defects and the background can be enhanced.
[0090] The following is combined Figure 4 A detailed explanation is provided on a specific implementation method of step S104, which involves detecting defects on the surface of a target object based on a differential image.
[0091] Figure 4 Flowchart of the defect detection method provided in the embodiments of this application Figure 2 .like Figure 4 As shown, a specific implementation of this defect detection method, which detects defects on the surface of a target object based on a differential image, may include the following steps:
[0092] S401, Generate a defect determination image based on the differential image.
[0093] For example, a defect determination image may contain at least one defect line, or it may not contain a defect line.
[0094] Figure 5 This is a schematic diagram of a defect determination image provided in an embodiment of this application. Figure 5 As shown, the solid black lines represent the outlines of the defect lines contained in the defect determination image.
[0095] It is understandable that the defect determination image uses line outlines to represent the concave and convex texture defects.
[0096] S402, Determine whether there are defect lines in the defect judgment image.
[0097] S403, in response to the presence of defect lines in the defect determination image, and the presence of at least one defect line with a length greater than or equal to a preset length threshold, it is determined that there are defects on the surface of the target object that do not meet the preset requirements, and the target object is determined to be unqualified.
[0098] For example, the preset length threshold can be 3mm. This application does not limit the size of the preset length threshold; it can be determined according to actual application requirements.
[0099] For example, the preset requirement is that the size, depth, number, and other parameters of defects on the surface of the target object are within a threshold range that does not affect the performance of the target object (such as strength, sealing, conductivity, etc.). If the parameters of the defects on the surface of the target object exceed this threshold range and affect the performance of the target object, then the defect is determined to not meet the preset requirement.
[0100] S404, in response to the presence of defect lines in the defect determination image, and the length of each defect line being less than a preset length threshold, determine that there are no defects on the surface of the target object that do not meet the preset requirements, and determine that the target object is qualified.
[0101] S405, in response to the absence of defect lines in the defect determination image, determine that there are no defects on the surface of the target object that do not meet the preset requirements, and determine that the target object is qualified.
[0102] In this embodiment, a defect judgment image is generated based on a differential image. When a defect line exists in the defect judgment image, and at least one defect line has a length greater than or equal to a preset length threshold, it is determined that the surface of the target object has a defect that does not meet the preset requirements, and the target object is deemed unqualified. When a defect line exists in the defect judgment image, and the length of each defect line is less than the preset length threshold, or when no defect line exists in the defect judgment image, it is determined that the surface of the target object does not have a defect that does not meet the preset requirements, and the target object is deemed qualified. This achieves rapid, efficient, and automated screening of the target object's quality, and can adapt to the application requirements of industrial batch defect detection.
[0103] It should be noted that any logic that determines whether a target object is qualified based on the absence of defect lines in a defect judgment image, or based on a preset length threshold to determine whether a target object is qualified or unqualified, falls within the scope of this application.
[0104] The following is combined Figure 6 A detailed explanation is provided of a specific implementation method for generating a defect determination image based on the differential image in step S401.
[0105] Figure 6 Flowchart of the defect detection method provided in the embodiments of this application Figure 3 .like Figure 6 As shown, a specific implementation of this defect detection method, which generates a defect determination image based on a differential image, may include the following steps:
[0106] S601 performs Gaussian smoothing on the difference image based on preset Gaussian smoothing parameters to obtain a denoised image.
[0107] For example, the preset Gaussian smoothing parameters can be determined based on the grayscale distribution characteristics of the original image of the target object's surface. Specifically, the preset Gaussian smoothing parameters can be empirically optimal values obtained through repeated adjustments based on the grayscale distribution characteristics of the original image of the target object's surface.
[0108] For example, when the grayscale values of the original image of the target object's surface are concentrated between 90 and 140, i.e., in a scenario where the grayscale contrast between the surface defects and the background is low, the preset Gaussian smoothing parameter (Sigma) can be set to 11.8357. This application embodiment does not limit the value of the preset Gaussian smoothing parameter; it can be determined specifically based on the actual application requirements of the grayscale distribution characteristics of the original image of the target object's surface.
[0109] Understandably, in this low-contrast scene, when the preset Gaussian smoothing parameter is set to 11.8357, it can effectively suppress the subtle noise remaining after frequency domain enhancement, and also avoid excessive smoothing that would blur weak feature defects.
[0110] S602 calculates the line response value of each pixel in the denoised image.
[0111] For example, one possible implementation is as follows: Based on the inherent gray-level distribution pattern of the "middle and sides" of the convex texture defect (e.g., slightly lower gray-level at the depression and slightly higher at the sides), that is, the gray-level difference between the "middle and sides" of the convex texture defect is small but there is a gradient change, for each pixel in the denoised image, based on the gray-level value of the pixel and the gray-level values of its neighboring pixels perpendicular to the main direction of the defect, the absolute value of the sum of the second-order derivatives of the pixel is calculated to obtain the line response value of the pixel. The higher the line response value, the more likely the pixel belongs to the core region of the defect, thus accurately locating the weak feature defect lines.
[0112] S603 generates a defect judgment image based on the line response values of all pixels in the denoised image.
[0113] Optionally, this step may include the following steps:
[0114] S6031 generates a defect response image based on the line response values of all pixels in the denoised image.
[0115] S6032, perform dual threshold filtering on the defect response image to determine the pixel type of each pixel in the defect response image.
[0116] Among them, the pixel types include target defect pixels, candidate defect pixels, and non-defect pixels.
[0117] For example, dual thresholds may include a low threshold and a high threshold. The low and high thresholds can be determined based on the grayscale distribution characteristics of the original image of the target object's surface. Specifically, the low and high thresholds can be empirically optimal values obtained through repeated adjustments based on the grayscale distribution characteristics of the original image of the target object's surface.
[0118] For example, when the grayscale values of the original image of the target object's surface are concentrated between 90 and 140, i.e., in a scenario where the grayscale contrast between the surface defects and the background is low, the low threshold and high threshold values can be 0.022 and 0.055, respectively. This application does not limit the values of the low and high thresholds; they can be determined based on the actual application requirements of the grayscale distribution characteristics of the original image of the target object's surface.
[0119] Understandably, in low-contrast scenes, setting the low threshold to 0.022 and the high threshold to 0.055 can improve the accuracy of capturing defect lines.
[0120] In this step, one possible implementation is as follows: pixels with line response values greater than a high threshold in the defect response image are identified as target defect pixels; pixels with line response values between the high and low thresholds and connected to the target defect pixels are identified as candidate defect pixels; and pixels with line response values less than the low threshold are identified as non-defect pixels.
[0121] Understandably, candidate defect pixels are used to connect discontinuous defects on the surface of the target object.
[0122] S6033 generates defect lines based on the target defect pixels and candidate defect pixels.
[0123] For example, one possible implementation is as follows: the target defect pixel is vectorized to obtain the vectorized line corresponding to the target defect pixel; the vectorized line is further fitted using a Bezier curve fitting algorithm to generate smooth defect contour data; then, based on the neighborhood correlation analysis of the candidate defect pixel, the discontinuous defect line is automatically completed to output a defect line that can clearly show the defect position and shape.
[0124] Understandably, by employing classification logic for target defect pixels and candidate defect pixels, stable and accurate capture of defect lines can be achieved.
[0125] S6034 generates a defect determination image based on defect lines and non-defect pixels.
[0126] In this embodiment, a denoised image is obtained by performing Gaussian smoothing on the difference image based on preset Gaussian smoothing parameters. For each pixel in the denoised image, the line response value of the pixel is calculated. Furthermore, a defect judgment image is generated based on the line response values of all pixels in the denoised image. By adopting a straight line extraction mechanism adapted to low contrast scenes, the defect lines in the defect judgment image are accurately captured.
[0127] Optionally, one possible implementation of step S101, which involves obtaining the target detection region image on the surface of the target object, is to: obtain the original image of the surface of the target object; and perform image cropping on the original image to obtain the target detection region image.
[0128] For example, the original image can be acquired by a camera.
[0129] For example, one possible implementation is to use a camera to acquire the original image of the surface of the target object, and to preprocess the original image (such as image cropping) using a preset region (such as a ROI with a radius of preset pixels), retaining only the core area of the target object to be detected, and completely eliminating the interference of irrelevant areas such as image edges and device background, so as to obtain a target detection area image focused on the core area of the target object to be detected.
[0130] For example, the shape and size of the preset area can be determined based on the outline of the target object. This application embodiment does not limit the shape and size of the preset area, but can be determined according to the actual application requirements.
[0131] In summary, a specific implementation of the defect detection method provided in this application embodiment may include the following steps:
[0132] S1. Obtain the original image of the target object's surface, and crop the original image using a ROI with a radius of 620 pixels to obtain the target detection region image.
[0133] S2, perform a fast Fourier transform on the target detection region image to obtain the frequency domain image corresponding to the target detection region image.
[0134] S3, convolve the frequency domain image with a preset frequency domain Gaussian filter to obtain the convolved frequency domain image.
[0135] The preset frequency domain Gaussian filter has a smoothing coefficient of 311 in both the main direction and the vertical direction.
[0136] S4. Perform inverse fast Fourier transform on the frequency domain image after convolution to obtain the defect feature enhancement image.
[0137] S5 performs differential operations on the defect feature enhancement image and the target detection region image to generate a differential image.
[0138] In the differential operation, the differential operation parameter, i.e., the scaling factor, is set to 2, and the offset is set to 100.
[0139] S6. Based on the preset Gaussian smoothing parameters, the difference image is subjected to Gaussian smoothing to obtain a denoised image. For each pixel in the denoised image, the line response value of the pixel is calculated, and a defect response image is generated based on the line response values of all pixels in the denoised image.
[0140] The preset Gaussian smoothing parameter is set to 11.8357.
[0141] S7. Perform double threshold filtering on the defect response image to determine the pixel type of each pixel in the defect response image, and generate a defect judgment image based on the pixel type.
[0142] Among them, the lower threshold value is 0.022 and the higher threshold value is 0.055.
[0143] S8. When there are defect lines in the defect judgment image and the length of at least one defect line is greater than or equal to the preset length threshold, it is determined that there are defects on the surface of the target object that do not meet the preset requirements, and the target object is determined to be unqualified; when there are defect lines in the defect judgment image and the length of each defect line is less than the preset length threshold, or when there are no defect lines in the defect judgment image, it is determined that there are no defects on the surface of the target object that do not meet the preset requirements, and the target object is determined to be qualified.
[0144] In this embodiment, the specific implementation of each step is similar to that described above, and will not be repeated here.
[0145] In this embodiment, on the one hand, a 620-pixel circular ROI, a frequency domain Gaussian filter with a bidirectional smoothing coefficient of 311, and a preprocessing parameter with a scaling factor of 2 and an offset value of 100 are used in combination to enhance weak feature defects in a targeted manner; on the other hand, a combination of weak feature defect line-lifting parameters with a preset Gaussian smoothing parameter of 11.8357, a low threshold of 0.022, and a high threshold of 0.055 is used to stably capture discontinuous low-contrast defect lines.
[0146] It should be noted that any combination of methods that only changes the numerical value of specific parameters falls within the scope of the embodiments of this application.
[0147] This application embodiment employs an integrated design of "ROI focusing - frequency domain enhancement - differential operation - precise line extraction - feature determination." First, a circular ROI is used to crop the original image of the target object's surface to eliminate background interference. Then, a customized preset frequency domain Gaussian filter is used to suppress noise and enhance weak high-frequency domain defect features. Combined with differential operation with specific parameters, the grayscale difference between the defect and the background is amplified, effectively solving the core pain point of low differentiation between defects and the background in low-contrast, concentrated grayscale scenes, and significantly improving the recognition of weak feature concave-convex texture defects. Then, a linear extraction mechanism with directional optimization parameters and dual-threshold screening logic are used to accurately balance noise suppression and weak feature preservation, achieving stable capture of discontinuous, slight concave-convex texture defects, greatly reducing the risk of missed detection and false detection. Compared with the subjectivity of manual detection and the limitations of ordinary visual algorithms in related technologies, this significantly improves detection reliability. Meanwhile, by adopting an integrated defect detection process, without complex preprocessing or model training steps, the defect judgment logic is simple, significantly improving detection efficiency. It can effectively adapt to the needs of industrial mass production, and the algorithm parameters are optimized for the target scenario, making it highly adaptable to environmental fluctuations and material batch differences. It does not require complex hardware upgrades or a large amount of labeled data, resulting in lower implementation and maintenance costs. Furthermore, it can be adapted to the detection of different types of metal stamping parts by adjusting key parameters, demonstrating outstanding versatility and practicality.
[0148] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0149] Figure 7 This is a schematic diagram of the defect detection device provided in an embodiment of this application. Figure 7 As shown, the defect detection device 70 includes an acquisition module 710, a first processing module 720, a second processing module 730, and a detection module 740.
[0150] The acquisition module 710 is used to acquire the target detection area image on the surface of the target object;
[0151] The first processing module 720 is used to perform frequency domain enhancement processing on the target detection area image to generate a defect feature enhanced image;
[0152] The second processing module 730 is used to perform differential operation processing on the defect feature enhancement image and the target detection area image to generate a differential image;
[0153] The detection module 740 is used to detect defects on the surface of a target object based on the differential image.
[0154] In one possible implementation, the first processing module 720 is specifically used to: perform a fast Fourier transform on the target detection region image to obtain a frequency domain image corresponding to the target detection region image; perform convolution processing on the frequency domain image and a preset frequency domain Gaussian filter to obtain a convolved frequency domain image, wherein the smoothing coefficients of the preset frequency domain Gaussian filter in the principal direction and the vertical direction are determined according to the gray-level distribution characteristics of the original image of the target object surface; and perform an inverse fast Fourier transform on the convolved frequency domain image to obtain a defect feature enhancement image.
[0155] In one possible implementation, the second processing module 730 is specifically used to: for each first pixel in the defect feature enhancement image, select a second pixel in the target detection region image corresponding to the spatial pixel coordinates of the first pixel, and calculate the gray value of a third pixel in the difference image at the corresponding spatial pixel coordinates based on a preset difference operation formula, the gray value of the first pixel, and the gray value of the corresponding second pixel, wherein the difference operation parameters in the preset difference operation formula are determined according to the gray distribution characteristics of the original image of the target object surface; and generate a difference image based on the gray values of all third pixels.
[0156] In one possible implementation, the detection module 740 is specifically used to: generate a defect judgment image based on the differential image; determine whether there are defect lines in the defect judgment image; in response to the presence of defect lines in the defect judgment image, and at least one defect line having a length greater than or equal to a preset length threshold, determine that the surface of the target object has a defect that does not meet the preset requirements, and determine that the target object is unqualified; in response to the presence of defect lines in the defect judgment image, and each defect line having a length less than the preset length threshold, determine that the surface of the target object does not have a defect that does not meet the preset requirements, and determine that the target object is qualified; in response to the absence of defect lines in the defect judgment image, determine that the surface of the target object does not have a defect that does not meet the preset requirements, and determine that the target object is qualified.
[0157] In one possible implementation, the detection module 740 is further configured to: perform Gaussian smoothing on the difference image based on preset Gaussian smoothing parameters to obtain a denoised image; calculate the line response value of each pixel in the denoised image; and generate a defect judgment image based on the line response values of all pixels in the denoised image.
[0158] In one possible implementation, the detection module 740 is further configured to: generate a defect response image based on the line response values of all pixels in the denoised image; perform dual threshold filtering on the defect response image to determine the pixel type of each pixel in the defect response image, wherein the pixel type includes target defect pixels, candidate defect pixels, and non-defect pixels; generate defect lines based on the target defect pixels and candidate defect pixels; and generate a defect determination image based on the defect lines and non-defect pixels.
[0159] In one possible implementation, the acquisition module 710 is specifically used to: acquire the original image of the surface of the target object; and perform image cropping processing on the original image to obtain the target detection region image.
[0160] The defect detection device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.
[0161] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 8 As shown, the electronic device 80 provided in this embodiment includes at least one processor 801 and a memory 802. Optionally, the electronic device 80 further includes a communication component 803. The processor 801, memory 802, and communication component 803 are connected via a bus 804.
[0162] In a specific implementation, at least one processor 801 executes computer execution instructions stored in memory 802, causing at least one processor 801 to perform the above-described method.
[0163] The specific implementation process of processor 501 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0164] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0165] The memory may include random access memory (RAM) and non-volatile memory (NVM), such as at least one disk storage device.
[0166] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0167] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0168] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.
[0169] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0170] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.
[0171] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0172] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0173] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0174] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0175] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0176] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. A defect detection method characterized by, include: Acquire an image of the target detection area on the surface of the target object; The target detection area image is subjected to frequency domain enhancement processing to generate a defect feature enhanced image; The defect feature enhancement image and the target detection region image are subjected to differential operation processing to generate a differential image; Based on the differential image, defects on the surface of the target object are detected.
2. The defect detection method according to claim 1, wherein The step of performing frequency domain enhancement processing on the target detection region image to generate a defect feature enhanced image includes: Perform a Fast Fourier Transform on the target detection region image to obtain the frequency domain image corresponding to the target detection region image; The frequency domain image is convolved with a preset frequency domain Gaussian filter to obtain a convolved frequency domain image. The smoothing coefficients of the preset frequency domain Gaussian filter in the main direction and vertical direction are determined based on the gray-level distribution characteristics of the original image of the target object surface. The inverse fast Fourier transform is performed on the convolutional frequency domain image to obtain the defect feature enhancement image.
3. The defect detection method according to claim 1, characterized in that, The step of performing a difference operation on the enhanced image of the defect features and the image of the target detection region to generate a difference image includes: For each first pixel in the defect feature enhancement image, a second pixel corresponding to the spatial pixel coordinates of the first pixel is selected in the target detection area image. Based on a preset difference operation formula, the gray value of the first pixel and the gray value of the corresponding second pixel, the gray value of the third pixel in the difference image at the corresponding spatial pixel coordinates is calculated. The difference operation parameters in the preset difference operation formula are determined according to the gray distribution characteristics of the original image of the target object surface. The difference image is generated based on the grayscale values of all third pixels.
4. The defect detection method according to any one of claims 1 to 3, characterized in that, The step of detecting defects on the surface of the target object based on the differential image includes: Based on the difference image, a defect determination image is generated; Determine whether defect lines exist in the defect determination image; In response to the presence of defect lines in the defect determination image, and the fact that at least one defect line has a length greater than or equal to a preset length threshold, it is determined that the surface of the target object has a defect that does not meet the preset requirements, and the target object is determined to be unqualified. In response to the presence of defect lines in the defect determination image, and the length of each defect line being less than the preset length threshold, it is determined that there are no defects on the surface of the target object that do not meet the preset requirements, and the target object is determined to be qualified. In response to the absence of defect lines in the defect determination image, it is determined that the surface of the target object does not have any defects that do not meet the preset requirements, and the target object is determined to be qualified.
5. The defect detection method according to claim 4, characterized in that, The step of generating a defect determination image based on the difference image includes: Based on preset Gaussian smoothing parameters, the difference image is subjected to Gaussian smoothing processing to obtain a denoised image; For each pixel in the denoised image, calculate the line response value of that pixel; The defect determination image is generated based on the line response values of all pixels in the denoised image.
6. The defect detection method according to claim 5, characterized in that, The step of generating the defect determination image based on the line response values of all pixels in the denoised image includes: A defect response image is generated based on the line response values of all pixels in the denoised image; The defect response image is subjected to dual threshold filtering to determine the pixel type of each pixel in the defect response image. The pixel type includes target defect pixels, candidate defect pixels, and non-defect pixels. Based on the target defect pixels and the candidate defect pixels, generate defect lines; The defect determination image is generated based on the defective lines and the non-defective pixels.
7. The defect detection method according to any one of claims 1 to 3, characterized in that, The process of acquiring the target detection region image on the surface of the target object includes: Obtain the original image of the surface of the target object; The original image is cropped to obtain the target detection region image.
8. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the defect detection method as described in any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the defect detection method as described in any one of claims 1 to 7.
10. A computer program product, characterized in that, include: A computer program, which, when executed by a processor, implements the defect detection method as described in any one of claims 1 to 7.