Product Appearance Defect Detection Method, Electronic Device and Storage Medium

By segmenting the product sample images and using the autoencoder to generate feature communication areas and thresholds, the problem of low detection accuracy caused by image scaling in the prior art is solved, and a higher accuracy of product appearance defect detection is achieved.

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

Patent Information

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

AI Technical Summary

Technical Problem

In existing product appearance defect detection solutions, image scaling leads to loss of details and cannot resist reasonable errors, resulting in low detection accuracy.

Method used

By segmenting the product sample image into multiple input image blocks, processing with a pre-trained autoencoder, a feature communication area and threshold are generated, the target area and defect area are selected, and the threshold is generated by combining the noise and defective pixel points of the positive and negative sample images to determine the detection result.

Benefits of technology

It avoids the loss of details caused by image scaling, accurately filters out the target area, improves the accuracy of product appearance defect detection, and reduces the impact of reasonable errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116433559B_ABST
    Figure CN116433559B_ABST
Patent Text Reader

Abstract

This application relates to image processing, and provides a method for detecting product appearance defects, an electronic device, and a storage medium. The method obtains multiple positive sample images, multiple negative sample images, and a product sample image. After dividing the product sample image into multiple input image blocks, the input image blocks are input into a pre-trained autoencoder to obtain multiple reconstructed image blocks. Based on each reconstructed image block and the corresponding pixel points in each input image block, the corresponding pixel differences are obtained. Multiple feature connected regions are generated according to the multiple positive sample images and the pixel differences. A first threshold is generated based on the image noise of the multiple positive sample images. Target regions are screened from the multiple feature connected regions according to the number of pixel points in each feature connected region and the first threshold. A second threshold is generated according to the defective pixel points of the multiple negative sample images. The detection result is determined based on the area of the target region and the second threshold. This application can improve the accuracy of product appearance 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 method for detecting product appearance defects, an electronic device, and a storage medium. Background Art

[0002] In existing product appearance defect detection solutions, scaling the product image changes the number of pixels in the image, which in turn causes some image details to be lost in the scaled image. In addition, there is also the problem of being unable to resist reasonable errors, resulting in low accuracy of existing product appearance detection solutions. Summary of the Invention

[0003] In view of the above, it is necessary to provide a method for detecting product appearance defects to improve the accuracy of product appearance defect detection.

[0004] This application provides a method for detecting product appearance defects, and the method for detecting product appearance defects includes:

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

[0006] Segment the product sample image into multiple input image blocks, and input the multiple input image blocks into a pre-trained autoencoder to obtain multiple reconstructed image blocks;

[0007] Based on the pixels in each reconstructed image block, determine the corresponding pixels and the corresponding pixel differences in each input image block;

[0008] Generate multiple feature connected regions for each input image block according to the multiple positive sample images and the pixel differences;

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

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

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

[0012] Determine the detection result of the product sample in the product sample image based on the area of the target region and the second threshold.

[0013] According to an optional embodiment of the present application, the step of inputting the multiple input image blocks into a pre-trained autoencoder to obtain multiple reconstructed image blocks includes:

[0014] Perform encoding processing on each input image block to obtain a feature vector of each input image block;

[0015] Performing arithmetic processing on each feature vector based on the encoder in the autoencoder to obtain a plurality of latent vectors corresponding to the plurality of input image patches;

[0016] Inputting the plurality of latent vectors into the decoder in the autoencoder for reconstruction processing to obtain the plurality of reconstructed image patches.

[0017] According to an optional embodiment of the present application, the generating a plurality of feature connected regions of each input image patch according to the plurality of positive sample images and the pixel difference values includes:

[0018] Performing a subtraction operation on the pixel values corresponding to the pixel points in any two positive sample image patches to obtain a color difference value;

[0019] Counting the number of pixel points with the same color difference value in the plurality of positive sample image patches;

[0020] Taking 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;

[0021] Selecting a plurality of 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 a plurality of feature sets;

[0022] Counting the number of elements in each feature set;

[0023] Determining the feature set with the largest number of elements as the target color difference set;

[0024] Selecting the largest color difference value from the target color difference set as the color difference threshold;

[0025] Determining the pixel difference values less than or equal to the color difference threshold as background difference values;

[0026] Selecting the pixel points corresponding to the background difference values from each input image patch as background pixel points;

[0027] Determining the pixel difference values greater than the color difference threshold as target difference values;

