Defect detection method, device, electronic device and storage medium

Through the defect detection model based on the scoring network, the board defects are identified using feature vectors of multiple color spaces, which solves the complex problem of multiple color defect detection in the prior art, and realizes efficient multiple color defect detection.

CN114549418BActive Publication Date: 2025-08-22HANGZHOU WEIMING XINKE TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210073199.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-21
Publication Date
2025-08-22
Estimated Expiration
2042-01-21

AI Technical Summary

Technical Problem

The existing multiple color defect detection requires separate design of detection models and detection methods, resulting in excessive workload.

Method used

A defect detection model based on a scoring network is adopted, by obtaining marked image samples, establishing a data set, determining feature vectors using multiple color spaces, building a defect detection model, training and obtaining the quantized scores of the photos to be detected, and identifying defects of the wooden board.

Benefits of technology

It is possible to detect multiple color defects through one detection solution, which simplifies the workload and improves the detection efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114549418B_ABST
    Figure CN114549418B_ABST
Patent Text Reader

Abstract

The present invention provides a defect detection method, apparatus, electronic device, and storage medium. The method comprises: obtaining labeled image samples to establish a data set, wherein the image samples consist of two image blocks labeled as being of the same or different classes, and the image blocks have feature vectors determined based on multiple color spaces; constructing a defect detection model structure based on a scoring network; training the defect detection model structure based on the data set to obtain a defect detection model; obtaining a photograph of a wood board to be inspected, wherein the feature vector of each pixel in the photograph is determined based on the multiple color spaces; obtaining a quantized score for each pixel in the photograph of the wood board according to the defect detection model; and identifying defects in the wood board based on the quantized score of each pixel. This method only requires providing an image sample corresponding to a color defect to detect the defect, significantly reducing the workload.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image recognition technology, and in particular to a defect detection method, device, electronic device and storage medium. Background Art

[0002] Color defect recognition and detection are common quality inspection processes in industrial manufacturing. Their purpose is to: classify the colors of manufactured products into specific categories, employing corresponding production processes to ensure consistent product color or to organize them into multiple color categories for sale; identify abnormal color distributions on manufactured products, such as unevenness or dirtiness, and address them accordingly to prevent products with poor color quality from entering the market; and determine whether color characteristics of certain manufactured products are associated with certain defects, raising the question of whether detecting these characteristics can aid in detecting these defects. Existing color defect detection methods generally include depth detection, color detection, two-color detection, blue discoloration detection, mineral line detection, and color difference detection.

[0003] For the above defects, the specific method of existing detection is generally to design different detection models for different defects, and perform separate training and detection; however, this workload is too complicated for existing color defects.

[0004] In view of this, a defect detection solution that can be used for detecting defects of multiple colors is provided. Summary of the Invention

[0005] The problem solved by the present invention is that the existing multiple color defect detection requires the separate design of detection models and detection methods, which is too complicated.

[0006] To solve the above problems, the present invention first provides a defect detection method, which includes:

[0007] Acquire labeled image samples and establish a data set, wherein the image samples are composed of two image blocks and the image samples are labeled as being of the same class or different classes, and the image blocks have feature vectors determined based on multiple color spaces;

[0008] Construct a defect detection model structure based on scoring network;

[0009] Training the defect detection model structure according to the data set to obtain a defect detection model;

[0010] Acquire a photo of a wooden board to be detected, and determine a feature vector of each pixel in the photo based on the multiple color spaces;

[0011] Obtaining a quantitative score for each pixel of the wooden board photo according to the defect detection model;

[0012] According to the quantitative score of each pixel, defects of the wooden board are identified.

[0013] Preferably, the defect detection model structure includes a scoring network and a difference layer, and the data set includes a training set and a validation set;

[0014] The defect detection model structure is trained according to the data set to obtain a defect detection model, including:

[0015] Traversing the training set, and obtaining a color score for each of the two image blocks of the image sample according to the scoring network;

[0016] Determining a color difference of the image sample by the difference layer according to the color scores of the two image blocks;

[0017] Calculating a loss value using a loss function according to the color difference and annotation of the image samples;

[0018] Updating the parameters of the defect detection model structure by the loss value;

[0019] Traversing the verification set, and determining the color difference of the image samples in the verification set according to the currently updated defect detection model structure;

[0020] According to the color differences and annotations of the image samples in the validation set, the accuracy of the color differences is calculated;

[0021] The defect detection model structure is iterated according to the accuracy to obtain the defect detection model.

[0022] Preferably, the plurality of color spaces include at least three of an RGB color space, an HSV color space, an HLS color space, a Lab color space, a Luv color space, a YCrCb color space, and an XYZ color space.

[0023] Preferably, the color score of the image block is in the zero-symmetric interval [-10, 10].

[0024] Preferably, obtaining the labeled image samples includes:

[0025] Collect multiple wooden board photos, and the depth of different wooden board photos is different;

[0026] Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks into image samples;

[0027] If the two image blocks of the image sample come from the same wooden board photo, the image sample is marked as the same class; if the two image blocks of the image sample come from different wooden board photos, the image sample is marked as different classes.

[0028] Preferably, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0029] Get the number of categories for deep and shallow classification;

[0030] Dividing the zero symmetric interval corresponding to the quantization score into equal parts according to the number of categories;

[0031] Calculating an average quantized score of the wooden board photo according to the quantized score of each pixel point of the wooden board photo;

[0032] The depth category of the wooden board photo to be detected is determined according to the equally divided intervals and the average quantization score.

[0033] Preferably, obtaining the labeled image samples includes:

[0034] Collect multiple wooden board photos, and the colors of different wooden board photos are different;

[0035] Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks into image samples;

[0036] If the two image blocks of the image sample come from the same wooden board photo, the image sample is marked as the same class; if the two image blocks of the image sample come from different wooden board photos, the image sample is marked as different classes.

[0037] Preferably, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0038] Get the number of categories for color classification;

[0039] Dividing the zero symmetric interval corresponding to the quantization score into equal parts according to the number of categories;

[0040] Calculating an average quantized score of the wooden board photo according to the quantized score of each pixel point of the wooden board photo;

[0041] The color category to which the wood board photo to be detected belongs is determined according to the equally divided intervals and the average quantization score.

[0042] Preferably, obtaining the labeled image samples includes:

[0043] Collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have two tones and a clear boundary between the two tones;

[0044] Cut out multiple image blocks from each wood board photo, and randomly combine the image blocks in the same wood board photo into image samples;

[0045] If the two image blocks of the image sample come from the same hue area in the same wooden board photo, the image sample is marked as the same class; if the two image blocks of the image sample come from different hue areas in the same wooden board photo, the image sample is marked as different classes.

[0046] Preferably, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0047] According to the quantitative score and coordinates of each pixel point in the wooden board photo, it is divided into two categories by clustering;

[0048] Based on the quantized scores of the pixels in the category, the average quantized scores of the two categories are calculated respectively, and the average quantized score difference between the two categories is determined;

[0049] When the difference in the average quantitative scores of the two categories is greater than a first preset threshold, it is determined that the wooden board photo has a two-color defect.

[0050] Preferably, the identifying defects of the wooden board according to the quantized score of each pixel point further includes:

[0051] generating a quantitative score map of the wooden board photo according to the quantitative scores of the pixels;

[0052] According to the category of the pixel points, a straight line is detected on the quantized score image by using an edge detection algorithm as a dividing line of the two-color defect;

[0053] The width of the two colors in the wooden board photo is determined according to the dividing line.

[0054] Preferably, obtaining the labeled image samples includes:

[0055] Collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have blue discoloration and the degree of blue discoloration in different wooden board photos is inconsistent;

[0056] Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks into image samples;

[0057] If the two image blocks of the image sample are both from the non-blue-shifted area or both from the blue-shifted area and have the same degree of blue shift, the image sample is marked as the same type; otherwise, the image sample is marked as different types.

[0058] Preferably, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0059] According to the quantitative score and coordinates of each pixel point of the wooden board photo, the wooden board photo is divided into multiple categories by clustering;

