Defect Detection Method and Device, Electronic Device, and Storage Medium

By generating chromatic aberration thresholds and image noise thresholds, the target area and defect area are selected, and the problem of low accuracy of defect detection in the prior art is solved, and higher detection accuracy is achieved.

CN116416190BActive Publication Date: 2025-07-01HON HAI PRECISION INDUSTRY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111663831.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-31
Publication Date
2025-07-01
Estimated Expiration
2041-12-31

AI Technical Summary

Technical Problem

The existing defect detection methods cannot effectively resist reasonable errors, resulting in low accuracy of defect detection.

Method used

By acquiring multiple positive sample images, negative sample images and test sample images, the pixel difference value corresponding to the pixel points in the test sample image is determined, the chromatic difference threshold and image noise threshold are generated, the target area and defect area are filtered, and the detection results are determined based on these thresholds.

Benefits of technology

It improves the accuracy of defect detection and effectively avoids the impact of reasonable errors on the detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116416190B_ABST
    Figure CN116416190B_ABST
Patent Text Reader

Abstract

This application relates to image processing, and provides a defect detection method, apparatus, electronic device, and storage medium. The method obtains multiple positive sample images, multiple negative sample images, and a test sample image, obtains pixel differences based on the pixel points in the test sample image and the pixel points in the multiple positive sample images, generates a color difference threshold according to the multiple positive sample images, generates multiple feature connected regions of the test sample image according to the color difference threshold and the pixel differences, generates a first threshold according to the image noise of the multiple positive sample images, screens target regions from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold, generates a second threshold according to the defective pixel points of the multiple negative sample images, and determines the detection result of the test sample in the test sample image according to the area of all pixel points in the target region and the second threshold. This application can improve the accuracy of defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing, and in particular, to a defect detection method and device, an electronic device, and a storage medium. Background Art

[0002] In the existing defect detection methods, there is a problem that reasonable errors cannot be resisted. For example, reasonable errors may include: slight color differences, background noise generated when generating product images, resulting in low accuracy of defect detection. Summary of the Invention

[0003] In view of the above, it is necessary to provide a defect detection method that can improve the accuracy of defect detection.

[0004] The first aspect of this application provides a defect detection method, and the defect detection method includes:

[0005] Obtain multiple positive sample images, multiple negative sample images, and a test sample image;

[0006] Based on the pixel points in the test sample image, determine the corresponding pixel points and the corresponding pixel differences in the multiple positive sample images;

[0007] Generate a color difference threshold according to the multiple positive sample images;

[0008] Generate multiple feature connected regions of the test sample image according to the color difference threshold and the pixel differences;

[0009] Generate a first threshold according to the image noise of the multiple positive sample images;

[0010] Screen target regions from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold;

[0011] Generate a second threshold according to the defective pixel points of the multiple negative sample images;

[0012] Determine the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold.

[0013] According to a preferred embodiment of this application, the generating a color difference threshold according to the multiple positive sample images includes:

[0014] Perform a subtraction operation on the pixel values of the corresponding pixel points in any two positive sample images to obtain a color difference value;

[0015] Count the number of pixel points with the same color difference value in the multiple positive sample images;

[0016] Generate a color difference histogram with the color difference value as the abscissa and the number of pixel points corresponding to the color difference value as the ordinate;

[0017] Select multiple consecutive color difference values from the coordinate values of the color difference histogram according to a preset value, and determine the mutually consecutive color difference values as the same set to obtain multiple feature sets;

[0018] Count the number of elements in each feature set;

[0019] Determine the feature set with the largest number of elements as the target color difference set;

[0020] Screen out the largest color difference value from the target color difference set as the color difference threshold.

[0021] According to a preferred embodiment of the present application, the generating the first threshold according to the image noise of the multiple positive sample images includes:

[0022] Determine the feature sets other than the target color difference set as multiple background color difference sets;

[0023] Screen out the pixel points corresponding to the color difference values in the multiple background color difference sets from the multiple positive sample images as noise pixel points;

[0024] Generate multiple first connected regions according to adjacent noise pixel points;

[0025] Count the number of noise pixel points in each first connected region to obtain the image noise;

[0026] Screen out the image noise with the largest value as the first threshold.

[0027] According to a preferred embodiment of the present application, the generating the multiple feature connected regions of the test sample image according to the color difference threshold and the pixel difference includes:

[0028] Determine the pixel differences less than or equal to the color difference threshold as background differences, and screen out the pixel points corresponding to the background differences from the test sample image as background pixel points;

[0029] Determine the pixel differences greater than the color difference threshold as target differences;

[0030] Screen out the pixel points corresponding to the target differences from the test sample image as target pixel points;

[0031] Generate the multiple feature connected regions according to adjacent target pixel points, and the background pixel points are located between any two feature connected regions.

[0032] According to a preferred embodiment of the present application, screening target regions from the multiple feature-connected regions according to the number of pixel points in each feature-connected region and the first threshold includes:

[0033] Count the number of pixel points in each feature-connected region to obtain a first quantity;

[0034] Determine the feature-connected region corresponding to the first quantity greater than the first threshold as the target region.

[0035] According to a preferred embodiment of the present application, generating a second threshold according to the defective pixel points of the multiple negative sample images includes:

[0036] Obtain the first pixel value of each pixel point of each negative sample image, and obtain the second pixel value of the corresponding pixel point of the corresponding positive sample image;

[0037] Calculate the difference between the first pixel value and the second pixel value to obtain a negative sample difference;