[0028] Selecting the pixel points corresponding to the target difference values from each input image patch as target pixel points;

[0029] Generating the plurality of feature connected regions according to adjacent target pixel points, and the background pixel points are located between any two feature connected regions.

[0030] According to an optional embodiment of the present application, the generating a first threshold based on the image noise of the plurality of positive sample images includes:

[0031] Determine the set of features other than the set of target color difference values as multiple sets of background color difference values;

[0032] Screen out the pixel points corresponding to the color difference values in the multiple sets of background color difference values from the multiple positive sample image patches as noise pixel points;

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

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

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

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

[0037] Segment each negative sample image into multiple negative sample image patches according to a preset size;

[0038] Obtain the first pixel value of each negative sample image patch and obtain the second pixel value of each positive sample image patch;

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

[0040] Determine the negative sample differences less than or equal to the color difference threshold as feature differences;

[0041] Screen out the pixel points corresponding to the feature differences from each negative sample image patch as feature pixel points;

[0042] Determine the negative sample differences greater than the color difference threshold as defective differences;

[0043] Screen out the pixel points corresponding to the defective differences from each negative sample image patch as the defective pixel points;

[0044] Generate multiple second connected regions according to adjacent defective pixel points, and the feature pixel points are located between any two second connected regions;

[0045] Count the number of pixel points in each second connected region to obtain a second quantity;

[0046] Determine the second connected regions with the second quantity greater than the first threshold as defective regions;

[0047] Calculate the area of the defective region according to all the pixel points in the defective region to obtain a first defective area;

[0048] Screen out the minimum value in the first defective area as the second threshold.

[0049] According to an alternative 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:

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

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

[0052] According to an alternative embodiment of the present application, determining the detection result of the product sample in the product sample image based on the area of the target region and the second threshold includes:

[0053] Calculate the area of the target region based on all the pixel points in the target region to obtain a second defect area;

[0054] Determine the input image block corresponding to the second defect area greater than the second threshold as a defect sample block;

[0055] If there is at least one defect sample block among the multiple input image blocks, determine the product sample as a product appearance defect sample;

[0056] Locate the defect position according to the position of the defect sample block in the product sample image;

[0057] Determine the product appearance defect sample and the defect position as the detection result.

[0058] According to an alternative embodiment of the present application, the product sample image can be regarded as a known product sample image to perform product appearance defect detection on the product sample image to be measured.

[0059] The present application also provides an electronic device, which includes:

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

[0061] A processor that obtains the instruction stored in the memory to implement the product appearance defect detection method.

[0062] The present application also 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 product appearance defect detection method.

[0063] As can be seen from the above technical solution, in this application, the multiple positive sample image blocks obtained by segmentation are input into the autoencoder for training. Since this application does not need to scale the product sample image, it can avoid losing the image details in the product sample image. Further, the first threshold is calculated through the multiple positive sample image blocks, and the target area is screened out from the product sample image according to the first threshold. Since there is a certain reasonable error in the target area, the second threshold determined by combining the defective pixel points in the multiple negative sample image blocks can avoid the influence of the reasonable error in the product sample image on the detection of product appearance defects, thereby improving the detection accuracy of the product sample image. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] Figure 1 FIG. is an application environment diagram of a preferred embodiment of the product appearance defect detection method of this application.

[0065] Figure 2 FIG. is a flowchart of a preferred embodiment of the product appearance defect detection method of this application.

[0066] Figure 3 FIG. is a schematic diagram of the generation of characteristic connected regions in a preferred embodiment of the product appearance defect detection method of this application.

[0067] Figure 4 FIG. is a schematic structural diagram of an electronic device in a preferred embodiment for implementing the product appearance defect detection method of this application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0068] In order to make the objectives, technical solutions, and advantages of this application clearer, the following describes this application in detail with reference to the accompanying drawings and specific embodiments.

[0069] As Figure 1 shown, FIG. is an application environment diagram of a preferred embodiment of a product appearance defect detection method of this 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.

[0070] As Figure 2 shown, FIG. is a flowchart of a preferred embodiment of a product appearance defect detection method of this 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.

[0071] The product appearance defect detection method is applied to one or more electronic devices 1, which are devices capable of automatically performing 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.

[0072] The electronic device 1 can be any electronic product that can interact with users. For example, personal computers, tablet computers, smart phones, personal digital assistants (PDAs), game consoles, Internet Protocol Televisions (IPTVs), intelligent wearable devices, etc.