[0060] According to the quantization scores of the pixels in the category, the average quantization score of each category is calculated;

[0061] The category with the lowest average quantization score is used as the wood board reference color, and the category whose average quantization score difference with the wood board reference color is greater than a second preset threshold is determined as the blue-discoloration category;

[0062] The degree and area of ​​blue change of each blue change category were determined based on the coordinates and average quantization scores of the pixel points of the blue change category.

[0063] Preferably, obtaining the labeled image samples includes:

[0064] collecting a plurality of wooden board photos, wherein the wooden board photos have mineral lines on the wooden board;

[0065] Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks into image samples;

[0066] If the two image blocks of the image sample are both from the non-mineral line area or both from the mineral line area and have the same color, the image sample is marked as the same type; otherwise, the image sample is marked as different types.

[0067] Preferably, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0068] According to the quantitative score and coordinates of each pixel point of the wooden board photo, the wooden board photo is divided into multiple categories by clustering;

[0069] According to the quantization scores of the pixels in the category, the average quantization score of each category is calculated;

[0070] The category with the lowest average quantitative score is used as the wood board reference color, and the category with a difference in average quantitative score from the wood board reference color greater than a third preset threshold is determined as the mineral line category;

[0071] According to the coordinates of the pixel points of the mineral line category, the minimum circumscribed rectangle of each mineral line category is determined, and the length of the minimum circumscribed rectangle is the length of the mineral line.

[0072] Preferably, obtaining the labeled image samples includes:

[0073] Collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have two or more tones;

[0074] Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks of the same wood board photo into image samples;

[0075] If the two image blocks of the image sample are from the same wooden board photo and have the same or similar tones, the image sample is marked as the same category; if the two image blocks of the image sample are from the same wooden board photo and have different tones, the image sample is marked as different categories.

[0076] Preferably, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0077] Divide the wooden board photo into at least five categories by clustering according to the quantized score and coordinates of each pixel point, and determine the adjacent relationship in the category space;

[0078] According to the quantization scores of the pixels in the category, the average quantization score of each category is calculated;

[0079] Calculating the score difference between the average quantized scores of adjacent categories based on the average quantized score of each category and the adjacent relationship;

[0080] If the score differences of all adjacent categories are smaller than a fourth preset threshold, and the score difference between the maximum and minimum values ​​in the average quantization scores of all categories is larger than a fifth preset threshold, it is determined that the wooden board photo has color difference.

[0081] Secondly, a defect detection device is provided, comprising:

[0082] A sample acquisition module is used to acquire labeled image samples and establish a data set, wherein the image samples are composed of two image blocks and the image samples are labeled as the same or different classes, and the image blocks have feature vectors determined based on multiple color spaces;

[0083] A model building module, which is used to build a defect detection model structure based on a scoring network;

[0084] A model training module, which is used to train the defect detection model structure according to the data set to obtain a defect detection model;

[0085] a photo acquisition module, configured to acquire a photo of a wooden board to be detected, wherein a feature vector of each pixel in the photo of the wooden board is determined based on the multiple color spaces;

[0086] a wood board detection module, configured to obtain a quantitative score for each pixel of the wood board photo according to the defect detection model;

[0087] The defect recognition module is used to identify defects of the wooden board according to the quantitative score of each pixel point.

[0088] Again, an electronic device is provided, comprising a computer-readable storage medium storing a computer program and a processor, wherein the computer program is read and executed by the processor to implement the method described above.

[0089] Finally, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is read and executed by a processor, the method described above is implemented.

[0090] In this way, only an image sample corresponding to a color defect is needed to detect the defect, which greatly reduces the workload. BRIEF DESCRIPTION OF THE DRAWINGS

[0091] Figure 1 is a flow chart of a defect detection method according to an embodiment of the present invention;

[0092] Figure 2 is a photograph of a wooden board according to an embodiment of the present invention;

[0093] Figure 3 for Figure 2 Quantitative score map corresponding to the middle wood board photo;

[0094] Figure 4 is a flow chart of a defect detection method S300 according to an embodiment of the present invention;

[0095] Figure 5 is a flowchart of a defect detection method S100 according to an embodiment of the present invention;

[0096] Figure 6 is a flowchart of a defect detection method S600 according to an embodiment of the present invention;

[0097] Figure 7 is a flowchart of a defect detection method S100 according to another embodiment of the present invention;

[0098] Figure 8 is a flowchart of a defect detection method S600 according to another embodiment of the present invention;

[0099] Figure 9 is a flow chart of a defect detection method S100 according to yet another embodiment of the present invention;

[0100] Figure 10 is a flow chart of a defect detection method S600 according to yet another embodiment of the present invention;

[0101] Figure 11 is another flow chart of a defect detection method S600 according to yet another embodiment of the present invention;

[0102] Figure 12is a flow chart of a defect detection method S100 according to yet another embodiment of the present invention;

[0103] Figure 13 is a flowchart of a defect detection method S600 according to yet another embodiment of the present invention;

[0104] Figure 14 is a flow chart of a defect detection method S100 according to an embodiment of the present invention;

[0105] Figure 15 is a flow chart of a defect detection method S600 according to an embodiment of the present invention;

[0106] Figure 16 is another flow chart of the defect detection method S100 according to an embodiment of the present invention;

[0107] Figure 17 is another flow chart of the defect detection method S600 according to an embodiment of the present invention;

[0108] Figure 18 is a structural block diagram of a defect detection device according to an embodiment of the present invention;

[0109] Figure 19 FIG. 4 is a structural block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0110] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0111] Color defect recognition and detection are common quality inspection processes in the industrial manufacturing sector. Their purpose is to: 1. Classify the colors of manufactured products into categories, adopt corresponding production processes for processing, ensure product color consistency, or divide them into multiple categories for sale by color; 2. Detect certain abnormal color distributions on manufactured products, such as unevenness, dirtiness, etc., and deal with them accordingly to prevent manufactured products with poor color quality from entering the market; 3. The color characteristics of certain manufactured products are related to certain defects. Can detecting color characteristics assist in detecting related defects? The present invention proposes a general method for color recognition and defect detection, which is applicable to scenarios requiring color detection in various processing and manufacturing industries. To explain the invention in detail, this document uses the surface color detection of wooden flooring as an example.

[0112] Wooden boards will develop different colors or color defects during their growth process. In the process of processing wooden floors, wooden boards of different colors need to be separated for processing into finished products of different colors. When providing finished products to consumers, similar colors are provided to avoid color differences when the wooden boards are laid. Color defects need to be identified and treated by painting or other methods to make them consistent with the surrounding colors. If not treated, color differences will also appear on the finished wooden boards.

[0113] Existing color defect detection generally includes depth detection, color detection, two-color detection, blue change detection, mineral line detection, and color difference detection.

[0114] For the above defects, the specific method of existing detection is generally to design different detection models for different defects, and perform separate training and detection; however, this workload is too complicated for existing color defects.

[0115] If there is a defect detection solution that can be used for detecting multiple color defects separately, then through one detection solution, only different corresponding samples need to be used to detect the defect, which greatly reduces the workload.

[0116] The embodiment of the present application provides a defect detection method, which can be performed by a defect detection device, and the defect detection device can be integrated into electronic devices such as computers, servers, and computers. Figure 1 As shown, it is a flow chart of a defect detection method according to an embodiment of the present invention; wherein the defect detection method includes:

[0117] S100, obtaining labeled image samples and establishing a data set, wherein the image samples are composed of two image blocks and the image samples are labeled as being of the same or different classes, and the image blocks have feature vectors determined based on multiple color spaces;

[0118] An image sample is composed of two image blocks and marked as the same or different classes. In this way, during training, the features are concentrated on the differences between the two image blocks of the same or different classes. This difference is present in the characteristics targeted by various defect detections. In this way, the applicability of the training of this type of image sample can be increased, and it can be applied to depth detection, color detection, two-color detection, blue discoloration detection, mineral line detection, and color difference detection.

[0119] In this embodiment, the neural network relies on a certain amount of labeled data, so it is necessary to obtain photos of defective samples from real scenes. The photos can be obtained by taking photos according to a designed imaging plan.