[0038] Determine the negative sample difference less than or equal to the color difference threshold as a feature difference, and screen out the pixel points corresponding to the feature difference from the multiple negative sample images as feature pixel points;

[0039] Determine the negative sample difference greater than the color difference threshold as a defective difference, and screen out the pixel points corresponding to the defective difference from the multiple negative sample images as the defective pixel points; generate the multiple second connected regions according to adjacent defective pixel points, and the feature pixel points are between any two second connected regions; count the number of pixel points in each second connected region to obtain a second quantity; determine the second connected region corresponding to the second quantity greater than the first threshold as a defective region; calculate the area of the defective region to obtain a first defective area; screen out the minimum value in the first defective areas as the second threshold.

[0040] According to a preferred embodiment of the present application, determining the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold includes:

[0041] Calculate the area of the target region according to all pixel points in the target region to obtain a second defective area;

[0042] If the second defective area is greater than the second threshold, determine the detection result as a defective sample;

[0043] If the second defective area is less than or equal to the second threshold, determine the detection result as a non-defective sample.

[0044] The second aspect of the present application provides a defect detection device, which includes:

[0045] An acquisition unit for acquiring multiple positive sample images, multiple negative sample images, and a test sample image;

[0046] A determination unit for determining corresponding pixel points and corresponding pixel differences in the multiple positive sample images based on the pixel points in the test sample image;

[0047] A generation unit for generating a color difference threshold according to the multiple positive sample images;

[0048] The generation unit is further configured to generate multiple feature connected regions of the test sample image according to the color difference threshold and the pixel differences;

[0049] The generation unit is further configured to generate a first threshold according to the image noise of the multiple positive sample images;

[0050] A screening unit for screening target regions from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold;

[0051] The generation unit is further configured to generate a second threshold according to the defective pixel points of the multiple negative sample images;

[0052] The determination unit is further configured to determine the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold.

[0053] The third aspect of the present application provides an electronic device, which includes:

[0054] A memory storing at least one instruction; and

[0055] A processor for executing the at least one instruction to implement the defect detection method.

[0056] The fourth aspect of the present application provides a computer-readable storage medium, in which at least one instruction is stored, and the at least one instruction is executed by a processor in an electronic device to implement the defect detection method.

[0057] It can be seen from the above technical solutions that the present application calculates the first threshold through the image noise of the multiple positive sample images, and screens out the target region from the test sample image according to the first threshold. Since the target region contains a certain reasonable error, therefore, by combining the second threshold determined by the defective pixel points of the multiple negative sample images, the influence of the reasonable error in the test image on defect detection can be avoided, thereby improving the detection accuracy of the test sample image. Brief Description of the Drawings

[0058] Figure 1 is an application environment diagram of a preferred embodiment of the defect detection method of the present application.

[0059] Figure 2 is a flowchart of a preferred embodiment of the defect detection method of the present application.

[0060] Figure 3 is a schematic diagram of the generation of a feature connected region in a preferred embodiment of the defect detection method of the present application.

[0061] Figure 4 is a functional module diagram of a preferred embodiment of the defect detection device of the present application.

[0062] Figure 5 is a schematic structural diagram of an electronic device in a preferred embodiment of the defect detection method implemented by the present application. Detailed Description of the Preferred Embodiment

[0063] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0064] As Figure 1 shown, it is an application environment diagram of a preferred embodiment of the defect detection method of the present application. The imaging device 2 communicates with the electronic device 1. The imaging device 2 can be a camera or other devices that implement shooting.

[0065] As Figure 2 shown, it is a flowchart of a preferred embodiment of the defect detection method of the present application. According to different requirements, the order of each step in this flowchart can be adjusted according to actual detection requirements, and some steps can be omitted.

[0066] The defect detection method is applied to one or more electronic devices 1. The electronic device 1 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. Its hardware includes, but is not limited to: microprocessors, application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.

[0067] The electronic device 1 can be any kind of electronic product that can perform human-computer interaction with users. For example, a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an Internet Protocol Television (IPTV), a smart wearable device, etc.

[0068] The electronic device 1 may further include a network device and / or a user device. Among them, the network device includes, but is not limited to, a single network server, a server group composed of multiple network servers, or a cloud composed of a large number of hosts or network servers based on cloud computing.

[0069] The network where the electronic device 1 is located includes, but is not limited to, the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.

[0070] S10, obtain multiple positive sample images, multiple negative sample images, and test sample images.

[0071] In at least one embodiment of the present application, the positive sample is a flawless sample, and the multiple positive sample images can represent flawless images. The multiple positive sample images can be used for calculating the color difference threshold and the first threshold, and the calculation process will be introduced in detail below.

[0072] In at least one embodiment of the present application, the negative sample is a defective sample, and the multiple negative sample images can represent defective images. The multiple negative sample images can be used for calculating the second threshold, and the calculation process will be introduced in detail below.

[0073] In at least one embodiment of the present application, the test sample image refers to an image of a sample that needs to be detected. By using the defect detection method, the test sample can be identified and detected to determine whether the test sample is a defective sample or a flawless sample.

[0074] In at least one embodiment of the present application, the electronic device obtains multiple positive sample images, multiple negative sample images, and test sample images, including:

[0075] The electronic device controls the imaging device to capture multiple positive samples, negative samples, and test samples at the same position and angle, and obtains the multiple positive sample images, the multiple negative sample images, and the test sample images. The multiple positive sample images, the multiple negative sample images, and the test sample images have the same shape and size.

[0076] S11. Based on the pixel points in the test sample image, determine the corresponding pixel points and the corresponding pixel differences in the multiple positive sample images.