[0073] The electronic device 1 may also include network devices and / or user devices. Among them, the network devices include, but are 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.

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

[0075] S10: Obtain multiple positive sample images, multiple negative sample images, and product sample images.

[0076] In at least one embodiment of the present application, the sample in each positive sample image is a product appearance non-defect sample. For example, the sample in each positive sample image can be a mobile phone case without appearance defects, and the multiple positive sample images can represent product appearance non-defect images. The multiple positive sample images can be used to calculate the color difference threshold and the first threshold, and the calculation process will be introduced in detail below.

[0077] In at least one embodiment of the present application, the sample in the negative sample image is a product appearance defect sample, and the multiple negative sample images can represent product appearance defect images. The multiple negative sample images can be used to calculate the second threshold, and the calculation process will be introduced in detail below.

[0078] In at least one embodiment of the present application, the product sample image refers to an image of a sample to be detected. By using the product appearance defect detection method, it is possible to identify and detect the product sample image, so as to determine whether the product sample in the product sample image is a product appearance defect sample or a product appearance non-defect sample.

[0079] In at least one embodiment of the present application, the electronic device obtaining multiple positive sample images, multiple negative sample images, and a product sample image includes:

[0080] The electronic device controls the imaging device to capture multiple positive samples, negative samples, and product samples at the same position and angle, so as to obtain the multiple positive sample images, the multiple negative sample images, and the product sample image. The multiple positive sample images, the multiple negative sample images, and the product sample image have the same size.

[0081] S11, segment the product sample image into multiple input image blocks, and input the multiple input image blocks into a pre-trained autoencoder to obtain multiple reconstructed image blocks.

[0082] In at least one embodiment of the present application, the autoencoder includes an encoder and a decoder. Further, the encoder includes multiple hidden layers, and the decoder includes multiple operation layers.

[0083] In at least one embodiment of the present application, the multiple input image blocks refer to the image blocks obtained by segmenting the product sample image according to a preset size. Among them, the preset size can be set according to requirements, and the present application does not make any restrictions.

[0084] In at least one embodiment of the present application, the multiple reconstructed image blocks refer to the image blocks similar to the multiple input image blocks restored by the autoencoder according to the multiple input image blocks.

[0085] In this embodiment, by segmenting the product sample image into multiple input image blocks, since there is no need to scale the product sample image, it is possible to avoid losing image details and improve the detection accuracy of the product sample image.

[0086] In at least one embodiment of the present application, the electronic device inputting the multiple input image blocks into a pre-trained autoencoder to obtain multiple reconstructed image blocks includes:

[0087] The electronic device encodes each input image block to obtain a feature vector of each input image block, performs arithmetic processing on each feature vector based on the encoder in the autoencoder to obtain a plurality of latent vectors corresponding to the plurality of input image blocks. Further, the electronic device inputs the plurality of latent vectors into the decoder in the autoencoder for reconstruction processing to obtain the plurality of reconstructed image blocks.

[0088] Specifically, the electronic device performs arithmetic processing on each feature vector based on the encoder in the autoencoder to obtain a plurality of latent vectors corresponding to the plurality of input image blocks, including:

[0089] The electronic device obtains the first weight matrix and the first bias value of the plurality of hidden layers, multiplies each feature vector by the first weight matrix corresponding to the first hidden layer to obtain an operation result, adds the operation result to the first bias value to obtain the output vector of the first hidden layer, and determines the output vector of the first hidden layer as the input vector of the next hidden layer until the plurality of hidden layers all participate in the operation to obtain the output vector of the last hidden layer. Further, the electronic device determines the output vector of the last hidden layer as the latent vector corresponding to each input image block to obtain a plurality of latent vectors corresponding to the plurality of input image blocks.

[0090] Through the above embodiments, the plurality of input image blocks can be compressed into the plurality of latent vectors.

[0091] Specifically, the electronic device inputs the plurality of latent vectors into the decoder in the autoencoder for reconstruction processing to obtain the plurality of reconstructed image blocks, including:

[0092] The electronic device obtains the second weight matrix and the second bias value of the plurality of operation layers, multiplies each latent vector by the second weight matrix of the first operation layer to obtain a multiplication result, adds the multiplication result to the second bias value to obtain the feature vector of the first operation layer, and determines the feature vector of the first operation layer as the input vector of the next operation layer until the plurality of operation layers all participate in the operation to obtain the feature vector of the last operation layer. Further, the electronic device reconstructs the feature vector of the last operation layer into an image block to obtain a plurality of reconstructed image blocks corresponding to the plurality of input image blocks.