[0120] In order to obtain image samples, we process the above photos as follows: according to the specific task requirements, we cut out image blocks from the photos, and each two image blocks form a pair. A pair of image blocks has two labeling results, the same category or different categories. Specifically, if the task is to identify the depth of color, the same depth is the same category, and different depths are different categories. If the task is to identify two colors, the image blocks on the same side of the two-color dividing line of the wooden board are of the same category, and the image blocks on both sides of the dividing line are of different categories.

[0121] Preferably, the multiple color spaces are multiple color spaces including at least three of RGB color space, HSV color space, HLS color space, Lab color space, Luv color space, YCrCb color space and XYZ color space.

[0122] Among them, the RGB color space is based on the three basic colors R (Red), G (Green), and B (Blue), which are superimposed to varying degrees to produce rich and wide colors, so it is commonly known as the three-primary color mode.

[0123] Among them, the HLS color space also has three components: hue, saturation, and lightness.

[0124] The HSV (Hue, Saturation, Value) color space, also known as the Hexcone Model, was created by AR Smith in 1978 based on the intuitive characteristics of color. The color parameters in this color space are: hue (H), saturation (S), and value (V).

[0125] Among them, the L component in the Lab color space is used to represent the brightness of the pixel, and its value range is [0,100], representing from pure black to pure white; a represents the range from red to green, and its value range is [127,-128]; b represents the range from yellow to blue, and its value range is [127,-128].

[0126] The LUV color space stands for the CIE 1976 (L*, u*, v*) (also known as CIELUV) color space. L* represents the brightness of an object, while u* and v* represent chromaticity. For general images, the values ​​of u* and v* range from -100 to +100, and the brightness ranges from 0 to 100.

[0127] YCbCr is a color space commonly used in continuous image processing in films and digital photography systems. Y represents the brightness (luma) component of a color, while CB and CR represent the blue and red color density offsets. Y represents the Y value of the tristimulus values, representing brightness, while x and y reflect the color's chromaticity.

[0128] Among them, the XYZ color space is a new colorimetric system established based on the RGB system using three imaginary primary colors X, Y, and Z.

[0129] Preferably, in addition to the color space mentioned above, the color space may also be any other artificially designed color space.

[0130] In this way, the image block determines the feature vector based on multiple color spaces. By increasing the number of color spaces, the richness of the feature vector of the image block is increased, thereby increasing its scope of application and applying it to depth detection, color detection, two-color detection, blue change detection, mineral line detection, and color difference detection.

[0131] It should be noted that the above color spaces are merely an exhaustive list of existing color spaces, that is, at least three color spaces are selected from the existing color spaces as color spaces for generating feature vectors, and this does not limit the color spaces that can be selected.

[0132] Preferably, the image block has a feature vector determined based on multiple color spaces, specifically by converting the image block into multiple color spaces, calculating the value of each component in each color space, and summarizing the values ​​of all components to form the feature vector.

[0133] Preferably, an image block has multiple pixels, and the value of each component calculated after the image block is converted into multiple color spaces may be the average value of the component calculated after all pixels of the image block are converted into corresponding color spaces.

[0134] S200, building a defect detection model structure based on a scoring network;

[0135] S300, training the defect detection model structure according to the data set to obtain a defect detection model;

[0136] It should be noted that the obtained defect detection model can process the input feature vector to obtain the corresponding score, and can be regarded as a trained scoring model.

[0137] S400, obtaining a photo of a wooden board to be detected, and determining a feature vector of each pixel in the wooden board photo based on the multiple color spaces;

[0138] The wooden board photo may be a wooden floor photo, which can be obtained through conventional imaging design schemes to ensure that a clear and undistorted photo of the wooden floor surface can be obtained. The specific acquisition method will not be repeated here.

[0139] S500, obtaining a quantitative score for each pixel of the wooden board photo according to the defect detection model;

[0140] S600: Identify defects of the wooden board according to the quantized score of each pixel.

[0141] In this way, only an image sample corresponding to a color defect is needed to detect the defect, which greatly reduces the workload.

[0142] In one embodiment, S600, identifying defects of the wooden board according to the quantitative score of each pixel point further includes: performing cluster analysis according to the quantitative score of each pixel point.

[0143] The cluster analysis is performed based on the quantitative score of each pixel point, specifically: based on the quantitative score of each pixel point, a quantitative score map of the wooden board photo can be obtained; through a clustering algorithm, all color scores are clustered into different categories to obtain clustering results, one category is the basic color of the wooden board, and the other categories are color defects; by analyzing the clustering results, the specific defects of the wooden board are obtained.

[0144] For example, Figure 2 and Figure 3 As shown, Figure 2 For wooden board photos, Figure 3 This is the quantitative score map corresponding to the wooden board photo.

[0145] Preferably, all color scores are clustered into different categories through a clustering algorithm to obtain clustering results, specifically: the coordinates x, y of each pixel point and the score of the point are encoded together into a three-dimensional vector, and the three dimensions are normalized separately to avoid the influence of data scale differences on clustering, so that the data points to be clustered are the unordered three-dimensional data points of all pixel points; determine the optimal number of clusters; perform clustering, and obtain clustering results.

[0146] A significant difference between the quantitative score map type of data and the typical data points used for clustering is that each point in the color score map contains implicit location information.

[0147] In this way, location information must be included in clustering to obtain better clustering results.

[0148] Preferably, clustering is performed using one of the following algorithms: K-means, DBSCAN, OPTICS, mean shift clustering, and maximum expectation clustering based on a Gaussian mixture model; all of the clustering algorithms may also be tested to select the best method.

[0149] Preferably, all color scores are clustered into different categories through a clustering algorithm, and after the clustering results are obtained, the clustering results are restored.

[0150] Preferably, the method for determining the optimal number of clusters is: exhaustively enumerate 1 to N, calculate the clustering results under various possibilities, and then use the BIC indicator to determine the optimal number of clusters.

[0151] Preferably, the method for determining the optimal number of clusters and the clustering method adopted can be replaced by any typical corresponding method.

[0152] In practice, we observe that a wooden board usually has no more than three color categories and produces no more than five color blocks, so N can be directly set to 5-10; this eliminates the need for complex algorithms to determine the number of clusters, greatly improving the clustering speed.

[0153] Preferably, the clustering results are restored, specifically: after obtaining the clustering results of all data points, we restore each point to its original image position according to its pixel coordinates, thus obtaining a clustering map of each pixel point of the wooden board.

[0154] Preferably, for different task objectives, different analysis methods are used according to customer needs to obtain a detailed description of the defects from the score cluster diagram. For example, for two-color defects, an edge detection algorithm such as the Canny operator is used to detect the edges of the two colors from the cluster diagram, and then the width of the two colors is calculated. For blue-discoloration defects, the mean of the blue component in each class is calculated, where the block with the lowest blue component is the base color of the wood board, and the other blocks are blue-discoloration blocks. The area and degree of blue-discoloration of the blue-discoloration blocks are calculated.

[0155] Preferably, the defect detection model structure includes a scoring network and a difference layer, and the data set includes a training set and a validation set;

[0156] like Figure 4 As shown, the step S300 of training the defect detection model structure according to the data set to obtain a defect detection model includes:

[0157] S310, traversing the training set and obtaining a color score of each image block in the two image blocks of the image sample according to the scoring network;

[0158] Preferably, the data in the dataset is divided into a training set and a validation set in a ratio of 8:2.

[0159] Preferably, the specific structure of the scoring network is: the feature vector of the image block is used as input, followed by several fully connected blocks, each fully connected block includes the following layers: batch normalization layer, fully connected layer, activation function layer; the last fully connected block is followed by an output layer, the output layer is a fully connected layer that does not contain an activation function, the fully connected layer contains only one neuron, and the output is the color score of the feature vector of the image block under the task.

[0160] Preferably, in the specific structure of the scoring network, 3-5 fully connected blocks are used, and the number of neurons in the fully connected layer in each block is set to between 5 and 20.

[0161] Preferably, the color score of the image block is in the interval [-10, 10] symmetrical to zero, so that a relatively linear color score can be obtained.