[0077] In at least one embodiment of the present application, the pixel difference refers to the difference between the pixel value corresponding to the pixel point in the test sample image and the pixel value corresponding to the pixel point in the multiple positive sample images, and is used to represent the gap between the pixel values of two corresponding pixel points.

[0078] In at least one embodiment of the present application, the electronic device determines the corresponding pixel points and the corresponding pixel differences in the multiple positive sample images based on the pixel points in the test sample image, including:

[0079] The electronic device obtains the pixel value corresponding to the pixel point in the test sample image as the first pixel value, and obtains the pixel values of the corresponding pixel points in the multiple positive sample images as the second pixel values. The electronic device calculates the difference between the first pixel value and the second pixel value to obtain the pixel difference.

[0080] S12. Generate a color difference threshold according to the multiple positive sample images.

[0081] In at least one embodiment of the present application, the color difference threshold refers to the maximum number of pixel points corresponding to the noise in the multiple positive sample images, and is used to distinguish the target pixel points from the background pixel points in the test sample image.

[0082] In at least one embodiment of the present application, the electronic device generates a color difference threshold according to the multiple positive sample images, including:

[0083] The electronic device performs a subtraction operation on the pixel values of the corresponding pixel points in any two positive sample images to obtain a color difference value. The electronic device counts the number of pixel points with the same color difference value in the multiple positive sample images. The electronic device uses the color difference value as the abscissa and the number of pixel points corresponding to the color difference value as the ordinate to generate a color difference histogram. The electronic device selects multiple consecutive color difference values from the coordinate values in the color difference histogram according to a preset value, and determines the mutually consecutive color difference values as the same set to obtain multiple feature sets.

[0084] The electronic device counts the number of elements in each feature set, determines the feature set with the largest number of elements as the target color difference set, and screens out the largest color difference value from the target color difference set as the color difference threshold.

[0085] Among them, the pixel points in the multiple positive sample images include noise pixel points and background pixel points.

[0086] The preset value can be set customarily, and this application does not make any restrictions.

[0087] For example, when the preset value is 0, the number of pixel points corresponding to the color difference value 0 in the histogram is 2, the number of pixel points corresponding to the color difference value 1 is 3, the number of pixel points corresponding to the color difference value 2 is 4, the number of pixel points corresponding to the color difference value 3 is 5, the number of pixel points corresponding to the color difference value 4 is 2, the number of pixel points corresponding to the color difference value 5 is 3, the number of pixel points corresponding to the color difference value 6 is 0, the number of pixel points corresponding to the color difference value 7 is 1, the number of pixel points corresponding to the color difference value 8 is 2, the number of pixel points corresponding to the color difference value 9 is 2, and the number of pixel points corresponding to the color difference value 10 is 0. Then, the feature set A {color difference value 0, color difference value 1, color difference value 2, color difference value 3, color difference value 4, color difference value 5} and the feature set B = {color difference value 7, color difference value 8, color difference value 9} are obtained. The number of elements included in the feature set A is greater than the number of elements included in the feature set B. Therefore, the feature set A is the target color difference value set, and the largest color difference value 5 in the feature set A is determined as the color difference threshold.

[0088] Specifically, the coordinate value includes a vertical coordinate value and a horizontal coordinate value. The electronic device selects multiple consecutive color difference values from the coordinate values in the color difference histogram according to the preset value, and determines the mutually consecutive color difference values as the same set, obtaining multiple feature sets including:

[0089] Each vertical coordinate value is respectively compared with the preset value. When the vertical coordinate value is greater than or equal to the preset value, the horizontal coordinate value corresponding to the vertical coordinate value is selected to obtain multiple color difference values. As described above, the horizontal coordinate value is the color difference value.

[0090] Consecutive color difference values are selected from the multiple color difference values, and the mutually consecutive color difference values are determined as the same set, obtaining multiple feature sets.

[0091] Through the above embodiments, the maximum color difference value of the background pixel points in the multiple positive sample images can be obtained, and the maximum color difference value is used as the color difference threshold.

[0092] S13. Generate multiple feature connected regions of the test sample image according to the color difference threshold and the pixel difference.

[0093] In at least one embodiment of this application, the multiple feature connected regions refer to multiple connected regions formed by adjacent target pixel points in the test sample image.

[0094] In at least one embodiment of this application, the electronic device generates multiple feature connected regions of the test sample image according to the color difference threshold and the pixel difference, including:

[0095] The electronic device determines the pixel difference greater than the color difference threshold as the target difference, and filters out the pixel points corresponding to the target difference from the test sample image as the target pixel points. The electronic device generates the multiple feature connected regions according to the adjacent target pixel points.

[0096] Among them, the pixel points in the test sample image include background pixel points and target pixel points. The background pixel points are located between any two feature connected regions.

[0097] As Figure 3 shown, it is a schematic diagram of generating feature connected regions in a preferred embodiment of the defect detection method of this application. When the color difference threshold is 5, if the pixel difference is greater than the color difference threshold 5, the pixel difference is determined as the target difference, the pixel points of the target difference on the test sample image are determined as the target pixel points, and the target pixel points are marked as "1". If the pixel difference is less than or equal to the color difference threshold 5, the pixel difference is determined as the background difference, the pixel points of the background difference on the test sample image are determined as the background pixel points, and the background pixel points are marked as "0". In this way, the target pixel points and the background pixel points are distinguished in the test sample image, the adjacent target pixel points generate the multiple feature connected regions, and the background pixel points are located between any two feature connected regions.