[0093] Through the above embodiments, the plurality of latent vectors can be quickly restored to a plurality of reconstructed image blocks.

[0094] In at least one embodiment of the present application, the training process of the autoencoder includes:

[0095] The electronic device divides each positive sample image into a plurality of positive sample image patches according to the preset size, and inputs the plurality of positive sample image patches into a learner for training. After the training converges, the pre-trained autoencoder is obtained.

[0096] S12. Based on the pixel points in each reconstructed image patch, determine the corresponding pixel points and the corresponding pixel differences in each input image patch.

[0097] 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 each reconstructed image patch and the pixel value corresponding to the pixel point in each input image patch. The pixel difference is used to represent the gap between the pixel values of two corresponding pixel points.

[0098] In at least one embodiment of the present application, the electronic device determines the corresponding pixel points and the corresponding pixel differences in each input image patch based on the pixel points in each reconstructed image patch, including:

[0099] The electronic device obtains the pixel value corresponding to the pixel point in each reconstructed image patch as the target pixel value, and obtains the pixel value of the corresponding pixel point in each input image patch as the feature pixel value. Further, the electronic device calculates the difference between the target pixel value and the feature pixel value to obtain the pixel difference.

[0100] Through the above implementation manner, the difference between the pixel values of the corresponding pixel points of each reconstructed image patch and each corresponding input image patch can be obtained. Furthermore, based on the pixel difference, it can be preliminarily determined whether each reconstructed image patch is similar to the corresponding input image patch.

[0101] S13. Generate a plurality of feature connected regions for each input image patch according to the plurality of positive sample images and the pixel differences.

[0102] In at least one embodiment of the present application, the plurality of feature connected regions refer to a plurality of connected regions formed by adjacent target pixel points in each input image patch. The target pixel point refers to the pixel point corresponding to the pixel difference greater than the color difference threshold in each input image patch.

[0103] In at least one embodiment of the present application, the electronic device generates a plurality of feature connected regions for each input image patch according to the plurality of positive sample images and the pixel differences, including:

[0104] The electronic device performs a subtraction operation on the pixel values corresponding to the pixel points in any two positive sample image blocks to obtain a color difference value, and counts the number of pixel points with the same color difference value in the multiple positive sample image blocks. Further, 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. Furthermore, the electronic device selects multiple consecutive color difference values from the coordinate values of 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. Then, the electronic device counts the number of elements in each feature set, and determines the feature set with the largest number of elements as the target color difference set. Furthermore, the electronic device screens out the largest color difference value from the target color difference set as the color difference threshold, determines the pixel differences less than or equal to the color difference threshold as background differences, screens out the pixel points corresponding to the background differences from each input image block as background pixel points, and determines the pixel differences greater than the color difference threshold as target differences, screens out the pixel points corresponding to the target differences from each input image block as target pixel points. Finally, the electronic device generates the multiple feature connected regions based on the adjacent target pixel points, and the background pixel points are located between any two feature connected regions.

[0105] Among them, the preset value can be set customarily, and this application does not make any restrictions.

[0106] The consecutive color difference values refer to the abscissa values corresponding to the ordinate values less than the preset value.

[0107] The pixel points in each input image block include target pixel points and background pixel points.

[0108] Through the above implementation manner, the maximum color difference value of the background pixel points in the multiple positive sample image blocks can be obtained, and multiple feature connected regions that may be defective can be screened out from each input image block through the color difference threshold.

[0109] Specifically, the coordinate values include ordinate values and abscissa values. The electronic device selects multiple consecutive color difference values from the abscissa values according to a preset value, and determines the mutually consecutive color difference values as the same set. The multiple feature sets obtained include:

[0110] The electronic device compares each ordinate value with the preset value respectively. When the ordinate value is greater than or equal to the preset value, it selects the abscissa value corresponding to the ordinate value to obtain multiple consecutive color difference values. Further, the electronic device determines the mutually consecutive color difference values as the same set to obtain multiple feature sets.

[0111] 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.

[0112] As Figure 3 shown, it is a schematic diagram of the generation of the feature connected region of the preferred embodiment of the method for detecting the appearance defects of the product of the present application. 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 each input image block 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 each input image block 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 each input image block, 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.