[0162] Preferably, the last layer of the output layer of the scoring network is set as a clipping layer, so as to clip the output into a zero-symmetric interval.

[0163] S320, determining a color difference of the image sample by the difference layer according to the color scores of the two image blocks;

[0164] In this embodiment, a dual-stream network is used for two image blocks of an image sample, that is, the two image blocks in the image pair are respectively input into the scoring network, and the two scoring results are subtracted as the color difference of the two image blocks.

[0165] Through two scoring methods, we can obtain more linear results and achieve better training and recognition effects.

[0166] S330, calculating a loss value using a loss function according to the color difference and annotation of the image sample;

[0167] In this embodiment, the hinge loss function is selected to calculate the loss. If the labeling results of the image pair are the same, the hinge loss is used to limit the color difference to be less than a certain threshold. If the labeling results of the image pair are different classes, the hinge loss is used to limit the color difference to be greater than a certain threshold.

[0168] Among them, the hinge loss function is a hinge loss function. In machine learning, hinge loss is used as a loss function and is usually used in the maximum-margin algorithm.

[0169] Preferably, the optimal results of the above two thresholds are obtained through grid search.

[0170] Preferably, the hinge loss function can be replaced by any loss function that satisfies the following conditions: different degrees of punishment or encouragement are imposed on samples smaller than a specific threshold and samples larger than a specific threshold.

[0171] S340, updating the parameters of the defect detection model structure according to the loss value;

[0172] In this embodiment, in combination with step S330, the gradient of the loss is calculated by the BP algorithm, and the parameters of the defect detection model structure are updated by back propagation.

[0173] The BP algorithm is a widely used parameter learning algorithm. It is a multi-layer feedforward neural network trained according to the back propagation of error algorithm. The learning process of the BP algorithm consists of two steps: forward propagation of the signal (calculating the loss) and back propagation of the error (returning the error).

[0174] Forward propagation (FP): In this process, we calculate the final output value and the loss between the output value and the actual value based on the input sample, the given initial weight values ​​and the bias value. If the loss value is not within the given range, the backward propagation process is carried out; otherwise, the weight and bias value updates are stopped.

[0175] Back propagation BP (back propagation error): The output is propagated back to the input layer layer by layer through the hidden layer in some form, and the error is distributed to all units in each layer, so as to obtain the error signal of the units in each layer. This error signal is used as the basis for correcting the weights of each unit.

[0176] S350, traversing the verification set, and determining the color difference of the image samples in the verification set according to the currently updated defect detection model structure;

[0177] S360, calculating the accuracy of the color difference based on the color difference and annotation of the image samples in the validation set;

[0178] In this embodiment, combined with the above-mentioned training process, after several steps of training, the training results are evaluated. The evaluation method is to calculate the color difference of the image samples in the verification set. The difference of image samples with the same type of annotation is required to be less than a threshold, and the difference of image samples with different types of annotation is required to be greater than a threshold, and the accuracy is calculated.

[0179] Preferably, in this embodiment, the threshold is 2.

[0180] Preferably, in this embodiment, the difference between image samples with the same type of annotations is required to be less than a threshold value, which is 1; the difference between image samples with different types of annotations is required to be greater than a threshold value, which is 2.

[0181] S370: Iterate the defect detection model structure according to the accuracy to obtain the defect detection model.

[0182] In this embodiment, steps S310-S360 are repeated until the network converges to a set of optimal parameters.

[0183] Preferably, the specific structure of the scoring network can be replaced by any other network structure, as long as the input is the color component features of each color space and the output is a scoring result.

[0184] An embodiment of the present application provides another defect detection method, which is similar to the defect detection method described above, except that this embodiment is a defect detection method that applies it to the field of depth detection.

[0185] In this embodiment, it is essentially necessary to determine the overall depth of the entire wooden board surface.

[0186] like Figure 5 As shown, S100, obtaining the labeled image sample includes:

[0187] S101, collecting multiple wooden board photos, where different wooden board photos have different depths;

[0188] In this embodiment, the multiple wooden board photos should cover all shades of wooden boards as much as possible; as image samples, only after the image samples cover all possible shades as much as possible, the trained model can cover wooden board photos of all possible shades.

[0189] S102, cutting out a plurality of image blocks from each wood board photo, and randomly combining the image blocks in pairs to form image samples;

[0190] S103 : If the two image blocks of the image sample come from the same wood board photo, the image sample is marked as the same class; if the two image blocks of the image sample come from different wood board photos, the image sample is marked as different classes.

[0191] Preferably, the wooden board photo includes a double-depth wooden board photo (a wooden board photo having different depth areas). When two image blocks of an image sample may come from a double-depth wooden board photo, if the two image blocks of the image sample come from different depth areas of the same double-depth wooden board photo, the image sample is labeled as a different class.

[0192] By setting up double deep and shallow boards, it is easier to achieve the preset training effect.

[0193] Preferably, the cut image blocks are combined into image samples in pairs by traversing. In other words, any image block is combined with other image blocks in pairs to form an image sample. In this way, the best training effect is achieved.

[0194] Preferably, dozens of wooden floor photos are collected, requiring that wooden floors of various shades are covered as much as possible; several (5-10) image blocks are cut out from each photo; and the image blocks are combined to form pairs. If two blocks come from the same wooden board of consistent shade, they are marked as the same type; if they come from two wooden boards of inconsistent shades, they are marked as different types.

[0195] When constructing and training the neural network, the neural network is constructed and trained as described above, and the floating-point number output in the interval [-10, 10] represents its depth score.

[0196] like Figure 6 As shown, in S600, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0197] S601, obtaining the number of categories for depth classification;

[0198] S602, dividing the zero symmetric interval corresponding to the quantization score into equal parts according to the number of categories;

[0199] S603, calculating an average quantized score of the wooden board photo according to the quantized score of each pixel point in the wooden board photo;

[0200] S604: Determine the lightness or darkness category of the wood board photo to be detected according to the equally divided intervals and the average quantization score.

[0201] Specifically, according to customer requirements, the depth is divided into N categories, that is, the interval [-10,10] is divided into N equal parts. After obtaining the depth score of each pixel of any input wooden board image, the depth score is averaged and the depth is evaluated based on which interval it falls into.

[0202] An embodiment of the present application provides another defect detection method, which is similar to the defect detection method described above, except that this embodiment is a defect detection method applied to the field of color detection.

[0203] In this embodiment, the overall color of the entire wooden board surface is essentially determined.

[0204] like Figure 7 As shown, S100, obtaining the labeled image sample includes:

[0205] S111, collecting multiple wooden board photos, where different wooden board photos have different colors;

[0206] In this embodiment, the multiple wooden board photos should cover all colors of wooden boards as much as possible; as image samples, only after the image samples cover all possible colors as much as possible, the trained model can cover wooden board photos of all possible colors.

[0207] S112, cutting out a plurality of image blocks from each wood board photo, and randomly combining the image blocks in pairs to form image samples;

[0208] If the two image blocks of the image sample come from the same wooden board photo, the image sample is marked as the same class; if the two image blocks of the image sample come from different wooden board photos, the image sample is marked as different classes.

[0209] Preferably, the wood board photo includes a two-color wood board photo. When the two image blocks of the image sample may come from the two-color wood board photo, if the two image blocks of the image sample come from different color areas of the same two-color wood board photo, the image sample is marked as a different class.

[0210] By setting a two-color plate, it is easier to achieve the preset training effect.

[0211] Preferably, the cut image blocks are combined into image samples in pairs by traversing. In other words, any image block is combined with other image blocks in pairs to form an image sample. In this way, the best training effect is achieved.

[0212] Preferably, dozens of wooden floor photos are collected, requiring to cover wooden floors of various colors as much as possible; several (5-10) image blocks are cut out from each photo; the image blocks are combined to form pairs, and if the two blocks come from the same wooden board with the same color, they are marked as the same type; if they come from two wooden boards with inconsistent colors, they are marked as different types.

[0213] When constructing and training the neural network, the neural network is constructed and trained as described above, and the floating-point number output in the interval [-10, 10] represents its color score.