[0098] Through the above implementation manner, the background pixel points and the target pixel points in the test sample image are respectively marked with "0" and "1", the target pixel points and the background pixel points are distinguished, and the adjacent target pixel points generate the multiple feature connected regions. Therefore, the multiple feature connected regions in the test sample image can be accurately filtered out.

[0099] S14. Generate a first threshold according to the image noise of the multiple positive sample images.

[0100] In at least one embodiment of this application, the maximum value in the image noise of the multiple positive sample images is used as the first threshold.

[0101] In at least one embodiment of this application, the image noise may include, but is not limited to: slight color difference, background noise generated when generating product images.

[0102] In at least one embodiment of this application, the electronic device generating the first threshold according to the image noise of the multiple positive sample images includes:

[0103] The electronic device determines the feature set other than the target color difference set as multiple background color difference sets, and screens out the pixel points corresponding to the color differences in the multiple background color difference sets from the multiple positive sample images as noise pixel points. Further, the electronic device generates multiple first connected regions based on adjacent noise pixel points, counts the number of noise pixel points in each first connected region to obtain the image noise, and screens out the image noise with the largest value as the first threshold.

[0104] Wherein, the noise pixel points refer to the pixel points corresponding to the color differences in the multiple background color difference sets in the multiple positive sample images.

[0105] Through the above implementation manner, the largest image noise in the multiple positive sample images can be screened out, and the largest image noise is used as the first threshold, and the first threshold is used to screen out the target region from the multiple feature connected regions.

[0106] S15. According to the number of pixel points in each feature connected region and the first threshold, screen out the target region from the multiple feature connected regions.

[0107] In at least one embodiment of the present application, the target region refers to a feature connected region containing a number of pixel points greater than the first threshold.

[0108] In at least one embodiment of the present application, the electronic device screening out the target region from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold includes:

[0109] The electronic device counts the number of pixel points in each feature connected region to obtain a first number. Further, the electronic device determines the feature connected region corresponding to the first number being greater than the first threshold as the target region.

[0110] Through the above implementation manner, screening out the target region from the multiple feature connected regions can further determine the reasonable error in the test sample image and improve the detection accuracy of the test sample image.

[0111] S16. Generate a second threshold according to the defective pixel points of the multiple negative sample images.

[0112] In at least one embodiment of the present application, determine the defective region according to the number of defective pixel points in each second connected region of the multiple negative sample images and the first threshold, and use the minimum value of the area of the defective region as the second threshold.

[0113] In at least one embodiment of the present application, the electronic device generating the second threshold according to the defective pixel points of the multiple negative sample images includes:

[0114] The electronic device obtains the third pixel value of each negative sample image and obtains the fourth pixel value of each positive sample image, calculates the difference between the third pixel value and the fourth pixel value to obtain a negative sample difference. Further, the electronic device determines the negative sample differences less than or equal to the color difference threshold as feature differences, screens the pixel points corresponding to the feature differences from the multiple negative sample images as feature pixel points, determines the negative sample differences greater than the color difference threshold as defective differences, and screens the pixel points corresponding to the defective differences from the multiple negative sample images as defective pixel points. Furthermore, the electronic device generates the multiple second connected regions according to adjacent defective pixel points, and the electronic device counts the number of pixel points in each second connected region to obtain a second quantity. The electronic device determines the second connected regions corresponding to the second quantity greater than the first threshold as defective regions, calculates the area of the defective regions to obtain a first defective area, and screens the minimum value in the first defective area as the second threshold.

[0115] Wherein, the pixel points in the multiple negative sample images include feature pixel points and defective pixel points, and the feature pixel points are located between any two second connected regions.

[0116] In at least one embodiment of the present application, the defective pixel points refer to the pixel points corresponding to the defective differences in the multiple negative sample images.

[0117] In at least one embodiment of the present application, the second connected region refers to the region generated by adjacent defective pixel points in the multiple negative sample images.

[0118] In at least one embodiment of the present application, the first defective area represents the area of the second connected regions where the number of pixel points is greater than the first threshold.

[0119] Through the above implementation manner, according to the color difference threshold and the first threshold, the minimum area of the defective regions in the multiple negative sample images can be accurately obtained, and the minimum area is used as the second threshold.

[0120] S17. Determine the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold.

[0121] In at least one embodiment of the present application, the detection result includes that the test sample in the test sample image is a defective sample and that the test sample in the test sample image is a non-defective sample.

[0122] In at least one embodiment of the present application, the electronic device determines the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold, including:

[0123] The electronic device calculates the area of the target region based on all the pixel points in the target region to obtain the second defect area. If the second defect area is greater than the second threshold, the electronic device determines that the test sample is a defective sample. Or, if the second defect area is less than or equal to the second threshold, the electronic device determines that the test sample is a non-defective sample.

[0124] Through the above implementation manner, it is possible to accurately detect whether the test sample in the test sample image is a defective sample and output the corresponding detection result.

[0125] It can be seen from the above technical solutions that the present application calculates the first threshold based on the image noise of the multiple positive sample images, and screens out the target region from the test sample image according to the first threshold. Since the target region contains a certain reasonable error, therefore, by combining the second threshold determined by the defective pixel points of the multiple negative sample images, it is possible to avoid the influence of the reasonable error in the test image on the defect detection, thereby improving the detection accuracy of the test sample image.

[0126] As Figure 4 shown, it is a functional module diagram of a preferred embodiment of the defect detection device of the present application. The defect detection device 11 includes an acquisition unit 110, a determination unit 111, a generation unit 112, and a screening unit 113. The modules / units referred to in the present application refer to a series of computer program segments that can be acquired by a processor 13 and can complete fixed functions, and are stored in a memory 12. In this embodiment, the functions of each module / unit will be described in detail in subsequent embodiments.