[0113] In this embodiment, the background pixel points in each input image block are marked with "0", and the target pixel points in each input image block are marked with "1", so that the target pixel points and the background pixel points are distinguished, and the multiple feature connected regions in each input image block are accurately screened out in this way.

[0114] S14. Generate a first threshold based on the image noise of the multiple positive sample images.

[0115] In at least one embodiment of the present application, the first threshold refers to the maximum value of the image noise of the multiple positive sample image blocks.

[0116] 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 the product sample images.

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

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

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

[0120] S15. Generating a second threshold according to the defective pixel points of the multiple negative sample images.

[0121] In at least one embodiment of the present application, the second threshold refers to the minimum area of the defective region, where the defective region refers to the region where the number of defective pixel points is greater than the first threshold. Further, the defective region includes multiple adjacent defective pixel points.

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

[0123] The electronic device divides each negative sample image into multiple negative sample image patches according to a preset size. The electronic device obtains the first pixel value of each negative sample image patch, and obtains the second pixel value of each positive sample image patch, calculates the difference between the first pixel value and the second 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, and screens out the pixel points corresponding to the feature differences from each negative sample image patch as feature pixel points. At the same time, the negative sample differences greater than the color difference threshold are determined as defect differences, and the pixel points corresponding to the defect differences are screened out from each negative sample image patch as the defect pixel points. Further still, the electronic device generates multiple second connected regions based on adjacent defect pixel points, and the feature pixel points are located between any two second connected regions. The number of pixel points in each second connected region is counted to obtain a second quantity. Further still, the electronic device determines the second connected regions corresponding to the second quantity greater than the first threshold as defect regions. Finally, the electronic device calculates the area of the defect region based on all the pixel points in the defect region to obtain a first defect area, and screens out the minimum value in the first defect area as the second threshold.

[0124] Among them, the pixel points in each negative sample image patch include feature pixel points and defect pixel points, and the feature pixel points are located between any two second connected regions.

[0125] In at least one embodiment of the present application, the defect pixel points refer to the pixel points corresponding to the defect differences in the multiple negative sample image patches. The second connected region refers to the region generated by adjacent defect pixel points in each negative sample image patch.

[0126] Through the above implementation manner, the minimum area of the defect region in the multiple negative sample image patches can be accurately obtained according to the color difference threshold and the first threshold, and the target regions larger than the minimum value can be accurately screened out from each input image patch by using the second threshold.

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

[0128] In at least one embodiment of the present application, the target region refers to the feature connected region in which the number of included pixel points is greater than the first threshold. For example, the first threshold is 5, the number of pixel points included in the feature connected region A is 4, the number of pixel points included in the feature connected region B is 6, and the number of pixel points included in the feature connected region C is 8. Therefore, the feature connected region B and the feature connected region C are both the target regions.

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

[0130] The electronic device counts the number of pixel points in each feature connected area to obtain a first quantity, and determines the feature connected area corresponding to the first quantity greater than the first threshold as the target area.

[0131] By the above implementation manner, screening the target area from the multiple feature connected areas can further determine the reasonable error in the product sample image, and improve the detection accuracy of the product sample image.

[0132] S17. Determine the detection result of the product sample in the product sample image based on the area of the target area and the second threshold.

[0133] In at least one embodiment of the present application, the detection result includes that the product sample in the product sample image is a product appearance defect sample and the position of the defect in the product sample image, or the product sample in the product sample image is a product appearance non-defect sample.

[0134] In at least one embodiment of the present application, the electronic device determining the detection result of the product sample in the product sample image based on the area of the target area and the second threshold includes:

[0135] The electronic device calculates the area of the target area according to all the pixel points in the target area to obtain a second defect area. Further, the electronic device determines the input image block corresponding to the second defect area greater than the second threshold as a defect sample block. If there is at least one defect sample block among the multiple input image blocks, the electronic device determines the product sample as a product appearance defect sample, and locates the defect position according to the position of the defect sample block in the product sample image. The electronic device determines the product appearance defect sample and the defect position as the detection result.

[0136] In at least one embodiment of the present application, the method further includes: if there is no defect sample block among the multiple input image blocks, determining the detection result as that the product sample is a product appearance non-defect sample.

[0137] By the above implementation manner, the detection result of the product sample in the product sample image can be accurately detected.

[0138] S18. The product sample image can be regarded as a known product sample image to perform product appearance defect detection on the product sample image to be measured.