[0214] like Figure 8 As shown, in S600, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0215] S611, obtaining the number of categories for color classification;

[0216] S612, dividing the zero symmetric interval corresponding to the quantization score into equal parts according to the number of categories;

[0217] S613, calculating an average quantized score of the wooden board photo according to the quantized score of each pixel point in the wooden board photo;

[0218] S614 , determining the color category to which the wood board photo to be detected belongs based on the equally divided intervals and the average quantization score.

[0219] Specifically, according to customer requirements, colors are divided into N categories, that is, the interval [-10, 10] is divided into N equal parts. After obtaining the score of each pixel of any input wooden board image, the scores are averaged and the color is evaluated based on which interval it falls into.

[0220] An embodiment of the present application provides another defect detection method, which is similar to the defect detection method described above, except that this embodiment is a defect detection method applied to the field of two-color detection.

[0221] In this embodiment, it is essentially necessary to detect whether the entire wooden board surface has two colors; further, if it exists, the width of the two colors can be calculated.

[0222] like Figure 9 As shown, S100, obtaining the labeled image sample includes:

[0223] S121, collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have two tones with a clear boundary between the two tones;

[0224] In this embodiment, the multiple wooden board photos should cover two-color wooden boards with a wider color range as much as possible; as image samples, only after the image samples cover two-color wooden boards of all possible colors as much as possible, the trained model can cover two-color wooden board photos of all possible colors.

[0225] S122, cutting out a plurality of image blocks from each wood board photo, and randomly combining the image blocks in the same wood board photo into image samples;

[0226] If the two image blocks of the image sample come from the same hue area in the same wooden board photo, the image sample is marked as the same class; if the two image blocks of the image sample come from different hue areas in the same wooden board photo, the image sample is marked as different classes.

[0227] Preferably, the cut image blocks are combined into image samples in pairs by traversing. In other words, any image block is combined with other image blocks in pairs to form an image sample. In this way, the best training effect is achieved.

[0228] Preferably, dozens of wooden floor photos are collected, and the photos are required to be collected from wooden boards with two colors, and try to cover two-color wooden boards with a wider color range; several (5-10) image blocks are cut out from each photo; the image blocks are combined to form pairs, and if two blocks come from the same side of the same two-color wooden board, they are marked as the same type; if they come from opposite sides of the same two-color wooden board, they are marked as different types.

[0229] like Figure 10 As shown, in S600, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0230] S621, dividing the wooden board photo into two categories by clustering according to the quantized score and coordinates of each pixel point;

[0231] Preferably, a clustering algorithm is constructed according to the method described above, and the number of clusters is set to 2. For any input wooden board image, the clustering algorithm divides the pixels on the wooden board into two categories. If there is a two-color defect, the two categories contain the pixels of each of the two colors.

[0232] In this way, two-color defects can be determined by clustering algorithms.

[0233] S622, calculating the average quantization scores of the two categories based on the quantization scores of the pixels in the category, and determining the average quantization score difference between the two categories;

[0234] S623: When the difference in the average quantitative scores of the two categories is greater than a first preset threshold, determine that the wooden board photo has a two-color defect.

[0235] When constructing and training the neural network, the neural network is constructed and trained as described above, and the floating-point number output in the interval [-10, 10] represents its two-color score.

[0236] like Figure 11 As shown, in S600, identifying defects of the wooden board according to the quantized score of each pixel point further includes:

[0237] S624, generating a quantized score map of the wooden board photo according to the quantized scores of the pixels;

[0238] There is no temporal sequence relationship between the step of generating the quantitative score map of the wooden board photo and steps S621, S622, and S623. In this embodiment, there is no restriction on the execution order of S624 and steps S621, S622, and S623.

[0239] S625 , detecting a straight line on the quantized score image using an edge detection algorithm according to the category of the pixel point as a boundary line of the two-color defect;

[0240] S626: Determine the width of the two colors in the wooden board photo according to the dividing line.

[0241] An embodiment of the present application provides another defect detection method, which is similar to the defect detection method described above, except that this embodiment is a defect detection method applied to the field of blue discoloration detection.

[0242] The blue stain is a defect in which certain areas of a wooden board are blue. This embodiment essentially detects whether there is blue stain. If there is, the area of ​​each blue stain block can be further calculated.

[0243] like Figure 12 As shown, S100, obtaining the labeled image sample includes:

[0244] S131, collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have blue discoloration, and the degree of blue discoloration in different wooden board photos is inconsistent;

[0245] In this embodiment, the multiple wooden board photos should cover blue-discolored wooden boards with a wider color range as much as possible; as image samples, only after the image samples cover all possible blue-discolored wooden boards with a wider color range as much as possible, the trained model can cover all wooden board photos with a wider color range.

[0246] S132, cutting out a plurality of image blocks from each wood board photo, and randomly combining the image blocks in pairs to form image samples;

[0247] S133: If the two image blocks of the image sample are both from the non-blue-shifted area or both from the blue-shifted area and have the same degree of blue-shifted, the image sample is marked as the same type; otherwise, the image sample is marked as different types.

[0248] Preferably, the cut image blocks are combined into image samples in pairs by traversing. In other words, any image block is combined with other image blocks in pairs to form an image sample. In this way, the best training effect is achieved.

[0249] Preferably, dozens of wooden flooring photos are collected, and the photos are required to be collected from wooden boards with blue discoloration, and blue discoloration wooden boards with a wider color range are covered as much as possible; a number of (2-10) image blocks are cut out from each photo; the image blocks are combined to form pairs, and if neither block is blue-discolored, they are marked as the same type; if both blocks are blue-discolored and the degree of blue discoloration is the same, they are also marked as the same type; if both blocks are blue-discolored and the degree of blue discoloration is different, they are marked as different types; if one block is blue-discolored and the other is not blue-discolored, they are also marked as different types.

[0250] When constructing and training the neural network, the neural network is constructed and trained as described above, and the floating-point number output in the interval [-10, 10] represents its blue-variant score.

[0251] like Figure 13 As shown, in S600, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0252] S631, dividing the wooden board photo into multiple categories by clustering according to the quantized score and coordinates of each pixel point;

[0253] S632, calculating an average quantization score for each category based on the quantization scores of the pixels in the category;

[0254] S633, determining the category with the lowest average quantization score as the wood board reference color, and determining the category whose average quantization score difference with the wood board reference color is greater than a second preset threshold as the blue-discoloration category;

[0255] S634 , determining the degree of blue shift and the blue shift area of ​​each blue shift category according to the coordinates and average quantization scores of the pixel points of the blue shift category.

[0256] Preferably, a clustering algorithm is constructed according to the method described above, and the optimal number of clusters is obtained by searching. For any input wooden board image, the clustering algorithm divides the pixels on the wooden board into several categories; the average blue change score of the pixels in each category is calculated, and the one with the lowest score is used as the wooden board benchmark. Other blocks with average blue change scores higher than the benchmark value by more than a specific threshold are detected as blue change blocks, and the number of pixels in each block is counted to represent its area.

[0257] An embodiment of the present application provides another defect detection method, which is similar to the defect detection method described above, except that this embodiment is a defect detection method applied to the field of mineral line detection.

[0258] Mineral lines are dark brown stripes that are usually found on wooden boards. This embodiment essentially detects whether mineral lines exist. If they do exist, the color depth and length of each mineral line can be further calculated.

[0259] like Figure 14 As shown, S100, obtaining the labeled image sample includes:

[0260] S141, collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have mineral lines on them;

[0261] S142, cutting out a plurality of image blocks from each wood board photo, and randomly combining the image blocks in pairs to form image samples;

[0262] S143 : If the two image blocks of the image sample are both from the non-mineral line area or both from the mineral line area and have the same color, the image sample is marked as the same type; otherwise, the image sample is marked as different types.