[0127] The acquisition unit 110 acquires multiple positive sample images, multiple negative sample images, and a test sample image.

[0128] In at least one embodiment of the present application, the multiple positive sample images are images of positive samples, the positive samples are non-defective samples, and the multiple positive sample images can represent non-defective images. The multiple positive sample images can be used for calculating the color difference threshold and the first threshold, and the calculation process will be introduced in detail below.

[0129] In at least one embodiment of the present application, the multiple negative sample images are images of negative samples, the negative samples are defective samples, and the multiple negative sample images can represent defective images. The multiple negative sample images can be used for calculating the second threshold, and the calculation process will be introduced in detail below.

[0130] In at least one embodiment of the present application, the test sample image refers to an image of a sample to be detected. By using the defect detection method, it is possible to determine whether the test sample is a defective sample or a non-defective sample by identifying and detecting the test sample image.

[0131] In at least one embodiment of the present application, the obtaining unit 110 obtaining multiple positive sample images, multiple negative sample images, and a test sample image includes:

[0132] The obtaining unit 110 controls the imaging device to capture multiple positive samples, negative samples, and test samples at the same position and angle, and obtains the multiple positive sample images, the multiple negative sample images, and the test sample image. The multiple positive sample images, the multiple negative sample images, and the test sample image have the same shape and size.

[0133] The determining unit 111 determines the corresponding pixel points and the corresponding pixel differences in the multiple positive sample images based on the pixel points in the test sample image.

[0134] In at least one embodiment of the present application, the pixel difference refers to the difference between the pixel value corresponding to the pixel point in the test sample image and the pixel value corresponding to the pixel point in the multiple positive sample images, and is used to represent the gap between the pixel values of two corresponding pixel points.

[0135] In at least one embodiment of the present application, the determining unit 111 determining the corresponding pixel points and the corresponding pixel differences in the multiple positive sample images based on the pixel points in the test sample image includes:

[0136] The determining unit 111 obtains the pixel value corresponding to the pixel point in the test sample image as the first pixel value, and obtains the pixel values of the corresponding pixel points in the multiple positive sample images as the second pixel values. The determining unit 111 calculates the difference between the first pixel value and the second pixel value to obtain the pixel difference.

[0137] The generating unit 112 generates a color difference threshold according to the multiple positive sample images.

[0138] In at least one embodiment of the present application, the color difference threshold refers to the maximum number of pixel points corresponding to the noise in the multiple positive sample images, and is used to distinguish the target pixel points from the background pixel points in the test sample image.

[0139] In at least one embodiment of the present application, the generating unit 112 generating a color difference threshold according to the multiple positive sample images includes:

[0140] The generating unit 112 performs a subtraction operation on the pixel values of the corresponding pixel points in any two positive sample images to obtain a color difference value. The generating unit 112 counts the number of pixel points with the same color difference value in the multiple positive sample images. The generating unit 112 uses the color difference value as the abscissa and the number of pixel points corresponding to the color difference value as the ordinate to generate a color difference histogram. The generating unit 112 selects multiple consecutive color difference values from the coordinate values in the color difference histogram according to a preset value, and determines the mutually consecutive color difference values as the same set to obtain multiple feature sets.

[0141] The generating unit 112 counts the number of elements in each feature set, determines the feature set with the largest number of elements as the target color difference set, and screens out the largest color difference value from the target color difference set as the color difference threshold.

[0142] Among them, the pixel points in the multiple positive sample images include noise pixel points and background pixel points.

[0143] The preset value can be set customarily, and this application does not make any restrictions.

[0144] For example, when the preset value is 0, the number of pixel points corresponding to the color difference value 0 in the histogram is 2, the number of pixel points corresponding to the color difference value 1 is 3, the number of pixel points corresponding to the color difference value 2 is 4, the number of pixel points corresponding to the color difference value 3 is 5, the number of pixel points corresponding to the color difference value 4 is 2, the number of pixel points corresponding to the color difference value 5 is 3, the number of pixel points corresponding to the color difference value 6 is 0, the number of pixel points corresponding to the color difference value 7 is 1, the number of pixel points corresponding to the color difference value 8 is 2, the number of pixel points corresponding to the color difference value 9 is 2, and the number of pixel points corresponding to the color difference value 10 is 0. Then, the feature set A {color difference values 0, 1, 2, 3, 4, 5} and the feature set B = {color difference values 7, 8, 9} are obtained. The number of elements included in the feature set A is greater than the number of elements included in the feature set B. Therefore, the feature set A is the target color difference set, and the largest color difference value 5 in the feature set A is determined as the color difference threshold.

[0145] Specifically, the coordinate values include ordinate values and abscissa values. The generating unit 112 selects multiple consecutive color difference values from the coordinate values in the color difference histogram according to a preset value, and determining the mutually consecutive color difference values as the same set to obtain multiple feature sets includes:

[0146] Compare each ordinate value with the preset value respectively. When the ordinate value is greater than or equal to the preset value, select the abscissa value corresponding to the ordinate value. Using this method, multiple abscissa values are obtained. As described above, the multiple abscissa values are multiple color difference values.

[0147] Select consecutive color difference values from the multiple abscissa values, and determine the mutually consecutive color difference values as the same set to obtain multiple feature sets.

[0148] Through the above embodiments, the maximum color difference value of the background pixel points in the positive sample image can be obtained, and the maximum color difference value is used as the color difference threshold.