[0139] If the product sample is determined to be a product sample with no appearance defects, then the product sample image is an image of no appearance defects of the product. The image of no appearance defects of the product can be regarded as a positive sample image to detect the product sample image to be measured. Or, if the product sample is a product sample with appearance defects, then the product sample image is an image of appearance defects of the product. The image of appearance defects of the product can be regarded as a negative sample image to detect the product sample image to be measured.

[0140] It can be seen from the above technical solution that the present application inputs the multiple positive sample image blocks obtained by segmentation into an autoencoder for training. Since the present application does not need to scale the product sample image, image details in the product sample image can be avoided from being lost. Further, a first threshold is calculated through the multiple positive sample image blocks, and the target region is screened out from the product sample image according to the first threshold. Since the target region contains a certain reasonable error, a second threshold determined by combining the defective pixel points in the multiple negative sample image blocks can avoid the influence of the reasonable error in the product sample image on the detection of product appearance defects, thereby improving the detection accuracy of the product sample image.

[0141] As Figure 4 shown, it is a schematic structural diagram of an electronic device according to a preferred embodiment of the method for detecting product appearance defects of the present application.

[0142] 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 program for detecting product appearance defects.

[0143] 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 those shown in the figure, or combine some components, or different components. For example, the electronic device 1 may further include input / output devices, network access devices, buses, etc.

[0144] 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, and connects various parts of the entire electronic device 1 through various interfaces and lines, and obtains the operating system of the electronic device 1 and various installed application programs, program codes, etc. For example, the processor 13 may obtain the multiple positive sample images captured by the imaging device 2 through an interface.

[0145] The processor 13 obtains the operating system of the electronic device 1 and various installed application programs. The processor 13 obtains the application programs to implement the steps in the embodiments of the above various product appearance defect detection methods, such as Figure 2 the steps shown.

[0146] 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 the instruction segments are used to describe the obtaining process of the computer program in the electronic device 1.

[0147] The memory 12 can be used to store the computer programs and / or modules. By running or obtaining the computer programs and / or modules stored in the memory 12, and invoking the data stored in the memory 12, the processor 13 realizes various functions of the electronic device 1. The memory 12 mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.); the data storage area can store data created according to the use of the electronic device. In addition, the memory 12 can 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.

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

[0149] If the modules / units integrated in the electronic device 1 are implemented in the form of software functional units and sold or used as independent products, they can 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 this application, it can also be completed by a computer program instructing relevant hardware. The computer program can 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 can be implemented.

[0150] Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code form, an obtainable 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 disc, a computer memory, a read-only memory (ROM, Read-Only Memory).

[0151] Combined with Figure 2, the memory 12 in the electronic device 1 stores a plurality of instructions to implement a method for detecting product appearance defects. The processor 13 can obtain the plurality of instructions to implement: obtaining a plurality of positive sample images, a plurality of negative sample images, and a product sample image; segmenting the product sample image into a plurality of input image blocks, and inputting the plurality of input image blocks into a pre-trained autoencoder to obtain a plurality of reconstructed image blocks; determining, based on the pixel points in each reconstructed image block, the corresponding pixel points and the corresponding pixel differences in each input image block; generating a plurality of feature connected regions for each input image block according to the plurality of positive sample images and the pixel differences; generating a first threshold based on the image noise of the plurality of positive sample images; screening target regions from the plurality of 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 plurality of negative sample images; and determining the detection result of the product sample in the product sample image based on the area of the target region and the second threshold.

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

[0153] In several embodiments provided in 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 may be other division methods in actual implementation.

[0154] 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 may be located in one place, or may be 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.

[0155] In addition, the functional modules in each embodiment of the present application 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 units can be implemented in the form of hardware, or in the form of a combination of hardware and software functional modules.

[0156] Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting. The scope of the present application is defined by the appended claims rather than the above description. Therefore, all changes falling within the meaning and scope of the equivalent elements of the claims are intended to be included in the present application. Any associated drawing marks in the claims should not be regarded as limiting the claimed rights.

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

[0158] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application and not to limit them. Although the present 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 the present application can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of the present application.

Claims

1. A method for detecting appearance defects of a product, characterized in that, The product appearance defect detection method includes: Obtaining multiple positive sample images, multiple negative sample images, and product sample images; Segmenting the product sample image into multiple input image blocks, and inputting the multiple input image blocks into a pre-trained autoencoder to obtain multiple reconstructed image blocks; Based on the pixel points in each reconstructed image block, determining the corresponding pixel points and corresponding pixel differences in each input image block; Generating multiple feature connected regions for each input image block according to the multiple positive sample images and the pixel differences; Generating a first threshold based on 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 product sample in the product sample image based on the area of the target region and the second threshold.