[0263] Preferably, dozens of wooden flooring photos are collected, and the photos are required to be collected from wooden boards with mineral lines, and the mineral line wooden boards with a wider color range are covered as much as possible; several (2-10) image blocks are cut out from each photo. Because mineral lines usually appear as line segments, when cutting image blocks, try to find an area close to a rectangle to ensure that the entire block is filled with mineral lines; the image blocks are combined to form pairs. If neither block is a mineral line, they are marked as the same type. If both blocks are mineral lines and the degree is consistent, they are also marked as the same type. If both blocks are mineral lines and the degree is inconsistent, they are marked as different types. If one of the two blocks is a mineral line and the other is a mineral line, they are also marked as different types.

[0264] When constructing and training the neural network, the neural network is constructed and trained as described above, and the floating-point number output in the interval [-10, 10] represents its mineral line score.

[0265] like Figure 15 As shown, in S600, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0266] S641, dividing the wooden board photo into multiple categories by clustering according to the quantized score and coordinates of each pixel point;

[0267] S642, calculating an average quantization score for each category based on the quantization scores of the pixels in the category;

[0268] S643, determining the category with the lowest average quantization score as the wood board reference color, and determining the category whose average quantization score difference with the wood board reference color is greater than a third preset threshold as the mineral line category;

[0269] S644 , determining a minimum circumscribed rectangle of each mineral line category according to the coordinates of the pixel points of the mineral line category, where the length of the minimum circumscribed rectangle is the length of the mineral line.

[0270] Preferably, a clustering algorithm is constructed according to the method described above, and the optimal number of clusters is obtained by searching. For any input wooden board image, the clustering algorithm divides the pixels on the wooden board into several categories; the average mineral line score of each pixel in each category is calculated, and the category with the most pixels is used as the wooden board benchmark. Other blocks with average mineral line scores higher than the benchmark value by more than a specific threshold are detected as mineral line blocks, and the minAreaRect in opencv is used to find its minimum circumscribed rectangle, and the length of the rectangle is the length of the mineral line.

[0271] An embodiment of the present application provides another defect detection method, which is similar to the defect detection method described above, except that this embodiment is a defect detection method applied to the field of color difference detection.

[0272] Color difference refers to the presence of two or more main tones on a wooden board, with uniform transitions between the tones and no obvious dividing lines. This embodiment essentially detects whether there is color difference.

[0273] like Figure 16 As shown, the step S100 of obtaining labeled image samples includes:

[0274] S151, collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have two or more tones;

[0275] S152, cutting out a plurality of image blocks from each wood board photo, and randomly combining the image blocks of the same wood board photo in pairs to form image samples;

[0276] If the two image blocks of the image sample are from the same wooden board photo and have the same or similar tones, the image sample is marked as the same category; if the two image blocks of the image sample are from the same wooden board photo and have different tones, the image sample is marked as different categories.

[0277] Preferably, dozens of wooden floor photos are collected, and the photos are required to be collected from wooden boards with color differences, and try to cover wooden boards with a wider color range; several (5-10) image blocks are cut out from each photo; the image blocks are combined to form pairs, and if the two blocks are from the same wooden board with similar color blocks, they are marked as the same type; if they are from the same wooden board with large color differences, they are marked as different types.

[0278] When constructing and training the neural network, the neural network is constructed and trained as described above, and the floating-point number output in the interval [-10, 10] represents its color difference score.

[0279] like Figure 17 As shown, in S600, identifying defects of the wooden board according to the quantized score of each pixel point includes:

[0280] S651, dividing each pixel in the wooden board photo into at least five categories by clustering based on the quantized score and coordinates of each pixel, and determining the adjacent relationship in the category space;

[0281] S652, calculating the average quantization score of each category based on the quantization scores of the pixels in the category;

[0282] S653, calculating the score difference between the average quantized scores of adjacent categories based on the average quantized score of each category and the adjacent relationship;

[0283] S654: If the score differences of all adjacent categories are less than a fourth preset threshold, and the score difference between the maximum and minimum values ​​in the average quantization scores of all categories is greater than a fifth preset threshold, it is determined that the wooden board photo has color difference.

[0284] Preferably, a clustering algorithm is constructed according to the method described above, and the number of clusters is set to 10. For any input wooden board image, the clustering algorithm divides the pixels on the wooden board into 10 categories; the average color difference score of the pixels is calculated in each category, and the score difference between each category and its spatially adjacent categories is calculated. If the difference between the highest score and the lowest score is greater than a specific threshold, and the difference in the scores of all adjacent categories is less than another specific threshold, the detection result is color difference, otherwise it is no color difference.

[0285] In this embodiment, various color spaces are fully utilized to obtain the optimal result that best suits each task.

[0286] Existing methods use complex convolutional neural networks or trained neural networks, which usually contain tens of thousands to tens of millions of parameters. In this embodiment, the neural network used only contains a few hundred parameters, so the number of samples required is much smaller, thereby saving samples and greatly reducing the difficulty of sample acquisition.

[0287] When using neural networks, existing methods directly obtain classification results from the neural network, which is only applicable to completely fixed usage scenarios. If the customer proposes a new classification category or wants to further subdivide the original classification, it is necessary to re-label the data and train the network. The regression neural network method proposed in this embodiment directly outputs a score value, and no additional work is required for the above modifications proposed by the customer.

[0288] Existing methods can only determine the presence or absence of color defects, but cannot make further judgments on the location, degree, shape, size, etc. of each defect. The clustering method of this embodiment clusters the pixels of each defect into one category. By analyzing the pixels within each category, a detailed judgment of each defect can be flexibly given.

[0289] An embodiment of the present application provides a defect detection device for executing the defect detection method described above in the present invention. The defect detection device is described in detail below.

[0290] like Figure 18 As shown, the defect detection device includes:

[0291] A sample acquisition module 101 is configured to acquire labeled image samples and establish a data set, wherein the image samples are composed of two image blocks and the image samples are labeled as being of the same or different classes, and the image blocks have feature vectors determined based on multiple color spaces;

[0292] A model building module 102 is used to build a defect detection model structure based on a scoring network;

[0293] A model training module 103 is used to train the defect detection model structure according to the data set to obtain a defect detection model;

[0294] A photo acquisition module 104 is configured to acquire a photo of a wooden board to be detected, wherein a feature vector of each pixel in the wooden board photo is determined based on the multiple color spaces;

[0295] A wood board detection module 105 is configured to obtain a quantitative score for each pixel of the wood board photo according to the defect detection model;

[0296] The defect recognition module 106 is configured to recognize defects of the wood board according to the quantized score of each pixel point.

[0297] In this way, only an image sample corresponding to a color defect is needed to detect the defect, which greatly reduces the workload.

[0298] Preferably, the defect detection model structure includes a scoring network and a difference layer, and the data set includes a training set and a validation set;

[0299] Preferably, the model training module 103 is also used to: traverse the training set, and obtain the color score of each image block in the two image blocks of the image sample according to the scoring network; determine the color difference of the image sample through the difference layer according to the color scores of the two image blocks; calculate the loss value through the loss function according to the color difference and annotation of the image sample; update the parameters of the defect detection model structure according to the loss value; traverse the verification set, and determine the color difference of the image samples in the verification set according to the currently updated defect detection model structure; calculate the accuracy of the color difference according to the color difference and annotation of the image samples in the verification set; iterate the defect detection model structure according to the accuracy to obtain the defect detection model.

[0300] Preferably, the plurality of color spaces include at least three of an RGB color space, an HSV color space, an HLS color space, a Lab color space, a Luv color space, a YCrCb color space, and an XYZ color space.

[0301] Preferably, the color score of the image block is in the zero-symmetric interval [-10, 10].

[0302] Preferably, the sample acquisition module 101 is also used to: collect multiple wooden board photos, different wooden board photos have different degrees of depth; cut out multiple image blocks from each wooden board photo, and randomly combine the image blocks into image samples; if the two image blocks of the image sample come from the same wooden board photo, the image sample is marked as the same type; if the two image blocks of the image sample come from different wooden board photos, the image sample is marked as different types.

[0303] Preferably, the defect identification module 106 is also used to: obtain the number of categories for depth classification; divide the zero-symmetric interval corresponding to the quantization score into equal parts according to the number of categories; calculate the average quantization score of the wooden board photo based on the quantization score of each pixel point in the wooden board photo; determine the depth category to which the wooden board photo to be detected belongs based on the equally divided interval and the average quantization score.