[0149] The generating unit 112 generates multiple feature connected regions of the test sample image according to the color difference threshold and the pixel difference.

[0150] In at least one embodiment of the present application, the multiple feature connected regions refer to multiple connected regions formed by adjacent target pixel points in the test sample image.

[0151] In at least one embodiment of the present application, the generating unit 112 generating multiple feature connected regions of the test sample image according to the color difference threshold and the pixel difference includes:

[0152] The generating unit 112 determines the pixel differences greater than the color difference threshold as target differences, and screens the pixel points corresponding to the target differences from the test sample image as target pixel points. The generating unit 112 generates the multiple feature connected regions according to the adjacent target pixel points.

[0153] Among them, the pixel points in the test sample image include background pixel points and target pixel points. The background pixel points are located between any two feature connected regions.

[0154] As Figure 3 shown, it is a schematic diagram of the generation of feature connected regions in a preferred embodiment of the defect detection method of the present application. When the color difference threshold is 5, if the pixel difference is greater than the color difference threshold 5, the pixel difference is determined as the target difference, the pixel points of the target difference on the test sample image are determined as target pixel points, and the target pixel points are marked as "1". If the pixel difference is less than or equal to the color difference threshold 5, the pixel difference is determined as the background difference, the pixel points of the background difference on the test sample image are determined as background pixel points, and the background pixel points are marked as "0". In this way, the target pixel points and the background pixel points are distinguished in the test sample image, and the adjacent target pixel points generate the multiple feature connected regions, and the background pixel points are located between any two feature connected regions.

[0155] Through the above embodiments, the background pixel points and the target pixel points in the test sample image are marked with "0" and "1" respectively, so that the target pixel points and the background pixel points can be distinguished, and the adjacent target pixel points generate the multiple feature connected regions. Therefore, the multiple feature connected regions in the test sample image can be accurately screened out.

[0156] The generating unit 112 generates a first threshold according to the image noise of the multiple positive sample images.

[0157] In at least one embodiment of the present application, the maximum value in the image noise of the multiple positive sample images is used as the first threshold.

[0158] In at least one embodiment of the present application, the image noise may include, but is not limited to: slight color differences, background noise generated when generating product images.

[0159] In at least one embodiment of the present application, the generating unit 112 generating a first threshold according to the image noise of the multiple positive sample images includes:

[0160] The generating unit 112 determines the feature sets except the target color difference set as multiple background color difference sets, screens the pixel points corresponding to the color differences in the multiple background color difference sets from the multiple positive sample images as noise pixel points. Further, the generating unit 112 generates multiple first connected regions according to the adjacent noise pixel points, counts the number of noise pixel points in each first connected region to obtain the image noise, and screens and selects the image noise with the largest value as the first threshold.

[0161] Wherein, the noise pixel points refer to the pixel points corresponding to the color differences in the multiple background color difference sets in the multiple positive sample images.

[0162] Through the above embodiments, the largest image noise in the multiple positive sample images can be screened out, and the largest image noise is used as the first threshold, and the first threshold is used to screen out the target region from the multiple feature connected regions.

[0163] The screening unit 113 screens the target region from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold.

[0164] In at least one embodiment of the present application, the target region refers to the feature connected region containing the number of pixel points greater than the first threshold.

[0165] In at least one embodiment of the present application, the screening unit 113 screening the target region from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold includes:

[0166] The screening unit 113 counts the number of pixel points in each feature connected region to obtain a first quantity. Further, the screening unit 113 determines the feature connected region corresponding to the first quantity greater than the first threshold as the target region.

[0167] By the above implementation manner, screening the target region from the multiple feature connected regions can further determine the reasonable error in the test sample image and improve the detection accuracy of the test sample image.

[0168] The generating unit 112 generates a second threshold according to the defective pixel points of the multiple negative sample images.

[0169] In at least one embodiment of the present application, the defective region is determined according to the number of defective pixel points in each second connected region of the multiple negative sample images and the first threshold, and the minimum value of the area of the defective region is used as the second threshold.

[0170] In at least one embodiment of the present application, the generating unit 112 generating the second threshold according to the defective pixel points of the multiple negative sample images includes:

[0171] The generating unit 112 obtains the third pixel value of each negative sample image, and obtains the fourth pixel value of each positive sample image, calculates the difference between the third pixel value and the fourth pixel value to obtain a negative sample difference. Further, the generating unit 112 determines the negative sample difference less than or equal to the color difference threshold as a feature difference, screens the pixel points corresponding to the feature difference from the multiple negative sample images as feature pixel points, determines the negative sample difference greater than the color difference threshold as a defective difference, screens the pixel points corresponding to the defective difference from the multiple negative sample images as defective pixel points. Further still, the generating unit 112 generates the multiple second connected regions according to adjacent defective pixel points, the generating unit 112 counts the number of pixel points in each second connected region to obtain a second quantity. The generating unit 112 determines the second connected region corresponding to the second quantity greater than the first threshold as the defective region, calculates the area of the defective region to obtain a first defective area, and screens the minimum value in the first defective areas as the second threshold.

[0172] Wherein, the pixel points in the multiple negative sample images include feature pixel points and defective pixel points, and the feature pixel points are between any two second connected regions.

[0173] In at least one embodiment of the present application, the defect difference refers to the negative sample difference greater than the color difference threshold, and the defective pixel points refer to the pixel points corresponding to the defect difference in the multiple negative sample images.

[0174] In at least one embodiment of the present application, the second connected region refers to the region generated by adjacent defective pixel points in the multiple negative sample images.

