Key defect detection method, device, computer equipment and storage medium
By acquiring key images under different light sources in a multi-color key material scene, generating target defect mask images and performing color space conversion, the problem of inaccurate key defect detection in the prior art is solved, and higher detection accuracy and accuracy are achieved.
Patent Information
- Application Number
- CN202411412579.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-11
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2044-10-11
AI Technical Summary
In the scenario of multi-color button materials, it is difficult for the prior art to accurately identify button defects through simple collection rules, especially when the background area has a great impact.
By acquiring the button images to be detected under different light sources, generating the target defect mask image, and color space conversion is performed to improve the integrity and discrimination of the defect profile area, thereby achieving more accurate button defect detection.
It improves the accuracy of key defect detection, effectively distinguishes defective parts from background parts, reduces the misjudgment rate, and enhances the accuracy of detection results.
Smart Images

Figure CN118918111B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a key defect detection method, device, computer equipment and storage medium. Background Art
[0002] With the widespread application of various products, product appearance defects have become one of the important indicators for evaluating product quality. Therefore, defect detection of product appearance has become an important process of product quality inspection.
[0003] In the process of defect detection on product appearance, different acceptance rules are usually set for defect detection. However, in the scenario of multi-color button materials, only simple acceptance rules are used to detect defects on product button images, such as gray value filtering. However, this method is greatly affected by the background area, resulting in a decrease in the accuracy of the button defect detection results and an inability to accurately identify button defects. Summary of the invention
[0004] Based on this, it is necessary to provide a key defect detection method, device, computer equipment and storage medium to address the above technical problems, which can improve the accuracy of key defect detection.
[0005] In a first aspect, the present application provides a key defect detection method, comprising:
[0006] Acquire an image of a key to be detected under at least one light source, and generate a target defect mask image according to the image of the key to be detected under each light source; the target defect mask image includes at least one defect contour area;
[0007] According to each defect contour area in the target defect mask image, based on the key image to be detected under each light source, at least one defect contour area image to be detected is generated;
[0008] Performing color space conversion on each image of the defect contour area to be detected to obtain a grayscale image of each image of the defect contour area to be detected under a brightness channel;
[0009] For any defect contour area image to be detected, key defect detection is performed based on its corresponding grayscale image and key defect type to obtain the key defect detection result.
[0010] In a second aspect, the present application provides a key defect detection device, comprising:
[0011] An image acquisition module, used to acquire an image of a key to be detected under at least one light source, and generate a target defect mask image according to the image of the key to be detected under each light source; the target defect mask image includes at least one defect contour area;
[0012] An image generation module, configured to generate at least one image of a defect contour region to be detected based on each defect contour region in the target defect mask image and based on the image of the key to be detected under each light source;
[0013] A space conversion module is used to perform color space conversion on each image of the defect contour area to be detected, so as to obtain a grayscale image of each image of the defect contour area to be detected under a brightness channel;
[0014] The defect detection module is used to perform key defect detection on any defect contour area image to be detected based on its corresponding grayscale image and key defect type to obtain a key defect detection result.
[0015] In a third aspect, the present application provides a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above method when executing the computer program.
[0016] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above method when executed by a processor.
[0017] In a fifth aspect, the present application provides a computer program product, which includes a computer program, and the computer program implements the steps in the above method when executed by a processor.
[0018] Compared with the prior art, the above-mentioned key defect detection method, device, computer equipment and storage medium take into account the image characteristics of key images taken under different light sources, improve the integrity and comprehensiveness of the defect contour area in the target defect mask image, and effectively increase the distinction between the defective part and the background part by performing color space conversion on the image of the defect contour area to be detected, so as to better distinguish subtle defects from background differences, thereby improving the accuracy of key defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 A diagram of an application environment of a key defect detection method provided in an embodiment of the present application;
[0020] Figure 2 A schematic diagram of a key defect detection method provided in an embodiment of the present application;
[0021] Figure 3 A schematic diagram of a method for generating a merged defect mask image provided in an embodiment of the present application;
[0022] Figure 4 A schematic diagram of a method for generating a target defect mask image provided in an embodiment of the present application;
[0023] Figure 5 A schematic diagram of a method for expanding a defect contour area provided in an embodiment of the present application;
[0024] Figure 6 A schematic diagram of a flow chart of another key defect detection method provided in an embodiment of the present application;
[0025] Figure 7 A structural block diagram of a key defect detection device provided in an embodiment of the present application;
[0026] Figure 8 An internal structure diagram of a computer device provided in an embodiment of the present application;
[0027] Fig. 9 An internal structure diagram of another computer device provided in an embodiment of the present application;
[0028] Fig.10 An internal structure diagram of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0030] The key defect detection method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through a communication network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented with an independent server or a server cluster consisting of multiple servers.
[0031] like Figure 2 As shown, the embodiment of the present application provides a key defect detection method, which is applied to Figure 1 The terminal 102 or the server 104 in the example is used for explanation. It is understandable that the computer device may include at least one of the terminal and the server. The method comprises the following steps:
[0032] S202, acquiring an image of a key to be detected under at least one light source, and generating a target defect mask image according to the image of the key to be detected under each light source; the target defect mask image includes at least one defect contour area.
[0033] S204 , generating at least one image of a defect contour region to be detected according to each defect contour region in the target defect mask image and based on the image of the key to be detected under each light source.
[0034] S206 , performing color space conversion on each image of the defect contour region to be detected, to obtain a grayscale image of each image of the defect contour region to be detected in a brightness channel.
[0035] S208 . For any defect contour area image to be detected, perform key defect detection based on its corresponding grayscale image and key defect type to obtain a key defect detection result.
[0036] Among them, light sources can include natural light sources, artificial light sources, special light sources, and industrial test-specific light sources, etc. For example, natural light sources can include sunlight and moonlight, etc.; artificial light sources can include incandescent light, fluorescent light, and LED (Light Emitting Diode) light, etc.; special light sources can include lasers, etc.; industrial test-specific light sources can include fiber lasers, ultraviolet light sources, high-intensity white light, and ring light sources, etc.
[0037] The key image to be inspected may be an image to be inspected for key defects, and may be obtained by using an image acquisition device to acquire the image of the key to be inspected. It is understandable that due to the influence of different light sources, the clarity, contrast, image details, and noise of the key image to be inspected may vary to some extent.
[0038] For example, if it is known that there are three different defects in the key to be inspected, namely defect a, defect b and defect c; under light source A, the key to be inspected is imaged, and the area outline of defect a in the obtained image of the key to be inspected is relatively clear, but the area outlines of defect b and defect c are relatively fuzzy; under light source B, the key to be inspected is imaged, and the area outline of defect b in the obtained image of the key to be inspected is relatively clear, but the area outlines of defect a and defect c are relatively fuzzy; under light source C, the key to be inspected is imaged, and the area outline of defect c in the obtained image of the key to be inspected is relatively clear, but the area outlines of defect a and defect b are relatively fuzzy. Therefore, by acquiring images of the key to be inspected under different light sources, all defects of the key to be inspected can be more comprehensively collected, effectively avoiding the occurrence of defect detection omissions.
[0039] For any key image to be detected, defect detection is performed on the key image to be detected to obtain an initial defect mask image corresponding to the key image to be detected. The defect detection method can be based on a preset image segmentation algorithm or image segmentation model to perform defect contour recognition or detection on the key image to be detected to obtain an initial defect mask image output by the model or calculated by the algorithm. The image segmentation algorithm can be a threshold segmentation algorithm, an edge detection algorithm, or a region generation algorithm, etc.; the image segmentation model can be obtained by relevant technical personnel using a key image sample data set to train a preset network model. For example, the network model can be a convolutional neural network or Mask R-CNN (Mask Region-based Convolutional Neural Network, mask region convolutional neural network), etc. The initial defect mask image can be a binary mask image or a grayscale mask image.
[0040] According to the initial defect mask images under each light source, the defect contour regions are merged to obtain the target defect mask image. It should be noted that due to the different illumination characteristics of different light sources, the defect contour regions in the initial defect mask images obtained under different light sources may be the same or different. Therefore, the defect contour regions of the initial defect mask images under each light source are merged to obtain the target defect mask image containing the complete defect contour region.
[0041] In some embodiments, the initial defect mask image under light source A includes defect contour area a, the initial defect mask image under light source B includes defect contour area b, and the initial defect mask image under light source C includes defect contour area b and defect contour area c. The defect contour areas under light sources A, B, and C are merged to obtain a target defect mask image. The target defect mask image includes defect contour area a, defect contour area b, and defect contour area c.
[0042] In order to further improve the generation accuracy and completeness of the defect contour area in the target defect mask image, in some embodiments, the target defect mask image is generated according to the key image to be detected under each light source, including:
[0043] Using at least one defect detection method to perform defect detection on the key image to be detected under each light source, and obtaining defect contour mask images corresponding to each defect detection method under each light source;
[0044] For any light source, pixel points of defect contour areas in defect contour mask images corresponding to each defect detection method under the light source are merged to obtain a merged defect mask image under the light source;
[0045] The defect contour areas in the combined defect mask images under each light source are regionally merged to obtain a target defect mask image.
[0046] The defect detection method may include different image segmentation algorithms, different image segmentation models or different mask image generation algorithms for defect contour extraction, such as edge detection algorithm, graph cut algorithm or image segmentation model.
[0047] For any light source, at least one defect detection method is used to perform defect detection on the key image to be detected under the light source, and defect contour mask images corresponding to each defect detection method under the light source are obtained. It should be noted that for the key image to be detected under any light source, the defect contour mask images obtained after defect detection on the key image to be detected using different defect detection methods may not be exactly the same, and there are certain differences.
[0048] like Figure 3 A schematic diagram of a method for generating a merged defect mask image is shown. Under a certain light source, three defect detection methods are used, namely defect detection method A, defect detection method B and defect detection method C, to perform defect detection on the key image to be detected under the light source, and obtain defect contour mask images corresponding to each defect detection method under the light source. The pixel points in the defect contour area of the three defect contour mask images under the three defect detection methods are merged to obtain a merged defect mask image. Among them, the black area in the dotted box is the defect contour area.
[0049] like Figure 4 A schematic diagram of a method for generating a target defect mask image is shown. The defect contour area of the merged mask images corresponding to light source A, light source B and light source C are merged to obtain a target defect mask image containing a complete defect contour area.
[0050] The above technical solution reduces the contour area detection error and improves the accuracy of determining the defect contour area by merging pixels of defect contour mask images of different defect detection methods under any light source; and improves the integrity of the defect contour area in the target defect mask image by performing regional merging on the merged defect mask images under each light source, thereby improving the accurate identification of subsequent defect detection.
[0051] The target defect mask image is a grayscale image or a binary image, and the key image to be detected is a color image, specifically an image in RGB (Red, Green, Blue) color mode. Since the target defect mask image is generated based on the key image to be detected, the two have the same size but different color modes.
[0052] Since the image characteristics of the key image to be detected under each light source are different, a key image to be detected can be randomly selected from each light source, and the area matching each defect contour area in the target defect mask image, that is, the area with the same pixel coordinates, is selected from the key image to be detected. The images of each area selected from the key image to be detected are used as the defect contour area images to be detected.
[0053] Due to the material characteristics of the key itself, its texture morphology is less distinguishable from the background part. In order to better distinguish the defect part from the background part, in some embodiments, according to each defect contour area in the target defect mask image, based on the key image to be detected under each light source, at least one defect contour area image to be detected is generated, including:
[0054] Selecting a target key image to be detected from the key images to be detected under various light sources;
[0055] For any defect contour region in the target defect mask image, based on a preset expansion radius, the defect contour region is expanded to obtain an expanded contour region;
[0056] According to each expanded contour area in the target defect mask image, an image of a defect contour area to be detected that matches each expanded contour area is extracted from the target key image to be detected, so as to obtain at least one image of a defect contour area to be detected.
[0057] The target key image to be detected may be selected by randomly selecting from the key images to be detected under various light sources. To improve the selection accuracy, the light source corresponding to the combined defect mask image containing the largest number of defect contour areas may be selected as the target light source based on the combined defect mask images under various light sources, and the key image to be detected of the target light source may be determined as the target key image to be detected.
[0058] It should be noted that the more areas containing defect contour areas are, the higher or clearer the contrast of the defective pixel acquisition of the key image to be detected obtained under the light source is; and the fewer areas containing defect contour areas are, the lower or blurrier the contrast of the defective pixel acquisition of the key image to be detected obtained under the light source is.
[0059] The expansion radius may be pre-set by relevant technical personnel according to actual needs. For example, the expansion radius may be 5 pixels.
[0060] like Figure 5A schematic diagram of a method for expanding a defect contour region is shown. Based on a preset expansion radius, the defect contour region is expanded to obtain an expanded contour region. From the target key image to be detected, an image of the defect contour region to be detected that matches the coordinates of the regional pixel points of each expanded contour region is extracted.
[0061] The above technical solution improves the accuracy of selecting the target key image to be detected by considering the number of defect contour areas that can be identified or detected under different light sources in the process of selecting the target key image to be detected, thereby facilitating the selection of matching defect contour area images to be detected from the target key image to be detected. By expanding the area of each defect contour area, it is easier to better distinguish the defect texture part from the background part, and then facilitate more accurate and effective identification of defects in the subsequent process.
[0062] Convert each defect contour area image to be detected from the RGB color space to the LAB (Lightness, AChannel, B Channel; brightness, green-red channel, blue-yellow channel) color space, and obtain the grayscale image of each defect contour area image to be detected in the brightness channel (L channel in the LAB color space). The pixel value range of the grayscale image in the brightness channel is 0-100.
[0063] Among them, the key defect types may include dirt defects, foreign body defects, scratch defects, bump defects and pressure defects, etc. Different key defect types may correspond to different defect detection rules. For example, for dirt defects, it can perform defect detection based on the grayscale mean; for scratch defects, it can perform defect detection based on the defect length.
[0064] Exemplarily, if the key defect type corresponding to the image of the defect contour area to be detected meets the preset judgment rule based on grayscale value characteristics, the grayscale value of each pixel in the image of the defect contour area to be detected is determined. Among them, the judgment rule based on grayscale value characteristics can specifically be that the key defect type needs to be judged based on the image grayscale value. Specifically, the grayscale average value corresponding to the grayscale value of each pixel is determined, and it is judged whether the grayscale average value meets the grayscale value range interval given in the judgment rule; if it meets, the defect is retained; if not, the defect is filtered. The retained defects can be further processed or verified later.
[0065] If the key defect type corresponding to the image of the defect contour area to be detected does not meet the preset judgment rules based on grayscale value characteristics, defect detection can be performed on the image of the defect contour area to be detected based on judgment rules matching the key defect type, such as length judgment rules or area judgment rules, to obtain the key defect detection result.
[0066] It can be seen that in the embodiment of the present application, a target defect mask image is generated by taking into account the image characteristics of the key images taken under different light sources, thereby improving the integrity and comprehensiveness of the defect contour area in the target defect mask image; by performing color space conversion on the image of the defect contour area to be detected, the distinction between the defective part and the background part is effectively increased, thereby better distinguishing subtle defects from background differences, and thus performing key defect detection based on the converted grayscale image, thereby improving the accuracy of key defect detection.
[0067] Figure 6 The flowchart of another key defect detection method provided in the embodiment of the present application is shown in FIG. This embodiment is further optimized on the basis of the above embodiment. Figure 6 As shown, the method includes:
[0068] S402, acquiring an image of a key to be detected under at least one light source, and generating a target defect mask image according to the image of the key to be detected under each light source; the target defect mask image includes at least one defect contour area.
[0069] S404: Generate at least one image of a defect contour region to be detected according to each defect contour region in the target defect mask image and based on the image of the key to be detected under each light source.
[0070] S406 , performing color space conversion on each image of the defect contour region to be detected, to obtain a grayscale image of each image of the defect contour region to be detected in a brightness channel.
[0071] S408 , determining the grayscale mean and grayscale difference of each grayscale image according to each pixel point in the grayscale image of each defect contour area image to be detected.
[0072] S410. Determine a target defect detection method corresponding to each of the defect contour area images to be detected according to the key defect type of each of the defect contour area images to be detected.
[0073] S412. For any defect contour area image to be detected, key defect detection is performed according to the grayscale mean, grayscale difference and target defect detection method of the corresponding grayscale image to obtain a key defect detection result.
[0074] The grayscale mean may be the average value between each pixel in the grayscale image; and the grayscale difference may be the difference between the pixel with the maximum value and the pixel with the minimum value in the grayscale image.
[0075] It is understandable that, since different button defects have different defect characteristics, different button defect types may correspond to the same or different target defect detection methods. For example, for a dirt defect, the target defect detection method may be to detect whether its grayscale mean is greater than 100 and whether its grayscale difference is greater than 70; for a foreign body defect, the target defect detection method may be to detect whether its grayscale mean is greater than 150 and whether its grayscale difference is greater than 50.
[0076] According to the grayscale mean and grayscale difference of the grayscale image, based on the corresponding target defect detection method, the key defect detection is performed on the image of the defect contour area to be detected, and the defect detection result is obtained. For example, if the grayscale mean of the grayscale image is 90, the grayscale difference is 60, and the target defect detection method is that the grayscale mean is greater than 100 and the grayscale difference is greater than 70. After comparison, the grayscale difference and grayscale mean of the grayscale image do not meet the detection conditions corresponding to the target defect detection method. Therefore, the key defect corresponding to the grayscale image is defect filtered. If the grayscale mean of the grayscale image is 110, the grayscale difference is 80, and the target defect detection method is that the grayscale mean is greater than 100 and the grayscale difference is greater than 70. After comparison, the grayscale difference and grayscale mean of the grayscale image meet the detection conditions corresponding to the target defect detection method. Therefore, the key defect corresponding to the grayscale image is defect retained for further processing or detection of the key defect.
[0077] The above technical solution determines the grayscale mean and grayscale difference of the defect contour area image to be detected, and based on the corresponding target trap detection method, performs key defect detection on the defect contour area image to be detected. In the defect detection process, the differences between different key defects are fully considered. At the same time, both the grayscale mean and the grayscale difference are considered, and the key defect analysis is performed from multiple dimensions and angles, thereby improving the accuracy of key defect detection.
[0078] In order to reduce the impact of the background on defect detection and thus improve the accuracy of key defect detection, before calculating the grayscale mean and grayscale difference of the grayscale image, the grayscale image can be filtered for abnormal pixels to reduce the impact of abnormal pixels in the background on the calculation results.
[0079] In some embodiments, before determining the grayscale mean and grayscale difference of each grayscale image according to each pixel point in the grayscale image of each defect contour area image to be detected, the method further includes:
[0080] For any defect contour area image to be detected, determine the pixel filtering percentage according to the corresponding key defect type;
[0081] According to the pixel filtering percentage, pixel filtering is performed on the pixel points in the corresponding grayscale image to obtain a filtered grayscale image of the defect contour area to be detected.
[0082] The pixel filtering percentage may be preset by relevant technical personnel, for example, the pixel filtering percentage may be set to 5%.
[0083] Exemplarily, for any grayscale image of a defect contour area image to be detected, the pixels in the grayscale image can be sorted, and the 5% of pixels with higher values and the 5% of pixels with lower values in the sorting result are selected for pixel filtering to obtain a filtered grayscale image of the defect contour area image to be detected.
[0084] The above technical solution reduces the influence of abnormal pixels in the background part on the calculation results by pre-filtering abnormal pixels in the suspected background part, thereby improving the subsequent calculation accuracy of the grayscale mean and grayscale difference of the grayscale image, and further improving the accuracy of subsequent key defect detection results.
[0085] In order to further improve the accuracy of grayscale difference calculation of grayscale images, in some embodiments, according to each pixel point in the grayscale image of each defect contour area image to be detected, the grayscale mean and grayscale difference of each grayscale image are determined respectively, including:
[0086] Step a1: determine the grayscale mean of each grayscale image according to each pixel point in the grayscale image of each defect contour area image to be detected.
[0087] The pixel average value between each pixel point is determined as the grayscale mean.
[0088] Step a21: for any grayscale image, determine a number of first pixel points that meet the high pixel threshold judgment condition and a number of second pixel points that meet the low pixel threshold judgment condition in the grayscale image.
[0089] Among them, the high pixel threshold judgment condition and the low pixel threshold judgment condition can be pre-set by relevant technical personnel according to actual needs. The high pixel threshold judgment condition can be the first 5% with higher pixel values; the low pixel threshold judgment condition can be the last 5% with lower pixel values.
[0090] The pixel points in the grayscale image are numerically sorted to obtain a numerical sorting result, and a plurality of first pixel points that meet a high pixel point threshold judgment condition are selected from the numerical sorting result, and a plurality of second pixel points that meet a low pixel point threshold judgment condition are selected.
[0091] Step a22, respectively determine the first pixel means of a plurality of first pixel points, and determine the second pixel means of a plurality of second pixel points.
[0092] The numerical mean of a plurality of first pixel points is determined as the first pixel mean; and the numerical mean of a plurality of second pixel points is determined as the second pixel mean.
[0093] Step a23: Determine the grayscale difference of each grayscale image according to the first pixel mean and the second pixel mean of each grayscale image.
[0094] The mean difference between the first pixel mean and the second pixel mean is determined as the grayscale difference.
[0095] The above technical solution determines the pixels with larger pixel values and the pixels with smaller pixel values that meet the pixel threshold judgment conditions, and determines the corresponding pixel means respectively; the mean difference between the two pixel means is determined as the grayscale difference, and the fault tolerance between the pixel values is taken into account in the calculation process of the grayscale difference, instead of directly taking the difference between the maximum pixel value and the minimum pixel value as the grayscale difference, which further reduces the influence of abnormal pixel values and improves the calculation accuracy of the grayscale mean of the grayscale image.
[0096] It should be noted that based on the differences in the key defects themselves, different key defects correspond to different defect detection methods, and different defect detection methods, in addition to defect detection based on grayscale characteristics, can also include defect detection based on area characteristics and defect detection based on length and width characteristics.
[0097] In some embodiments, for any defect contour area image to be detected, key defect detection is performed according to the grayscale mean, grayscale difference and target defect detection method of the grayscale image respectively corresponding thereto, and a key defect detection result is obtained, including:
[0098] Step b1: for any defect contour area image to be detected, based on the grayscale mean threshold and grayscale difference threshold of the grayscale defect detection method in the corresponding target defect detection method, perform a first defect detection on the corresponding grayscale image to obtain a first defect detection result.
[0099] Exemplarily, the grayscale mean of the grayscale image of the defect contour area image to be detected is compared with the grayscale mean threshold, and the grayscale difference of the grayscale image is compared with the grayscale difference threshold to determine whether the threshold judgment condition is met; if both the grayscale difference and the grayscale mean meet the threshold judgment condition, the first defect detection of the grayscale image passes; if the grayscale difference and / or the grayscale mean do not meet the threshold judgment condition, the first defect detection of the grayscale image fails.
[0100] For example, the grayscale difference of a grayscale image is 70, the grayscale mean is 120, the grayscale difference threshold is 60, and the grayscale mean threshold is 110. Then the grayscale difference is greater than the grayscale difference threshold, and the grayscale difference meets the threshold judgment condition; and the grayscale mean is greater than the grayscale mean threshold, and the grayscale mean meets the threshold judgment condition.
[0101] Step b21: If there is an area defect detection method in the corresponding target defect detection method, a second defect detection is performed on the corresponding grayscale image based on the area threshold of the area defect detection method to obtain a second defect detection result.
[0102] Exemplarily, if there is an area defect detection method in the target defect detection method of the grayscale image, the defect contour area corresponding to the grayscale image is determined, and the defect contour area is compared with the area threshold. If the defect contour area is larger than the area threshold, the second defect detection of the grayscale image passes; if the defect contour area is not larger than the area threshold, the second defect detection of the grayscale image fails.
[0103] In some embodiments, if there is no area defect detection method in the target defect detection method of the grayscale image, there is no need to perform defect detection based on area characteristics.
[0104] Step b22: If the corresponding target defect detection method includes a length and width defect detection method, a third defect detection is performed on the corresponding grayscale image based on the length threshold and width threshold of the length and width defect detection method to obtain a third defect detection result.
[0105] If there is a length and width defect detection method in the target defect detection method of the grayscale image, the length and width of the defect contour corresponding to the grayscale image are determined, and the defect contour length is compared with the length threshold, and the defect contour width is compared with the width threshold. If the defect contour width is greater than the width threshold and the defect contour length is greater than the length threshold, the third defect detection of the grayscale image passes; if the defect contour width is not greater than the width threshold and / or the defect contour length is not greater than the length threshold, the third defect detection of the grayscale image fails.
[0106] In some embodiments, if there is no length-width defect detection method in the target defect detection method of the grayscale image, there is no need to perform defect detection based on length-width characteristics.
[0107] Step b3: determine the key defect detection result based on the first defect detection result, the second defect detection result and the third defect detection result.
[0108] If the first defect detection result, the second defect detection result, and the third defect detection result of the grayscale image are all passed, the key defect detection result is passed, and the defect contour area corresponding to the grayscale image is retained. If any of the first defect detection result, the second defect detection result, and the third defect detection result of the grayscale image is failed, the key defect detection result is failed, and the defect contour area corresponding to the grayscale image is removed.
[0109] The above technical solution combines the defect characteristics of different key defects and comprehensively considers defect detection in different dimensions such as grayscale defect detection method, area defect detection method and length and width defect detection method. The multi-dimensional defect detection method can capture defects that cannot be accurately identified in a single dimension, reduce the missed detection rate, and improve the accuracy and reliability of key defect detection.
[0110] It should be understood that, although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indications of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0111] Based on the same inventive concept, the embodiment of the present application also provides a key defect detection device. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more key defect detection device embodiments provided below can refer to the limitations of the key defect detection method above, and will not be repeated here.
[0112] like Figure 7 As shown, the embodiment of the present application provides a key defect detection device 700, comprising:
[0113] The image acquisition module 702 is used to acquire an image of a key to be detected under at least one light source, and generate a target defect mask image according to the image of the key to be detected under each light source; the target defect mask image includes at least one defect contour area;
[0114] The image generation module 704 is used to generate at least one image of a defect contour area to be detected based on each defect contour area in the target defect mask image and the key image to be detected under each light source;
[0115] The space conversion module 706 is used to perform color space conversion on each image of the defect contour area to be detected, so as to obtain a grayscale image of each image of the defect contour area to be detected under a brightness channel;
[0116] The defect detection module 708 is used to perform key defect detection on any defect contour area image to be detected based on its corresponding grayscale image and key defect type to obtain a key defect detection result.
[0117] In some embodiments, in terms of generating a target defect mask image according to the key image to be detected under each light source, the image acquisition module 702 is specifically used to:
[0118] Using at least one defect detection method to perform defect detection on the key image to be detected under each light source, and obtaining defect contour mask images corresponding to each defect detection method under each light source;
[0119] For any light source, pixel points of defect contour areas in defect contour mask images corresponding to each defect detection method under the light source are merged to obtain a merged defect mask image under the light source;
[0120] The defect contour areas in the combined defect mask images under each light source are regionally merged to obtain a target defect mask image.
[0121] In some embodiments, in terms of generating at least one image of a defect contour area to be detected based on each defect contour area in the target defect mask image and based on the key image to be detected under each light source, the image generating module 704 is specifically used to:
[0122] Selecting a target key image to be detected from the key images to be detected under various light sources;
[0123] For any defect contour region in the target defect mask image, based on a preset expansion radius, the defect contour region is expanded to obtain an expanded contour region;
[0124] According to each expanded contour area in the target defect mask image, an image of a defect contour area to be detected that matches each expanded contour area is extracted from the target key image to be detected, so as to obtain at least one image of a defect contour area to be detected.
[0125] In some embodiments, in performing key defect detection on any defect contour area image to be detected based on the grayscale image and key defect type respectively corresponding thereto to obtain a key defect detection result, the defect detection module 708 is specifically used to:
[0126] According to each pixel point in the grayscale image of each defect contour area image to be detected, the grayscale mean value and grayscale difference value of each grayscale image are determined respectively;
[0127] According to the key defect type of each defect contour area image to be detected, determine the target defect detection method corresponding to each defect contour area image to be detected;
[0128] For any defect contour area image to be detected, key defect detection is performed according to the grayscale mean, grayscale difference and target defect detection method of the corresponding grayscale image to obtain the key defect detection result.
[0129] In some embodiments, in terms of determining the grayscale mean and grayscale difference of each grayscale image according to each pixel point in the grayscale image of each defect contour area image to be detected, the defect detection module 708 is specifically used to:
[0130] Determine the grayscale mean of each grayscale image according to each pixel point in the grayscale image of each defect contour area image to be detected; and
[0131] For any grayscale image, a plurality of first pixel points satisfying a high pixel point threshold judgment condition and a plurality of second pixel points satisfying a low pixel point threshold judgment condition in the grayscale image are respectively determined;
[0132] Determine first pixel means of a plurality of first pixel points, and determine second pixel means of a plurality of second pixel points;
[0133] The grayscale difference of each grayscale image is determined according to the first pixel mean and the second pixel mean of each grayscale image.
[0134] In some embodiments, for any defect contour area image to be detected, key defect detection is performed according to the grayscale mean, grayscale difference and target defect detection method of the grayscale image respectively corresponding thereto to obtain the key defect detection result, the defect detection module 708 is specifically used to:
[0135] For any defect contour area image to be detected, based on the grayscale mean threshold and grayscale difference threshold of the grayscale defect detection method in the corresponding target defect detection method, a first defect detection is performed on the corresponding grayscale image to obtain a first defect detection result;
[0136] If there is an area defect detection method in the corresponding target defect detection method, a second defect detection is performed on the corresponding grayscale image based on the area threshold of the area defect detection method to obtain a second defect detection result;
[0137] If the corresponding target defect detection method includes a length and width defect detection method, a third defect detection is performed on the corresponding grayscale image based on the length threshold and the width threshold of the length and width defect detection method to obtain a third defect detection result;
[0138] A key defect detection result is determined according to the first defect detection result, the second defect detection result and the third defect detection result.
[0139] In some embodiments, the apparatus further includes an image filtering module, the image filtering module being configured to:
[0140] For any defect contour area image to be detected, determine the pixel filtering percentage according to the corresponding key defect type;
[0141] According to the pixel filtering percentage, pixel filtering is performed on the pixel points in the corresponding grayscale image to obtain a filtered grayscale image of the defect contour area to be detected.
[0142] Each module in the above-mentioned key defect detection device can be implemented in whole or in part by software, hardware or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0143] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 8 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data related to the key defect detection method. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in the above-mentioned key defect detection method are implemented.
[0144] In some embodiments, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig. 9As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be realized through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the steps in the above-mentioned key defect detection method are implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen; the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0145] Those skilled in the art will understand that Figure 8 or Fig. 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0146] In some embodiments, a computer device is provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps in the above method embodiments are implemented.
[0147] In some embodiments, Fig.10 The figure shows an internal structure diagram of a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0148] In some embodiments, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0149] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0150] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0151] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0152] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A key defect detection method, characterized in that: include: Acquire a key image to be detected under at least one light source, and use at least one defect detection method to perform defect detection on the key image to be detected under each of the light sources, to obtain defect contour mask images corresponding to each of the defect detection methods under each of the light sources; For any of the light sources, pixel points of defect contour areas in the defect contour mask images corresponding to the respective defect detection methods under the light source are merged to obtain a merged defect mask image under the light source; Merging the defect contour areas in the merged defect mask images under each of the light sources to obtain a target defect mask image; the target defect mask image includes at least one defect contour area; According to the combined defect mask images under each of the light sources, the light source corresponding to the combined defect mask image containing the largest number of defect contour areas is selected as the target light source, and the key image to be detected of the target light source is determined as the target key image to be detected; For any of the defect contour regions in the target defect mask image, based on a preset expansion radius, the defect contour region is expanded to obtain an expanded contour region; According to each of the expanded contour areas in the target defect mask image, extracting from the target key image to be detected defect contour area images that match each of the expanded contour areas, to obtain at least one defect contour area image to be detected; Performing color space conversion on each of the defect contour area images to be detected to obtain a grayscale image of each of the defect contour area images to be detected under a brightness channel; For any of the defect contour area images to be detected, key defect detection is performed based on the grayscale image and key defect type respectively corresponding thereto to obtain a key defect detection result.
2. The method according to claim 1, characterized in that: The step of performing key defect detection on any of the defect contour area images to be detected based on the grayscale image and key defect type respectively corresponding thereto to obtain a key defect detection result includes: According to each pixel point in the grayscale image of each of the defect contour area images to be detected, respectively determine the grayscale mean value and the grayscale difference value of each of the grayscale images; Determine the target defect detection mode corresponding to each of the defect contour area images to be detected according to the key defect type of each of the defect contour area images to be detected; For any of the defect contour area images to be detected, key defect detection is performed according to the grayscale mean, grayscale difference and target defect detection method of the corresponding grayscale image to obtain a key defect detection result.
3. The method according to claim 2, characterized in that Determining the grayscale mean and grayscale difference of each grayscale image according to each pixel point in the grayscale image of each defect contour area image to be detected includes: Determine the grayscale mean of each grayscale image according to each pixel point in the grayscale image of each defect contour area image to be detected; and For any of the grayscale images, a plurality of first pixel points satisfying a high pixel point threshold judgment condition and a plurality of second pixel points satisfying a low pixel point threshold judgment condition in the grayscale image are respectively determined; respectively determining first pixel means of the plurality of first pixel points and second pixel means of the plurality of second pixel points; The grayscale difference of each of the grayscale images is determined according to the first pixel mean and the second pixel mean of each of the grayscale images.
4. The method according to claim 2, characterized in that: For any of the defect contour area images to be detected, key defect detection is performed according to the grayscale mean, grayscale difference and target defect detection method of the grayscale image respectively corresponding thereto to obtain a key defect detection result, including: For any of the defect contour area images to be detected, based on the grayscale mean threshold and grayscale difference threshold of the grayscale defect detection method in the corresponding target defect detection method, perform a first defect detection on the corresponding grayscale image to obtain a first defect detection result; If there is an area defect detection method in the corresponding target defect detection method, performing a second defect detection on the corresponding grayscale image based on the area threshold of the area defect detection method to obtain a second defect detection result; If the corresponding target defect detection mode includes a length and width defect detection mode, performing a third defect detection on the corresponding grayscale image based on the length threshold and the width threshold of the length and width defect detection mode to obtain a third defect detection result; A key defect detection result is determined according to the first defect detection result, the second defect detection result and the third defect detection result.
5. The method according to claim 2, characterized in that: Before determining the grayscale mean and grayscale difference of each grayscale image according to each pixel point in the grayscale image of each defect contour area image to be detected, the method further includes: For any of the defect contour area images to be detected, determine the pixel filtering percentage according to the corresponding key defect type; According to the pixel filtering percentage, pixel filtering is performed on the pixel points in the corresponding grayscale image to obtain a filtered grayscale image of the defect contour area to be detected.
6. A key defect detection device, characterized in that: include: An image acquisition module, used to acquire an image of a key to be detected under at least one light source, and perform defect detection on the image of the key to be detected under each of the light sources using at least one defect detection method, to obtain defect contour mask images corresponding to each of the defect detection methods under each of the light sources; For any of the light sources, pixel points of defect contour areas in the defect contour mask images corresponding to the respective defect detection methods under the light source are merged to obtain a merged defect mask image under the light source; Merging the defect contour areas in the merged defect mask images under each of the light sources to obtain a target defect mask image; the target defect mask image includes at least one defect contour area; An image generation module is used to select the light source corresponding to the merged defect mask image containing the largest number of defect contour areas as the target light source according to the merged defect mask images under each of the light sources, and determine the key image to be detected of the target light source as the target key image to be detected; For any of the defect contour regions in the target defect mask image, based on a preset expansion radius, the defect contour region is expanded to obtain an expanded contour region; According to each of the expanded contour areas in the target defect mask image, extracting from the target key image to be detected defect contour area images that match each of the expanded contour areas, to obtain at least one defect contour area image to be detected; A space conversion module, used for performing color space conversion on each of the defect contour area images to be detected, so as to obtain a grayscale image of each of the defect contour area images to be detected under a brightness channel; The defect detection module is used to perform key defect detection on any of the defect contour area images to be detected based on the grayscale image and key defect type respectively corresponding thereto to obtain a key defect detection result.
7. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Object surface defect detection method and device, computer equipment and storage medium
CN114359228A
Magnetic rotor appearance quality detection method for new energy automobile
CN115937216A