[0304] Preferably, the sample acquisition module 101 is also used to: collect multiple wooden board photos, different wooden board photos have different colors; cut out multiple image blocks from each wooden board photo, and randomly combine the image blocks into image samples; if the two image blocks of the image sample come from the same wooden board photo, the image sample is marked as the same type; if the two image blocks of the image sample come from different wooden board photos, the image sample is marked as different types.

[0305] Preferably, the defect recognition module 106 is also used to: obtain the number of categories for color classification; divide the zero-symmetric interval corresponding to the quantitative score into equal parts according to the number of categories; calculate the average quantitative score of the wooden board photo based on the quantitative score of each pixel point in the wooden board photo; determine the color category to which the wooden board photo to be detected belongs based on the equally divided interval and the average quantitative score.

[0306] Preferably, the sample acquisition module 101 is also used to: collect multiple wooden board photos, wherein the wooden boards in the wooden board photos have two tones and there is a clear boundary between the two tones; cut out multiple image blocks from each wooden board photo, and randomly combine the image blocks in the same wooden board photo into image samples; if the two image blocks of the image sample come from the same tonal area in the same wooden board photo, the image sample is marked as the same type; if the two image blocks of the image sample come from different tonal areas in the same wooden board photo, the image sample is marked as different types.

[0307] Preferably, the defect identification module 106 is also used to: divide the wooden board photo into two categories by clustering according to the quantitative score and coordinates of each pixel point; calculate the average quantitative scores of the two categories according to the quantitative scores of the pixels in the category, and determine the average quantitative score difference between the two categories; when the average quantitative score difference between the two categories is greater than a first preset threshold, determine that the wooden board photo has a two-color defect.

[0308] Preferably, the defect recognition module 106 is also used to: generate a quantitative score map of the wooden board photo based on the quantitative scores of the pixel points; detect a straight line on the quantitative score map as a dividing line of two-color defects through an edge detection algorithm according to the category of the pixel points; and determine the width of the two colors in the wooden board photo based on the dividing line.

[0309] Preferably, the sample acquisition module 101 is further used to: collect multiple wooden board photos, the wooden boards in the wooden board photos have blue discoloration and the degree of blue discoloration in different wooden board photos is inconsistent; cut out multiple image blocks from each wooden board photo, and randomly combine the image blocks into image samples in pairs; if the two image blocks of the image sample are both from non-blue discoloration areas or both from blue discoloration areas and the degree of blue discoloration is the same, then the image samples are marked as the same type; otherwise, the image samples are marked as different types.

[0310] Preferably, the defect identification module 106 is also used to: divide the wooden board photo into multiple categories by clustering according to the quantitative score and coordinates of each pixel point; calculate the average quantitative score of each category according to the quantitative scores of the pixels in the category; take the category with the lowest average quantitative score as the wooden board reference color, and determine the category whose difference with the average quantitative score of the wooden board reference color is greater than a second preset threshold as the blue change category; determine the blue change degree and blue change area of ​​each blue change category according to the coordinates and average quantitative scores of the pixel points of the blue change category.

[0311] Preferably, the sample acquisition module 101 is also used to: collect multiple wooden board photos, where the wooden boards in the wooden board photos have mineral lines; cut out multiple image blocks from each wooden board photo, and randomly combine the image blocks into image samples; if the two image blocks of the image sample are both from non-mineral line areas or both from mineral line areas and have the same color, then the image samples are marked as the same type; otherwise, the image samples are marked as different types.

[0312] Preferably, the defect identification module 106 is also used to: divide the wooden board photo into multiple categories by clustering according to the quantitative score and coordinates of each pixel point; calculate the average quantitative score of each category according to the quantitative scores of the pixel points in the category; take the category with the lowest average quantitative score as the wooden board reference color, and determine the category whose difference with the average quantitative score of the wooden board reference color is greater than a third preset threshold as the mineral line category; determine the minimum circumscribed rectangle of each mineral line category according to the coordinates of the pixel points of the mineral line category, and the length of the minimum circumscribed rectangle is the length of the mineral line.

[0313] Preferably, the sample acquisition module 101 is also used to: collect multiple wooden board photos, where the wooden boards in the wooden board photos have two or more tones; cut out multiple image blocks from each wooden board photo, and randomly combine the image blocks of the same wooden board photo into image samples; if the two image blocks of the image sample are from the same wooden board photo and have the same or similar tones, the image samples are marked as the same type; if the two image blocks of the image sample are from the same wooden board photo and have different tones, the image samples are marked as different types.

[0314] Preferably, the defect identification module 106 is also used to: divide the wooden board photo into at least five categories by clustering according to the quantitative score and coordinates of each pixel point, and determine the adjacent relationship in the category space; calculate the average quantitative score of each category according to the quantitative scores of the pixel points in the category; calculate the score difference of the average quantitative scores of adjacent categories according to the average quantitative score of each category and the adjacent relationship; if the score difference of all adjacent categories is less than the fourth preset threshold, and the score difference between the maximum and minimum values ​​of the average quantitative scores of all categories is greater than the fifth preset threshold, it is determined that the wooden board photo has color difference.

[0315] The present application embodiment provides an electronic device, such as Figure 19 As shown, it includes a computer-readable storage medium 301 storing a computer program and a processor 302. When the computer program is read and executed by the processor, the defect detection method as described above is implemented.

[0316] In this way, only an image sample corresponding to a color defect is needed to detect the defect, which greatly reduces the workload.

[0317] An embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program. When the computer program is read and executed by a processor, the defect detection method as described above is implemented.

[0318] The technical solution of the embodiments of the present invention, or the portion that contributes to the prior art, or all or part of the technical solution, may be embodied in the form of a software product. This computer software product, stored in a storage medium, includes instructions for causing a computer device (such as an air conditioner, refrigeration device, personal computer, server, or network device) or a processor to execute all or part of the steps of the method described in the embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a mobile hard drive, ROM, RAM, a magnetic disk, or an optical disk.

[0319] In this way, only an image sample corresponding to a color defect is needed to detect the defect, which greatly reduces the workload.

[0320] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0321] Each embodiment in this application is described in a related manner. The same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments. For related parts, please refer to the partial description of the aforementioned embodiments.

[0322] Although the present invention is disclosed as above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the scope of protection of the present invention should be based on the scope defined by the claims.

Claims

1. A defect detection method, characterized in that: include: Acquire labeled image samples and establish a data set, wherein the image samples are composed of two image blocks and the image samples are labeled as being of the same class or different classes, and the image blocks have feature vectors determined based on multiple color spaces; Construct a defect detection model structure based on scoring network; Training the defect detection model structure according to the data set to obtain a defect detection model; Acquire a photo of a wooden board to be detected, and determine a feature vector of each pixel in the photo based on the multiple color spaces; Obtaining a quantitative score for each pixel of the wooden board photo according to the defect detection model; identifying defects of the wood board according to the quantitative score of each pixel; The obtaining of labeled image samples includes: Collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have blue discoloration and the degree of blue discoloration in different wooden board photos is inconsistent; Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks into image samples; If the two image blocks of the image sample are both from the non-blue-shifted area or both from the blue-shifted area and the degree of blue shift is the same, the image sample is marked as the same type; otherwise, the image sample is marked as different types; The identifying defects of the wooden board according to the quantified score of each pixel point includes: According to the quantitative score and coordinates of each pixel point of the wooden board photo, the wooden board photo is divided into multiple categories by clustering; According to the quantization scores of the pixels in the category, the average quantization score of each category is calculated; The category with the lowest average quantization score is used as the wood board reference color, and the category whose average quantization score difference with the wood board reference color is greater than a second preset threshold is determined as the blue-discoloration category; The degree and area of ​​blue change of each blue change category were determined based on the coordinates and average quantization scores of the pixel points of the blue change category.