[0175] In at least one embodiment of the present application, the first defect area represents the area of the second connected region where the number of pixel points is greater than the first threshold.

[0176] Through the above implementation manner, the minimum area of the defect region in the multiple negative sample images can be accurately obtained according to the color difference threshold and the first threshold, and the minimum area is used as the second threshold.

[0177] The determining unit 111 determines the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold.

[0178] In at least one embodiment of the present application, the detection result includes that the test sample in the test sample image is a defective sample and the test sample in the test sample image is a non-defective sample.

[0179] In at least one embodiment of the present application, the determining unit 111 determines the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold, including:

[0180] The determining unit 111 calculates the area of the target region according to all the pixel points in the target region to obtain the second defect area. If the second defect area is greater than the second threshold, the determining unit 111 determines that the test sample is a defective sample. Or, if the second defect area is less than or equal to the second threshold, the determining unit 111 determines that the test sample is a non-defective sample.

[0181] Through the above implementation manner, it can be accurately detected whether the test sample in the test sample image is a defective sample and the corresponding detection result is output.

[0182] As can be seen from the above technical solutions, in the present application, the first threshold is calculated based on the image noise of the multiple positive sample images, and the target region is screened from the test sample images according to the first threshold. Since the target region contains a certain reasonable error, therefore, by combining the defective pixel points of the multiple negative sample images to determine the second threshold, the influence of the reasonable error in the test image on the defect detection can be avoided, thereby improving the detection accuracy of the test sample images.

[0183] As Figure 5 shown, it is a schematic structural diagram of an electronic device according to a preferred embodiment of the method for implementing defect detection in the present application.

[0184] In an embodiment of the present application, the electronic device 1 includes, but is not limited to, a memory 12, a processor 13, and a computer program stored in the memory 12 and executable on the processor 13, such as a defect detection program.

[0185] Those skilled in the art can understand that the schematic diagram is only an example of the electronic device 1, and does not constitute a limitation on the electronic device 1. It may include more or fewer components than shown, or combine certain components, or different components. For example, the electronic device 1 may further include input / output devices, network access devices, buses, etc.

[0186] The processor 13 may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The processor 13 is the operation core and control center of the electronic device 1, connecting various parts of the entire electronic device 1 through various interfaces and lines, and obtaining the operating system of the electronic device 1 and various installed application programs, program codes, etc.

[0187] The processor 13 obtains the operating system of the electronic device 1 and various installed application programs. The processor 13 obtains the application program to implement the steps in the above-mentioned various embodiments of the defect detection method, such as Figure 2 the steps shown.

[0188] Exemplarily, the computer program may be divided into one or more modules / units, and the one or more modules / units are stored in the memory 12 and obtained by the processor 13 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, and these instruction segments are used to describe the obtaining process of the computer program in the electronic device 1. For example, the computer program may be divided into an obtaining unit 110, a determining unit 111, a generating unit 112, and a screening unit 113.

[0189] The memory 12 may be used to store the computer program and / or modules. The processor 13 realizes various functions of the electronic device 1 by running or obtaining the computer program and / or modules stored in the memory 12, and by calling the data stored in the memory 12. The memory 12 may mainly include a program storage area and a data storage area. Among them, the program storage area may store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.); the data storage area may store data created according to the use of the electronic device. In addition, the memory 12 may include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices.

[0190] The memory 12 may be an external memory and / or an internal memory of the electronic device 1. Further, the memory 12 may be a memory in a physical form, such as a memory stick, a TF card (Trans-flash Card), etc.

[0191] If the modules / units integrated in the electronic device 1 are implemented in the form of software function units and sold or used as independent products, they may be stored in a computer-readable storage medium. Based on such an understanding, to implement all or part of the processes in the above-mentioned embodiment methods of the present application, it may also be completed by a computer program instructing relevant hardware. The computer program may be stored in a computer-readable storage medium. When the computer program is obtained by the processor, the steps of the above-mentioned various method embodiments may be implemented.

[0192] Among them, the computer program includes computer program code, which can be in the form of source code, object code, an accessible file, or some intermediate form, etc. The computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM, Read-Only Memory).

[0193] Combined with Figure 2 , the memory 12 in the electronic device 1 stores multiple instructions to implement a defect detection method, and the processor 13 can obtain the multiple instructions to implement: obtaining multiple positive sample images, multiple negative sample images, and test sample images; based on the pixel points in the test sample images, determining the corresponding pixel points and the corresponding pixel differences in the multiple positive sample images; generating a color difference threshold according to the multiple positive sample images; generating multiple feature connected regions of the test sample images according to the color difference threshold and the pixel differences; generating a first threshold according to the image noise of the multiple positive sample images; screening target regions from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold; generating a second threshold according to the defective pixel points of the multiple negative sample images; and determining the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold.

[0194] Specifically, for the specific implementation method of the above instructions by the processor 13, reference can be made to Figure 2 the description of the relevant steps in the corresponding embodiment, which will not be elaborated here.

[0195] In several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division, and there can be other division methods in actual implementation.

[0196] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they can be located in one place, or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0197] In addition, in each embodiment of the present application, the various functional modules can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated unit can be implemented in the form of hardware, or in the form of a combination of hardware and software functional modules.

[0198] Therefore, in all aspects, the embodiments should be regarded as exemplary and non-restrictive. The scope of this application is defined by the appended claims rather than the above description. Accordingly, all changes that fall within the meaning and scope of the equivalent elements of the claims are intended to be embraced within this application. Any reference signs in the claims should not be construed as limiting the claims concerned.