2. The method for detecting product appearance defects according to claim 1, wherein, The step of inputting the multiple input image blocks into a pre-trained autoencoder to obtain multiple reconstructed image blocks includes: Performing encoding processing on each input image block to obtain the feature vector of each input image block; Based on the encoder in the autoencoder, performing arithmetic processing on each feature vector to obtain multiple latent vectors corresponding to the multiple input image blocks; Inputting the multiple latent vectors into the decoder in the autoencoder for reconstruction processing to obtain the multiple reconstructed image blocks.

3. The product appearance defect detection method according to claim 1, characterized in that, The step of generating multiple feature connected regions for each input image block according to the multiple positive sample images and the pixel differences includes: Performing a subtraction operation on the pixel values corresponding to the pixel points in any two positive sample image blocks to obtain a color difference value; Counting the number of pixel points with the same color difference value in the multiple positive sample image blocks; Taking 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 continuous 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 corresponding to 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; Determining the pixel differences greater than the color difference threshold as target differences, screening out the pixel points corresponding to the target differences from each input image block as target pixel points, and generating the multiple feature connected regions according to adjacent target pixel points; Determining the pixel differences less than or equal to the color difference threshold as background differences, screening out the pixel points corresponding to the background differences from each input image block as background pixel points, and the background pixel points are located between any two feature connected regions.

4. The method for detecting product appearance defects according to claim 3, characterized in that The step of generating a first threshold based on the image noise of the multiple positive sample images includes: Determining each feature set except the target color difference set as a background color difference set; Screening out the pixel points corresponding to the color difference values in the background color difference set from the multiple positive sample image blocks as noise pixel points; Generate a plurality of first connected regions based on adjacent noise pixel points; Count the number of noise pixel points in each first connected region to obtain the image noise; Select the image noise with the largest value as the first threshold.

5. The method for detecting product appearance defects according to claim 3, wherein The generating a second threshold based on the defective pixel points of the plurality of negative sample images includes: Divide each negative sample image into a plurality of negative sample image blocks according to a preset size; Obtain the first pixel value of each negative sample image block and obtain the second pixel value of each positive sample image block; Calculate the difference between the first pixel value and the second pixel value to obtain a negative sample difference; Determine the negative sample differences greater than the color difference threshold as defective differences, screen the pixel points corresponding to the defective differences from each negative sample image block as the defective pixel points, and generate a plurality of second connected regions based on adjacent defective pixel points; Determine the negative sample differences less than or equal to the color difference threshold as feature differences, screen the pixel points corresponding to the feature differences from each negative sample image block as feature 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 based on all the pixel points in the defective region to obtain a first defective area; Take the minimum value in the first defective area as the second threshold.

6. The method for detecting product appearance defects according to claim 1, wherein, The screening a target region from the plurality of feature connected regions according to the number of pixel points in each feature connected region and the first threshold includes: Count the number of pixel points in each feature connected region to obtain a first quantity; Determine the feature connected region corresponding to the first quantity greater than the first threshold as the target region.

7. The method for detecting product appearance defects according to claim 1, characterized in that, The determining a detection result of the product sample in the product sample image based on the area of the target region and the second threshold includes: Calculate the area of the target region based on all the pixel points in the target region to obtain a second defective area; Determine the input image block corresponding to the second defective area greater than the second threshold as a defective sample block; If there is at least one defective sample block among the plurality of input image blocks, determine the product sample as a product appearance defective sample; Locate the defective position according to the position of the defective sample block in the product sample image; Determine the product appearance defective sample and the defective position as the detection result.

8. The method for detecting product appearance defects according to claim 1, characterized in that, The product sample image can be regarded as a known product sample image to perform product appearance defect detection on the product sample image to be measured.

9. An electronic device, characterized in that, The electronic device includes: A memory storing at least one instruction; and A processor that obtains the instruction stored in the memory to implement the product appearance defect detection method according to any one of claims 1 to 8.

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 obtained by a processor in the electronic device to implement the product appearance defect detection method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Surface defect detection method based on positive case training

    CN108961217A

  • Chip surface defect detection method based on a convolutional denoising auto-encoder

    CN109829903A