2. The method according to claim 1, characterized in that The defect detection model structure includes a scoring network and a difference layer, and the data set includes a training set and a validation set; The defect detection model structure is trained according to the data set to obtain a defect detection model, including: Traversing the training set, and obtaining a color score for each of the two image blocks of the image sample according to the scoring network; Determining a color difference of the image sample by the difference layer according to the color scores of the two image blocks; Calculating a loss value using a loss function according to the color difference and annotation of the image samples; Updating the parameters of the defect detection model structure by the loss value; Traversing the verification set, and determining the color difference of the image samples in the verification set according to the currently updated defect detection model structure; According to the color differences and annotations of the image samples in the validation set, the accuracy of the color differences is calculated; The defect detection model structure is iterated according to the accuracy to obtain the defect detection model.

3. The method according to claim 1, characterized in that The plurality of color spaces include at least three of an RGB color space, an HSV color space, an HLS color space, a Lab color space, a Luv color space, a YCrCb color space, and an XYZ color space.

4. The method according to claim 2, characterized in that The color score of the image block is in the zero-symmetric interval [-10, 10].

5. The method according to any one of claims 1 to 4, characterized in that The obtaining of labeled image samples includes: Collect multiple wooden board photos, and the depth of different wooden board photos is different; Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks into image samples; If the two image blocks of the image sample come from the same wooden board photo, the image sample is marked as the same class; if the two image blocks of the image sample come from different wooden board photos, the image sample is marked as different classes.

6. The method according to claim 5, characterized in that The identifying defects of the wooden board according to the quantified score of each pixel point includes: Get the number of categories for deep and shallow classification; Dividing the zero symmetric interval corresponding to the quantization score into equal parts according to the number of categories; Calculating an average quantized score of the wooden board photo according to the quantized score of each pixel point of the wooden board photo; The depth category of the wooden board photo to be detected is determined according to the equally divided intervals and the average quantization score.

7. The method according to any one of claims 1 to 4, characterized in that The obtaining of labeled image samples includes: Collect multiple wooden board photos, and the colors of different wooden board photos are different; Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks into image samples; If the two image blocks of the image sample come from the same wooden board photo, the image sample is marked as the same class; if the two image blocks of the image sample come from different wooden board photos, the image sample is marked as different classes.

8. The method according to claim 7, characterized in that The identifying defects of the wooden board according to the quantified score of each pixel point includes: Get the number of categories for color classification; Dividing the zero symmetric interval corresponding to the quantization score into equal parts according to the number of categories; Calculating an average quantized score of the wooden board photo according to the quantized score of each pixel point of the wooden board photo; The color category to which the wood board photo to be detected belongs is determined according to the equally divided intervals and the average quantization score.

9. The method according to any one of claims 1 to 4, characterized in that The obtaining of labeled image samples includes: Collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have two tones and a clear boundary between the two tones; Cut out multiple image blocks from each wood board photo, and randomly combine the image blocks in the same wood board photo into image samples; If the two image blocks of the image sample come from the same hue area in the same wooden board photo, the image sample is marked as the same class; if the two image blocks of the image sample come from different hue areas in the same wooden board photo, the image sample is marked as different classes.

10. The method according to claim 9, characterized in that The identifying defects of the wooden board according to the quantified score of each pixel point includes: According to the quantitative score and coordinates of each pixel point in the wooden board photo, it is divided into two categories by clustering; Based on the quantized scores of the pixels in the category, the average quantized scores of the two categories are calculated respectively, and the average quantized score difference between the two categories is determined; When the difference in the average quantitative scores of the two categories is greater than a first preset threshold, it is determined that the wooden board photo has a two-color defect.

11. The method according to claim 10, characterized in that The identifying defects of the wooden board according to the quantized score of each pixel point further includes: generating a quantitative score map of the wooden board photo according to the quantitative scores of the pixels; According to the category of the pixel points, a straight line is detected on the quantized score image by using an edge detection algorithm as a dividing line of the two-color defect; The width of the two colors in the wooden board photo is determined according to the dividing line.

12. The method according to any one of claims 1 to 4, characterized in that The obtaining of labeled image samples includes: collecting a plurality of wooden board photos, wherein the wooden board photos have mineral lines on the wooden board; Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks into image samples; If the two image blocks of the image sample are both from the non-mineral line area or both from the mineral line area and have the same color, the image sample is marked as the same type; otherwise, the image sample is marked as different types.

13. The method according to claim 12, characterized in that The identifying defects of the wooden board according to the quantified score of each pixel point includes: According to the quantitative score and coordinates of each pixel point of the wooden board photo, the wooden board photo is divided into multiple categories by clustering; According to the quantization scores of the pixels in the category, the average quantization score of each category is calculated; The category with the lowest average quantitative score is used as the wood board reference color, and the category with a difference in average quantitative score from the wood board reference color greater than a third preset threshold is determined as the mineral line category; According to the coordinates of the pixel points of the mineral line category, the minimum circumscribed rectangle of each mineral line category is determined, and the length of the minimum circumscribed rectangle is the length of the mineral line.

14. The method according to any one of claims 1 to 4, characterized in that The obtaining of labeled image samples includes: Collecting a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have two or more tones; Cut out a plurality of image blocks from each wood board photo, and randomly combine the image blocks of the same wood board photo in pairs to form image samples; If the two image blocks of the image sample are from the same wooden board photo and have the same or similar tones, the image sample is marked as the same category; if the two image blocks of the image sample are from the same wooden board photo and have different tones, the image sample is marked as different categories.

15. The method according to claim 14, characterized in that The identifying defects of the wooden board according to the quantified score of each pixel point includes: Divide the wooden board photo into at least five categories by clustering according to the quantized score and coordinates of each pixel point, and determine the adjacent relationship in the category space; According to the quantization scores of the pixels in the category, the average quantization score of each category is calculated; Calculating the score difference between the average quantized scores of adjacent categories based on the average quantized score of each category and the adjacent relationship; If the score differences of all adjacent categories are smaller than a fourth preset threshold, and the score difference between the maximum and minimum values ​​in the average quantization scores of all categories is larger than a fifth preset threshold, it is determined that the wooden board photo has color difference.

16. A defect detection device, characterized in that: include: A sample acquisition module is used to acquire labeled image samples and establish a data set, wherein the image samples are composed of two image blocks and the image samples are labeled as the same or different classes, and the image blocks have feature vectors determined based on multiple color spaces; A model building module, which is used to build a defect detection model structure based on a scoring network; A model training module, which is used to train the defect detection model structure according to the data set to obtain a defect detection model; a photo acquisition module, configured to acquire a photo of a wooden board to be detected, wherein a feature vector of each pixel in the photo of the wooden board is determined based on the multiple color spaces; a wood board detection module, configured to obtain a quantitative score for each pixel of the wood board photo according to the defect detection model; a defect recognition module, configured to recognize defects of the wood board based on the quantized score of each pixel; The sample acquisition module is further configured to: collect a plurality of wooden board photos, wherein the wooden boards in the wooden board photos have blue discoloration and the degree of blue discoloration in different wooden board photos is inconsistent; cut out a plurality of image blocks from each wooden board photo, and randomly combine the image blocks into image samples; if two image blocks of the image sample are both from non-blue discoloration areas or both from blue discoloration areas and have the same degree of blue discoloration, then mark the image samples as the same type; otherwise, mark the image samples as different types; The defect recognition module is further configured to: divide the wood board photo into multiple categories by clustering based on the quantized score and coordinates of each pixel point; and calculate the average quantized score of each category based on the quantized scores of the pixels in the category; The category with the lowest average quantization score is used as the wood board reference color, and the category whose average quantization score difference with the wood board reference color is greater than a second preset threshold is determined as the blue-discoloration category; The degree and area of ​​blue change of each blue change category were determined based on the coordinates and average quantization scores of the pixel points of the blue change category.

17. An electronic device, characterized in that: The method comprises a computer-readable storage medium storing a computer program and a processor, wherein the computer program, when read and executed by the processor, implements the method according to any one of claims 1 to 15.

18. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is read and executed by a processor, the method according to any one of claims 1 to 15 is implemented.

Citation Information

Patent Citations

  • A computer generated picture detection method based on a multi-color space convolutional neural network and a random forest

    CN109948692A