[0199] In addition, it is obvious that the term "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of elements or devices described in this application can also be implemented by one element or device through software or hardware. Terms such as "first" and "second" are used to denote names and do not denote any particular order.

[0200] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and not to limit them. Although this application has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of this application can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of this application.

Claims

1. A flaw detection method, characterized in that, The defect detection method includes: Obtaining multiple positive sample images, multiple negative sample images, and a test sample image; Based on the pixel points in the test sample image, determining the corresponding pixel points and the corresponding pixel differences in the multiple positive sample images; Generating a color difference threshold according to the multiple positive sample images; Generating multiple feature connected regions of the test sample image according to the color difference threshold and the pixel differences; Generating a first threshold according to the image noise of the multiple positive sample images; Screening target regions from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold; Generating a second threshold according to the defective pixel points of the multiple negative sample images; Determining the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold.

2. The defect detection method according to claim 1, wherein The generating a color difference threshold according to the multiple positive sample images includes: Performing a subtraction operation on the pixel values of the corresponding pixel points in any two positive sample images to obtain a color difference value; Counting the number of pixel points with the same color difference value in the multiple positive sample images; Using the color difference value as the abscissa and the number of pixel points corresponding to the color difference value as the ordinate to generate a color difference histogram; Selecting multiple consecutive color difference values from the coordinate values of the color difference histogram according to a preset value, and determining the mutually consecutive color difference values as the same set to obtain multiple feature sets; Counting the number of elements in each feature set; Determining the feature set with the largest number of elements as the target color difference set; Screening out the largest color difference value from the target color difference set as the color difference threshold.

3. The defect detection method according to claim 2, wherein The generating a first threshold according to the image noise of the multiple positive sample images includes: Determining the feature sets other than the target color difference set as multiple background color difference sets; Screening the pixel points corresponding to the color difference values in the multiple background color difference sets from the multiple positive sample images as noise pixel points; Generating multiple first connected regions according to adjacent noise pixel points; Counting the number of noise pixel points in each first connected region to obtain the image noise; Selecting the image noise with the largest value as the first threshold.

4. The defect detection method according to claim 1, wherein The generating multiple feature connected regions of the test sample image according to the color difference threshold and the pixel differences includes: Determining the pixel differences less than or equal to the color difference threshold as background differences, and screening the pixel points corresponding to the background differences from the test sample image as background pixel points; Determining the pixel differences greater than the color difference threshold as target differences, and screening the pixel points corresponding to the target differences from the test sample image as target pixel points; and generating the multiple feature connected regions according to adjacent target pixel points, with the background pixel points being between any two feature connected regions.

5. The defect detection method according to claim 1, characterized in that, The screening target regions from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold includes: Counting the number of pixel points in each feature connected region to obtain a first number; Determining the feature connected region corresponding to the first number greater than the first threshold as the target region.

6. The defect detection method according to claim 1, wherein Generating the second threshold according to the defective pixel points of the multiple negative sample images includes: Obtaining a first pixel value of each pixel point of each negative sample image, and obtaining a second pixel value of the corresponding pixel point of the corresponding positive sample image; Calculating a difference between the first pixel value and the second pixel value to obtain a negative sample difference; Determining the negative sample differences less than or equal to the color difference threshold as characteristic differences, and screening out the pixel points corresponding to the characteristic differences from the multiple negative sample images as characteristic pixel points; Determining the negative sample differences greater than the color difference threshold as defective differences, and screening out the pixel points corresponding to the defective differences from the multiple negative sample images as the defective pixel points; generating the multiple second connected regions according to adjacent defective pixel points, with the characteristic pixel points being between any two second connected regions; counting the number of pixel points in each second connected region to obtain a second quantity; determining the second connected region corresponding to the second quantity greater than the first threshold as a defective region; calculating the area of the defective region to obtain a first defective area; screening out the minimum value in the first defective areas as the second threshold.

7. The defect detection method according to claim 1, wherein Determining the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold includes: Calculating the area of the target region according to all the pixel points in the target region to obtain a second defective area; If the second defective area is greater than the second threshold, determining the detection result as a defective sample; If the second defective area is less than or equal to the second threshold, determining the detection result as a non-defective sample.

8. A defect detection device, characterized in that, The defective detection device includes: An acquisition unit, configured to acquire multiple positive sample images, multiple negative sample images, and a test sample image; A determination unit, configured to determine, based on the pixel points in the test sample image, the corresponding pixel points and the corresponding pixel differences in the multiple positive sample images; A generation unit, configured to generate a color difference threshold according to the multiple positive sample images; The generation unit is further configured to generate multiple characteristic connected regions of the test sample image according to the color difference threshold and the pixel differences; The generation unit is further configured to generate a first threshold according to the image noise of the multiple positive sample images; A screening unit, configured to screen out a target region from the multiple characteristic connected regions according to the number of pixel points in each characteristic connected region and the first threshold; The generation unit is further configured to generate a second threshold according to the defective pixel points of the multiple negative sample images; The determination unit is further configured to determine the detection result of the test sample corresponding to the test sample image according to the area of the target region and the second threshold.

9. An electronic device, characterized in that, The electronic device includes: A memory, storing at least one instruction; and A processor, configured to execute the at least one instruction to implement the defective detection method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: At least one instruction is stored in the computer-readable storage medium, and the at least one instruction is executed by a processor in the electronic device to implement the defective detection method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Pearl finish grade detection method and system

    CN110766683A

  • Image processing method and device, electronic equipment and storage medium

    CN111709894A