Carton surface coloring detection method and system based on machine vision

By performing color space conversion, superpixel segmentation and feature extraction on the carton surface image, combined with pre-trained superpixel classification model and curve fitting, the problem of low detection accuracy of complex color patterns in the prior art is solved, and more efficient detection of carton surface shading defects is achieved.

CN119991609AActive Publication Date: 2025-05-13宜宾四合宜包装有限公司
View PDF 13 Cites 0 Cited by

Patent Information

Application Number
CN202510073444.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-17
Publication Date
2025-05-13
Estimated Expiration
2045-01-17

AI Technical Summary

Technical Problem

The prior art has poor recognition effect and low detection accuracy when detecting complex color patterns on the surface of the carton.

Method used

By obtaining the carton surface image and performing color space conversion, the carton hue image is obtained; superpixel segmentation of the hue image, extracting the feature vectors and inputting the pre-trained superpixel classification model, and outputting the cluster center; curve fitting is performed based on the cluster center and feature vector to obtain the hue fitting function; finally, defect judgment is made based on the fitting function and the preset deviation value threshold.

Benefits of technology

It improves the efficiency and accuracy of detection of surface tinting defects of cartons, and can more accurately identify complex color patterns.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119991609A_ABST
    Figure CN119991609A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of machine vision, and discloses a carton surface coloring detection method and system based on machine vision, and the method comprises the steps: obtaining a carton surface image, and carrying out the color space conversion, and obtaining a carton hue image; performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image; performing feature extraction on the superpixel hue image to obtain an image feature vector; inputting the image feature vector into a pre-trained super-pixel classification model, and outputting to obtain a super-pixel clustering center; performing curve fitting according to the superpixel clustering center and the image feature vector to obtain a hue fitting function; and performing defect judgment according to the hue fitting function and a preset deviation threshold value to obtain a coloring defect detection result. The method has the following effect that the carton surface coloring defect detection efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of machine vision technology, and in particular to a method and system for detecting carton surface coloring based on machine vision. Background Art

[0002] With the development of industrial automation and intelligent manufacturing, industrial manufacturing quality inspection has gradually moved away from manual inspection and used machine vision technology to detect problems that arise in the production process of industrial products. Machine vision technology has the advantages of being stable, efficient, error-prone, and able to detect specific areas. The use of machine vision technology can realize the full automation and intelligence of industrial product production, improve the efficiency of industrial inspection, and avoid false detections.

[0003] In the prior art, there is a method for identifying the color of a carton surface. The method proposes to perform binarization processing on the carton surface image by setting a grayscale threshold, and use the binarization image to determine the abnormal color of the carton surface. The method is simple to determine, but has poor recognition effect on complex color patterns on the carton surface, and has low detection accuracy. A method for automatically detecting defects in carton surface images based on regional features. The method segments the grayscale image by setting three color thresholds, obtains the target area in the grayscale image, calculates the degree of abnormality in the target area, and uses regional features for classification and judgment. The method sets three color thresholds, and the color threshold selection is difficult. The feature is single, which affects the detection accuracy. A method, terminal and storage medium for identifying defects in carton surface images based on a convolutional neural network. The method extracts carton surface image features through a convolutional neural network, constructs a convolutional neural network classification library, and classifies and determines carton images. The construction efficiency of the convolutional neural network is low, and it is difficult to obtain sample data. A large amount of experimental data is required to obtain empirical parameters.

[0004] In the prior art, when using image grayscale threshold to determine abnormalities on the carton surface, the method is simple and direct, but the threshold is set and only involves problems such as single color, too dark color, and too light color. The recognition effect on complex color patterns on the carton surface is poor and the detection accuracy is low. Summary of the invention

[0005] The present invention provides a method and system for detecting carton surface coloration based on machine vision, so as to improve the detection accuracy of carton surface coloration.

[0006] In the first aspect, in order to solve the above technical problems, the present invention provides a method for detecting carton surface coloring based on machine vision, comprising:

[0007] Obtain the carton surface image and perform color space conversion to obtain the carton hue image;

[0008] Performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image;

[0009] Performing feature extraction on the super-pixel hue image to obtain an image feature vector;

[0010] Inputting the image feature vector into a pre-trained superpixel classification model, and outputting a superpixel clustering center;

[0011] Performing curve fitting according to the superpixel cluster center and the image feature vector to obtain a hue fitting function;

[0012] Defect judgment is performed according to the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result.

[0013] In an optional implementation, the step of acquiring the carton surface image and performing color space conversion to obtain the carton hue image includes:

[0014] Extracting the three-color channel intensity of the carton surface image;

[0015] Normalizing the three-color channel intensities to obtain normalized three-color intensities;

[0016] Pixel brightness is calculated according to the following formula:

[0017] V=max(R',G',B')

[0018] Where V is the pixel brightness, max(R',G',B') is the maximum value of the normalized red channel intensity R', the normalized green channel intensity G', and the normalized blue channel intensity B';

[0019] Pixel saturation is calculated according to the following formula:

[0020]

[0021] Among them, S is the pixel saturation, min(R',G',B') is the minimum value of R',G',B', otherwise means otherwise;

[0022] Pixel chromaticity is calculated according to the following formula:

[0023] Δ=C max -C min

[0024]

[0025] Among them, Δ is the intermediate process quantity, C max is the maximum value of normalized three-color intensity, C min is the normalized minimum value of the three color channels, H is the pixel chromaticity, R' is the normalized red channel intensity, G' is the normalized green channel intensity, and N' is the normalized blue channel intensity;

[0026] The carton hue image corresponds one-to-one to pixels of the carton surface image, wherein the pixels of the carton hue image are determined by the pixel brightness, the pixel saturation and the pixel chromaticity.

[0027] In an optional implementation, performing superpixel segmentation on the carton hue image to obtain a superpixel hue image includes:

[0028] Initialize compactness factor and number of superpixels;

[0029] Initializing cluster centers according to the compactness factor and the number of superpixels;

[0030] Assign each pixel to the nearest cluster center;

[0031] Calculate the new average position and average hue value of all pixels in each cluster to update the cluster center;

[0032] Continue the next iteration until the preset number of iterations is reached to obtain a super-pixel hue image.

[0033] In an optional implementation, extracting features from the superpixel hue image to obtain an image feature vector includes:

[0034] Calculate the pixel chromaticity variance of each type of superpixel and normalize it to obtain the chromaticity dimension of the image feature vector;

[0035] Calculate the pixel saturation variance and pixel saturation mean of each type of superpixel;

[0036] The saturation dimension of the image feature vector is obtained by dividing the pixel saturation variance by the pixel saturation mean value;

[0037] Calculate the mean pixel brightness of each type of superpixel as the brightness dimension of the image feature vector;

[0038] The image feature vector includes the chromaticity dimension, the brightness dimension, the saturation dimension and a superpixel number.

[0039] In an optional implementation, the training process of the superpixel classification model includes:

[0040] A superpixel classification model is constructed based on the feature vectors of historical images, and the model is trained. After the loss function of the detection model meets the conditions, the training is determined to be completed, and the trained superpixel classification model is obtained;

[0041] The image feature vector is input into the trained superpixel classification model to obtain the superpixel clustering center.

[0042] In an optional implementation, performing curve fitting according to the superpixel cluster center and the image feature vector to obtain a hue fitting function includes:

[0043] Initialize curve parameters;

[0044] Optimize the curve parameters by the least square method to obtain the optimal curve parameters;

[0045] Substitute the optimal curve parameters into the initial fitting function to obtain the hue fitting function.

[0046] In an optional implementation, the defect judgment is performed according to the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result, including:

[0047] The deviation value is calculated by the following formula:

[0048] Deviation=|H predicted -H actual |

[0049] Among them, Deviation is the deviation value, H predicted is the superpixel chromaticity prediction value corresponding to the hue fitting function, H actual is the actual chromaticity of the superpixel;

[0050] When the deviation value is less than a preset first deviation value threshold, the coloring defect detection result is a slight deviation;

[0051] When the deviation value is greater than the first deviation value threshold and less than a preset second deviation value threshold, the coloring defect detection result is a moderate deviation;

[0052] When the deviation value is greater than the second deviation value threshold, the coloring defect detection result is a height deviation.

[0053] In an optional implementation, the step of inputting the image feature vector into a pre-trained superpixel classification model and outputting a superpixel cluster center comprises:

[0054] Initialize seed point and drift bandwidth;

[0055] The spatial density of all points is calculated by the following formula:

[0056]

[0057] Where x is the horizontal coordinate of the superpixel, y is the vertical coordinate of the superpixel, i is the horizontal coordinate of the scanning point, j is the vertical coordinate of the scanning point, k is the side length of the scanning window, and σ is the standard deviation;

[0058] Perform weighted averaging according to the seed point, the drift bandwidth and the spatial density, so as to update the seed point coordinates;

[0059] Continue the next iteration until the preset number of iterations is reached and the superpixel cluster center is obtained.

[0060] In a second aspect, the present invention provides a carton surface coloring detection system based on machine vision, comprising:

[0061] An image acquisition module is used to acquire the carton surface image and perform color space conversion to obtain the carton hue image;

[0062] A pixel segmentation module, used for performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image;

[0063] A feature extraction module, used to extract features from the super-pixel hue image to obtain an image feature vector;

[0064] A pixel clustering module, used for inputting the image feature vector into a pre-trained superpixel classification model and outputting superpixel clustering centers;

[0065] A curve fitting module, used for performing curve fitting according to the superpixel cluster center and the image feature vector to obtain a hue fitting function;

[0066] The defect detection module is used to make defect judgment according to the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result.

[0067] In a third aspect, the present invention further provides an electronic device comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, it implements any one of the above-mentioned carton surface coloring detection methods based on machine vision.

[0068] In a fourth aspect, the present invention further provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned carton surface coloring detection methods based on machine vision.

[0069] Compared with the prior art, the present invention has the following beneficial effects: the present invention discloses a method and system for detecting carton surface coloration based on machine vision, the method comprising acquiring a carton surface image, and performing color space conversion to obtain a carton hue image; performing superpixel segmentation on the carton hue image to obtain a superpixel hue image; performing feature extraction on the superpixel hue image to obtain an image feature vector; inputting the image feature vector into a pre-trained superpixel classification model, and outputting a superpixel cluster center; performing curve fitting based on the superpixel cluster center and the image feature vector to obtain a hue fitting function; performing defect judgment based on the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result. The present method has the following effects: the present method can improve the efficiency of detecting carton surface coloring defects.

[0070] Specifically, in the method for detecting the coloring of the carton surface based on machine vision, the process of acquiring the carton surface image and performing color space conversion to obtain the carton hue image involves a series of calculation steps, which are used to extract brightness, saturation and chroma from the color information of the original image, that is, convert to the HSV color model. This process helps to more accurately analyze the color characteristics of the carton surface, thereby realizing effective detection of the coloring quality of the carton surface. First, by extracting the three-channel intensity of the carton surface image, that is, the intensity values ​​of the red, green and blue channels, and then normalizing these intensity values, the normalized red channel intensity, green channel intensity and blue channel intensity are obtained, ensuring that the comparison between different images is comparable and reducing the impact of changes in lighting conditions. Then, the brightness value of each pixel is calculated using the formula. This formula selects the maximum value of the three-channel intensity after normalization as the brightness value, so that the brightness represents the brightest component of the color, which is very important for evaluating the brightness of the color. Subsequently, the saturation of the pixel is calculated according to the given conditions. When the pixel brightness is 0, the saturation is set to 0; otherwise, the formula is used to calculate the saturation, which represents the minimum value of the three channel intensities. Saturation reflects the purity of the color, and high saturation means that the color is more vivid. Finally, the chromaticity of the pixel, that is, the angular position of the color, is determined through a series of logical judgments and calculations. The calculation of chromaticity depends on the difference between the maximum color component and the minimum color component, and the channel (red, green or blue) to which the maximum color component belongs. Different maximum color components correspond to different calculation methods, and the final chromaticity value ranges from 0 to 360 degrees, which is used to represent the angular position of the color on the color wheel. After the above steps, each pixel of the image is described by the three parameters of brightness, saturation and chromaticity, forming a carton hue image. This color space conversion method can effectively distinguish different colors and improve the detection accuracy of coloring defects on the surface of the carton.

[0071] Furthermore, for the carton surface coloring detection method based on machine vision, the feature extraction process and the training of the superpixel classification model are important links to ensure the accuracy and efficiency of detection. In this process, the technical improvement is mainly reflected in the accurate calculation of the image feature vector and the effective training of the superpixel classification model. In the feature extraction stage, for the superpixel hue image, the pixel chromaticity variance, saturation variance and mean, and brightness mean are calculated for each type of superpixel, and these statistical information are used as different dimensions of the feature vector to achieve a quantitative description of the color distribution and change in the image. In particular, the chromaticity dimension of the image feature vector is constructed by normalizing the chromaticity variance. This approach can effectively reduce the impact of chromaticity differences between superpixels of different categories and improve the consistency of feature expression. The saturation dimension uses the saturation variance divided by the saturation mean, which can highlight the degree of change in color purity and provide more detailed color feature information for subsequent classification. In addition, the brightness mean is directly used as the brightness dimension of the image feature vector, which simplifies the calculation process while retaining the basic description of the brightness of the image.

[0072] As for the training of the superpixel classification model, its core lies in using historical image feature vectors to build and optimize the model. By setting the loss function and continuously adjusting the model parameters until the loss function reaches the preset conditions, it is ensured that the model can learn effective classification rules from the training data. When the training is completed, when the new image feature vector is input, the model can quickly and accurately determine the cluster center to which each superpixel belongs, thereby realizing automatic classification and recognition of the coloring of the carton surface. The above method not only enhances the ability to understand the complex color patterns on the carton surface, but also improves the detection speed and accuracy.

[0073] Furthermore, using absolute difference as a measure of the difference between the predicted value and the actual value is an intuitive and direct way. This method can effectively quantify the difference between two chromaticity values ​​without considering the directionality issue, which can improve the efficiency of color defect detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0074] Figure 1 It is a schematic flow chart of a method for detecting carton surface coloration based on machine vision provided by the first embodiment of the present invention;

[0075] Figure 2 It is a structural schematic diagram of a carton surface coloring detection system based on machine vision provided in the second embodiment of the present invention. DETAILED DESCRIPTION

[0076] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0077] With the development of industrial automation and intelligent manufacturing, industrial manufacturing quality inspection has gradually moved away from manual inspection and used machine vision technology to detect problems that arise in the production process of industrial products. Machine vision technology has the advantages of being stable, efficient, error-prone, and able to detect specific areas. The use of machine vision technology can realize the full automation and intelligence of industrial product production, improve the efficiency of industrial inspection, and avoid false detections.

[0078] In the prior art, there is a method for identifying the color of a carton surface. The method proposes to perform binarization processing on the carton surface image by setting a grayscale threshold, and use the binarization image to determine the abnormal color of the carton surface. The method is simple to determine, but has poor recognition effect on complex color patterns on the carton surface, and has low detection accuracy. A method for automatically detecting defects in carton surface images based on regional features. The method segments the grayscale image by setting three color thresholds, obtains the target area in the grayscale image, calculates the degree of abnormality in the target area, and uses regional features for classification and judgment. The method sets three color thresholds, and the color threshold selection is difficult. The feature is single, which affects the detection accuracy. A method, terminal and storage medium for identifying defects in carton surface images based on a convolutional neural network. The method extracts carton surface image features through a convolutional neural network, constructs a convolutional neural network classification library, and classifies and determines carton images. The construction efficiency of the convolutional neural network is low, and it is difficult to obtain sample data. A large amount of experimental data is required to obtain empirical parameters.

[0079] In the prior art, when using image grayscale threshold to determine abnormalities on the carton surface, the method is simple and direct, but the threshold is set and only involves problems such as single color, too dark color, and too light color. The recognition effect on complex color patterns on the carton surface is poor and the detection accuracy is low.

[0080] To solve the above problems, refer to Figure 1 The first embodiment of the present invention provides a method for detecting carton surface coloring based on machine vision, comprising the following steps:

[0081] S11, obtaining a carton surface image and performing color space conversion to obtain a carton hue image;

[0082] S12, performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image;

[0083] S13, extracting features from the superpixel hue image to obtain an image feature vector;

[0084] S14, inputting the image feature vector into a pre-trained superpixel classification model, and outputting a superpixel clustering center;

[0085] S15, performing curve fitting according to the superpixel cluster center and the image feature vector to obtain a hue fitting function;

[0086] S16, performing defect judgment according to the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result.

[0087] In step S11, a carton surface image is acquired and a color space conversion is performed to obtain a carton hue image.

[0088] In one embodiment, a uniform light source with moderate intensity is used to avoid shadows and reflections, ensuring that all areas of the carton surface can be clearly photographed. An industrial CCD is used to acquire the carton surface image.

[0089] In one embodiment, the three-color channel intensity of the carton surface image is extracted;

[0090] Normalizing the three-color channel intensities to obtain normalized three-color intensities;

[0091] Pixel brightness is calculated according to the following formula:

[0092] V=max(R',G',B')

[0093] Where V is the pixel brightness, max(R',G',B') is the maximum value of the normalized red channel intensity R', the normalized green channel intensity G', and the normalized blue channel intensity B';

[0094] Pixel saturation is calculated according to the following formula:

[0095]

[0096] Among them, S is the pixel saturation, min(R',G',B') is the minimum value of R',G',B', otherwise means otherwise;

[0097] Pixel chromaticity is calculated according to the following formula:

[0098] Δ=C max -C min

[0099]

[0100] Among them, Δ is the intermediate process quantity, C maxis the maximum value of normalized three-color intensity, C min is the normalized minimum value of the three color channels, H is the pixel chromaticity, R' is the normalized red channel intensity, G' is the normalized green channel intensity, and B' is the normalized blue channel intensity;

[0101] The carton hue image corresponds one-to-one to pixels of the carton surface image, wherein the pixels of the carton hue image are determined by the pixel brightness, the pixel saturation and the pixel chromaticity.

[0102] It is worth mentioning that the HSV color space is a nonlinear transformation model designed based on the human eye's perception of color. It represents colors as points in a cylindrical coordinate system. Chroma is measured in angles ranging from 0° to 360°, representing the position of the color on the color wheel. For example, red corresponds to an angle of 0°, green corresponds to 120°, and blue is at 240°. The saturation ranges from 0.0 to 1.0, reflecting the purity of the color. When S=0, it means that the color is gray without color components; as the S value increases, the color becomes more and more vivid. The brightness ranges from 0.0 to 1.0, indicating the brightness of the color. 0 represents black, while 1 represents the brightest color. This representation method is very suitable for color recognition and segmentation tasks because it can intuitively describe color features and easily adjust the threshold of a specific color for target detection.

[0103] In step S12, super-pixel segmentation is performed on the carton hue image to obtain a super-pixel hue image.

[0104] In one implementation, the compactness factor and the number of superpixels are initialized; the cluster centers are initialized according to the compactness factor and the number of superpixels; each pixel is assigned to the nearest cluster center; the new average position and average hue value of all pixels in each cluster are calculated to update the cluster centers; and the next iteration is continued until a preset number of iterations is reached to obtain a superpixel hue image.

[0105] It is worth noting that the process of superpixel segmentation of the carton hue image to obtain a superpixel hue image is actually an application of a clustering-based image segmentation technique. The core of this method is the SLIC (Simple Linear Iterative Clustering) algorithm, which is essentially a K-means clustering process, but is specifically designed to generate compact and regular superpixels. The compact factor is an important parameter that adjusts the balance between color similarity and spatial proximity. A larger compact factor means that spatial proximity is emphasized more, making the generated superpixels more compact and smooth; on the contrary, a smaller compact factor allows superpixels to better fit the image boundary, even if this results in less regular shapes. The number of superpixels specifies how many superpixels you want to extract from the image. This value directly affects the fineness of the final segmentation result. More superpixels can capture smaller objects or features, but it also increases the computational complexity. Cluster centers These are points randomly selected or set according to some rules during the initialization phase, which serve as the starting position of each potential superpixel. In the SLIC algorithm, these initial cluster centers are evenly distributed on the image. The main purpose of using this method is to simplify the image representation and reduce the amount of data for subsequent processing.

[0106] In step S13, feature extraction is performed on the super-pixel hue image to obtain an image feature vector.

[0107] In one embodiment, the pixel chromaticity variance of each type of superpixel is calculated and normalized to obtain the chromaticity dimension of the image feature vector; the pixel saturation variance and pixel saturation mean of each type of superpixel are calculated; the saturation dimension of the image feature vector is obtained by dividing the pixel saturation variance by the pixel saturation mean; the pixel brightness mean of each type of superpixel is calculated as the brightness dimension of the image feature vector; the image feature vector includes the chromaticity dimension, the brightness dimension, the saturation dimension and the superpixel number.

[0108] It is worth noting that for each type of superpixel, the standard deviation or variance of the chromaticity values ​​of all pixels within it must first be calculated. This step measures the degree of color variation in the area. A larger variance means that the superpixel contains more pixels of different hues, while a smaller variance indicates that the colors are more consistent. Similarly, for all pixels within each superpixel, their saturation mean and standard deviation are calculated respectively. Saturation reflects the intensity or purity of the color. High saturation means bright colors, and low saturation is close to gray. A special method is adopted here to construct the saturation dimension, that is, the saturation variance is divided by its mean. This method not only takes into account the changes in color intensity, but also relatively reflects the proportion of these changes relative to the overall intensity. Directly calculate the average brightness value of all pixels in each superpixel. Brightness is directly related to the degree of brightness in visual perception. Higher brightness values ​​correspond to brighter colors, and vice versa. In addition to the above three color space-based features, each superpixel is also assigned a unique number. This number is not a physical measurement result, but a logical index used to distinguish different superpixels.

[0109] In step S14, the image feature vector is input into a pre-trained superpixel classification model, and the superpixel cluster center is output.

[0110] In one implementation, a superpixel classification model is constructed based on historical image feature vectors, the model is trained, and the training is determined to be completed after the loss function of the detection model meets the conditions, thereby obtaining a trained superpixel classification model; the image feature vector is input into the trained superpixel classification model to obtain a superpixel clustering center.

[0111] In one implementation, the inputting of the image feature vector into a pre-trained superpixel classification model and outputting superpixel cluster centers includes:

[0112] Initialize seed point and drift bandwidth;

[0113] The spatial density of all points is calculated by the following formula:

[0114]

[0115] Where x is the horizontal coordinate of the superpixel, y is the vertical coordinate of the superpixel, i is the horizontal coordinate of the scanning point, j is the vertical coordinate of the scanning point, k is the side length of the scanning window, and σ is the standard deviation;

[0116] Perform weighted averaging according to the seed point, the drift bandwidth and the spatial density, so as to update the seed point coordinates;

[0117] Continue the next iteration until the preset number of iterations is reached and the superpixel cluster center is obtained.

[0118] In another embodiment, a large number of historical images are collected, and the corresponding image feature vectors are extracted therefrom as training samples. Each sample should contain characteristic values ​​such as chromaticity, saturation, brightness, etc. calculated from superpixels, as well as the true category labels to which they belong (i.e., the correct cluster centers). For the superpixel classification problem, support vector machine is selected as the basic model. The core idea of ​​SVM is to find a decision boundary (or "hyperplane") that can maximize the "interval" between two categories, which enables it to have good generalization ability in high-dimensional space. By defining the optimization function, and then using the gradient descent method to optimize the hyperparameters, the hyperplane corresponding to the optimal optimization function is obtained, and the cluster centers are obtained.

[0119] In step S15, curve fitting is performed according to the superpixel cluster center and the image feature vector to obtain a hue fitting function.

[0120] In one implementation, the curve parameters are initialized; the curve parameters are optimized by the least square method to obtain the optimal curve parameters; and the optimal curve parameters are substituted into the initial fitting function to obtain the hue fitting function.

[0121] In one implementation function, the hue fitting function adopts a linear function, which is determined by the three dimensions of the image feature vector. The goal of the least square method is to minimize the sum of the squares of the distances from all data points to the fitting line. The role of the hue fitting function is prediction. By giving a new image feature vector, the function can be used to predict its hue value.

[0122] In step S16, defect judgment is performed according to the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result.

[0123] In one implementation, the deviation value is calculated by the following formula:

[0124] Deviation=|H predicted -H actual |

[0125] Among them, Deviation is the deviation value, H predicted is the superpixel chromaticity prediction value corresponding to the hue fitting function, H actual is the actual chromaticity of the superpixel;

[0126] When the deviation value is less than a preset first deviation value threshold, the coloring defect detection result is a slight deviation;

[0127] When the deviation value is greater than the first deviation value threshold and less than a preset second deviation value threshold, the coloring defect detection result is a moderate deviation;

[0128] When the deviation value is greater than the second deviation value threshold, the coloring defect detection result is a height deviation.

[0129] It is worth noting that based on the hue fitting function constructed previously, the theoretical chromaticity of each superpixel can be predicted. The deviation value here represents the degree of gap between the predicted value and the actual value, which reflects the degree of consistency of color in the superpixel area; smaller deviation values ​​represent more consistent color distribution, while larger deviation values ​​represent color changes or anomalies. Next, in order to convert this numerical difference into a specific defect level, this method defines two key thresholds-the first deviation value threshold (used to distinguish slight deviations) and the second deviation value threshold (used to distinguish moderate deviations from high deviations). For example, the first deviation value threshold is set to 5 and the second deviation value threshold is set to 10. This is equivalent to when the color difference is less than 5, the human eye can hardly perceive it; when it is between 5 and 10, although slight differences can be seen, it does not affect the overall aesthetics; once it exceeds 10, it will obviously affect the visual effect.

[0130] In summary, the present invention discloses a method for detecting carton surface coloring based on machine vision, which aims to solve the problems of poor recognition effect and low detection accuracy of complex color patterns on the carton surface in the prior art. The method first involves the steps of image acquisition and color space conversion, that is, acquiring an image from the carton surface and converting it into a color model suitable for analysis, such as the HSV (hue-saturation-brightness) color space. In this process, the three-color channel intensities of the original RGB image are extracted and normalized to ensure that the images acquired under different conditions are comparable. Subsequently, the brightness, saturation, and chromaticity values ​​of each pixel are calculated according to a specific formula, and these values ​​together define each pixel in the converted carton hue image, thereby forming a data set that can accurately reflect the color characteristics of the carton surface.

[0131] Next, this method uses superpixel segmentation technology to simplify the image representation and reduce the amount of data for subsequent processing. Specifically, after initializing the compact factor and a preset number of superpixels, the SLIC algorithm is used to segment the image into several superpixel regions, where each superpixel represents a set of pixels with similar color characteristics. This process involves iterative operations such as initializing cluster centers, assigning pixels to the nearest cluster centers, and updating the locations of cluster centers until a predetermined number of iterations is reached or a specific convergence condition is met. Superpixel segmentation not only helps to reduce computational complexity, but also captures smaller objects or features and enhances the understanding of the surface details of the carton.

[0132] After completing the superpixel segmentation, the feature extraction stage begins, which is mainly performed on the superpixel hue image. For each type of superpixel, the standard deviation (or variance) of the chromaticity values ​​of all pixels inside it, the average saturation value and its standard deviation, and the brightness mean are calculated. In order to improve the consistency and discrimination of feature expression, the chromaticity variance is also normalized, and the saturation variance is divided by its mean to obtain the saturation dimension, which can better reflect the degree of change in color purity. The final image feature vector contains information in three dimensions: chromaticity, brightness, and saturation. Together with the superpixel number, it constitutes a complete descriptor for subsequent classification model training and defect detection tasks.

[0133] In terms of constructing a superpixel classification model, the present invention uses a support vector machine (SVM) as the basic model. By learning a large number of historical image feature vectors, the loss function parameters are optimized until the set threshold is met, thereby completing the model training. The trained model can receive new image feature vector inputs and output the corresponding superpixel clustering centers to achieve automated classification and recognition of carton surface coloring. In addition, in order to further improve the detection accuracy, this method introduces a curve fitting mechanism, uses the least squares method to find the optimal curve parameters, and establishes a hue fitting function, which can predict the theoretical chromaticity distribution pattern based on the relationship between the superpixel clustering centers and the image feature vectors.

[0134] Finally, in the defect judgment stage, the difference between the actual measured value and the theoretical predicted value is evaluated based on the preset deviation value threshold to determine whether there are slight, moderate or severe coloring defects. For example, when the deviation value is less than the first threshold, it indicates that the coloring consistency is good; if the deviation value is between the two thresholds, there is a certain degree of color change; and once it exceeds the second threshold, it means that there is a significant visual impact. This method enables the difference in values ​​to be converted into specific defect grade assessment results, providing a scientific basis for quality control. In summary, the present invention provides a complete and efficient solution for carton surface coloring defect detection. Compared with traditional methods, it can adapt to more complex color patterns while maintaining high accuracy.

[0135] Reference Figure 2 The second embodiment of the present invention provides a carton surface coloring detection system based on machine vision, comprising:

[0136] An image acquisition module is used to acquire the carton surface image and perform color space conversion to obtain the carton hue image;

[0137] A pixel segmentation module, used for performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image;

[0138] A feature extraction module, used to extract features from the super-pixel hue image to obtain an image feature vector;

[0139] A pixel clustering module, used for inputting the image feature vector into a pre-trained superpixel classification model and outputting superpixel clustering centers;

[0140] A curve fitting module, used for performing curve fitting according to the superpixel cluster center and the image feature vector to obtain a hue fitting function;

[0141] The defect detection module is used to make defect judgment according to the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result.

[0142] Preferably, the image acquisition module is used to:

[0143] Get the carton surface image and perform color space conversion to obtain the carton hue image, including:

[0144] Extracting the three-color channel intensity of the carton surface image;

[0145] Normalizing the three-color channel intensities to obtain normalized three-color intensities;

[0146] Pixel brightness is calculated according to the following formula:

[0147] V=max(R',G',B')

[0148] Where V is the pixel brightness, max(R',G',B') is the maximum value of the normalized red channel intensity R', the normalized green channel intensity G', and the normalized blue channel intensity B';

[0149] Pixel saturation is calculated according to the following formula:

[0150]

[0151] Among them, S is the pixel saturation, min(R',G',B') is the minimum value of R',G',B', otherwise means otherwise;

[0152] Pixel chromaticity is calculated according to the following formula:

[0153]

[0154] Among them, Δ is the intermediate process quantity, C max is the maximum value of normalized three-color intensity, C min is the normalized minimum value of the three color channels, H is the pixel chromaticity, R' is the normalized red channel intensity, G' is the normalized green channel intensity, and B' is the normalized blue channel intensity;

[0155] The carton hue image corresponds one-to-one to pixels of the carton surface image, wherein the pixels of the carton hue image are determined by the pixel brightness, the pixel saturation and the pixel chromaticity.

[0156] Preferably, the pixel segmentation module is used to:

[0157] Performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image includes:

[0158] Initialize compactness factor and number of superpixels;

[0159] Initializing cluster centers according to the compactness factor and the number of superpixels;

[0160] Assign each pixel to the nearest cluster center;

[0161] Calculate the new average position and average hue value of all pixels in each cluster to update the cluster center;

[0162] Continue the next iteration until the preset number of iterations is reached to obtain a super-pixel hue image.

[0163] Preferably, the feature extraction module is used to:

[0164] Performing feature extraction on the super-pixel hue image to obtain an image feature vector includes:

[0165] Calculate the pixel chromaticity variance of each type of superpixel and normalize it to obtain the chromaticity dimension of the image feature vector;

[0166] Calculate the pixel saturation variance and pixel saturation mean of each type of superpixel;

[0167] The saturation dimension of the image feature vector is obtained by dividing the pixel saturation variance by the pixel saturation mean value;

[0168] Calculate the mean pixel brightness of each type of superpixel as the brightness dimension of the image feature vector;

[0169] The image feature vector includes the chromaticity dimension, the brightness dimension, the saturation dimension and a superpixel number.

[0170] Preferably, the pixel clustering module is used to:

[0171] Inputting the image feature vector into a pre-trained superpixel classification model, and outputting a superpixel clustering center;

[0172] The training process of the superpixel classification model includes:

[0173] A superpixel classification model is constructed based on the feature vectors of historical images, and the model is trained. After the loss function of the detection model meets the conditions, the training is determined to be completed, and the trained superpixel classification model is obtained;

[0174] The image feature vector is input into the trained superpixel classification model to obtain the superpixel clustering center.

[0175] Preferably, the step of inputting the image feature vector into a pre-trained superpixel classification model and outputting a superpixel cluster center comprises:

[0176] Initialize seed point and drift bandwidth;

[0177] The spatial density of all points is calculated by the following formula:

[0178]

[0179] Where x is the horizontal coordinate of the superpixel, y is the vertical coordinate of the superpixel, i is the horizontal coordinate of the scanning point, j is the vertical coordinate of the scanning point, k is the side length of the scanning window, and σ is the standard deviation;

[0180] Perform weighted averaging according to the seed point, the drift radius and the spatial density, thereby updating the seed point coordinates;

[0181] Continue the next iteration until the preset number of iterations is reached and the superpixel cluster center is obtained.

[0182] Preferably, the curve fitting module is used for:

[0183] Performing curve fitting according to the superpixel cluster center and the image feature vector to obtain a hue fitting function includes:

[0184] Initialize curve parameters;

[0185] Optimize the curve parameters by the least square method to obtain the optimal curve parameters;

[0186] Substitute the optimal curve parameters into the initial fitting function to obtain the hue fitting function.

[0187] Preferably, the defect detection module is used to:

[0188] Defect judgment is performed according to the hue fitting function and the preset deviation value threshold to obtain a coloring defect detection result, including:

[0189] The deviation value is calculated by the following formula:

[0190] Deviation=|H predicted -H actual |

[0191] Among them, Deviation is the deviation value, H predicted is the superpixel chromaticity prediction value corresponding to the hue fitting function, H actual is the actual chromaticity of the superpixel;

[0192] When the deviation value is less than a preset first deviation value threshold, the coloring defect detection result is a slight deviation;

[0193] When the deviation value is greater than the first deviation value threshold and less than a preset second deviation value threshold, the coloring defect detection result is a moderate deviation;

[0194] When the deviation value is greater than the second deviation value threshold, the coloring defect detection result is a height deviation.

[0195] It should be noted that the carton surface coloring detection system based on machine vision provided in an embodiment of the present invention is used to execute all the process steps of the carton surface coloring detection method based on machine vision in the above-mentioned embodiment. The working principles and beneficial effects of the two correspond one to one, and therefore will not be repeated here.

[0196] The embodiment of the present invention further provides an electronic device. The electronic device includes: a processor, a memory, and a computer program stored in the memory and executable on the processor, such as an image acquisition program. When the processor executes the computer program, the steps in the above-mentioned various machine vision-based carton surface coloring detection method embodiments are implemented, such as Figure 1 Alternatively, when the processor executes the computer program, the functions of each module / unit in the above-mentioned device embodiments are implemented, such as the image acquisition module.

[0197] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the electronic device.

[0198] The electronic device may be a computing device such as a desktop computer, a notebook, a PDA, and a smart tablet. The electronic device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the above components are merely examples of electronic devices and do not constitute a limitation on the electronic device. The electronic device may include more or fewer components than the above components, or may combine certain components, or different components. For example, the electronic device may also include input and output devices, network access devices, buses, etc.

[0199] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device.

[0200] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the electronic device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0201] Wherein, if the module / unit integrated in the electronic device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0202] It should be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the accompanying drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art may understand and implement it without paying any creative effort.

[0203] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for detecting carton surface coloring based on machine vision, characterized in that: include: Obtain the carton surface image and perform color space conversion to obtain the carton hue image; Performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image; Performing feature extraction on the super-pixel hue image to obtain an image feature vector; Inputting the image feature vector into a pre-trained superpixel classification model, and outputting a superpixel clustering center; Performing curve fitting according to the superpixel cluster center and the image feature vector to obtain a hue fitting function; Defect judgment is performed according to the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result.

2. The method for detecting carton surface coloring based on machine vision according to claim 1 is characterized in that: The method of acquiring the carton surface image and performing color space conversion to obtain the carton hue image includes: Extracting the three-color channel intensity of the carton surface image; Normalizing the three-color channel intensities to obtain normalized three-color intensities; Pixel brightness is calculated according to the following formula: V=max(R',G',B') Where V is the pixel brightness, max(R',G',B') is the maximum value of the normalized red channel intensity R', the normalized green channel intensity G', and the normalized blue channel intensity B'; Pixel saturation is calculated according to the following formula: Among them, S is the pixel saturation, min(R',G',B') is the minimum value of R',G',B', otherwise means otherwise; Pixel chromaticity is calculated according to the following formula: Δ=C max -C min Among them, Δ is the intermediate process quantity, C max is the maximum value of normalized three-color intensity, C min is the normalized minimum value of the three color channels, H is the pixel chromaticity, R' is the normalized red channel intensity, G' is the normalized green channel intensity, and B' is the normalized blue channel intensity; The carton hue image corresponds one-to-one to pixels of the carton surface image, wherein the pixels of the carton hue image are determined by the pixel brightness, the pixel saturation and the pixel chromaticity.

3. The method for detecting carton surface coloring based on machine vision according to claim 1 is characterized in that: The step of performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image includes: Initialize compactness factor and number of superpixels; Initializing cluster centers according to the compactness factor and the number of superpixels; Assign each pixel to the nearest cluster center; Calculate the new average position and average hue value of all pixels in each cluster to update the cluster center; Continue the next iteration until the preset number of iterations is reached to obtain a super-pixel hue image.

4. The method for detecting carton surface coloring based on machine vision according to claim 1, characterized in that: The step of extracting features from the superpixel hue image to obtain an image feature vector includes: Calculate the pixel chromaticity variance of each type of superpixel and normalize it to obtain the chromaticity dimension of the image feature vector; Calculate the pixel saturation variance and pixel saturation mean of each type of superpixel; The saturation dimension of the image feature vector is obtained by dividing the pixel saturation variance by the pixel saturation mean value; Calculate the mean pixel brightness of each type of superpixel as the brightness dimension of the image feature vector; The image feature vector includes the chromaticity dimension, the brightness dimension, the saturation dimension and a superpixel number.

5. The method for detecting carton surface coloring based on machine vision according to claim 1, characterized in that: The training process of the superpixel classification model includes: A superpixel classification model is constructed based on the feature vectors of historical images, and the model is trained. After the loss function of the detection model meets the conditions, the training is determined to be completed, and the trained superpixel classification model is obtained; The image feature vector is input into the trained superpixel classification model to obtain the superpixel clustering center.

6. The method for detecting carton surface coloring based on machine vision according to claim 1, characterized in that: The step of performing curve fitting according to the superpixel cluster center and the image feature vector to obtain a hue fitting function comprises: Initialize curve parameters; Optimize the curve parameters by the least square method to obtain the optimal curve parameters; Substitute the optimal curve parameters into the initial fitting function to obtain the hue fitting function.

7. The method for detecting carton surface coloring based on machine vision according to claim 1, characterized in that: The defect judgment is performed according to the hue fitting function and the preset deviation value threshold to obtain the coloring defect detection result, including: The deviation value is calculated by the following formula: Deviation=|H predicted -H actual | Among them, Deviation is the deviation value, H predicted is the superpixel chromaticity prediction value corresponding to the hue fitting function, H actual is the actual chromaticity of the superpixel; When the deviation value is less than a preset first deviation value threshold, the coloring defect detection result is a slight deviation; When the deviation value is greater than the first deviation value threshold and less than a preset second deviation value threshold, the coloring defect detection result is a moderate deviation; When the deviation value is greater than the second deviation value threshold, the coloring defect detection result is a height deviation.

8. The method for detecting carton surface coloration based on machine vision according to claim 1, characterized in that: The step of inputting the image feature vector into a pre-trained superpixel classification model and outputting a superpixel clustering center comprises: Initialize seed point and drift bandwidth; The spatial density of all points is calculated by the following formula: Where x is the horizontal coordinate of the superpixel, y is the vertical coordinate of the superpixel, i is the horizontal coordinate of the scanning point, j is the vertical coordinate of the scanning point, k is the side length of the scanning window, and σ is the standard deviation; Perform weighted averaging according to the seed point, the drift bandwidth and the spatial density, so as to update the seed point coordinates; Continue the next iteration until the preset number of iterations is reached and the superpixel cluster center is obtained.

9. A carton surface coloring detection system based on machine vision, characterized in that: include: An image acquisition module is used to acquire the carton surface image and perform color space conversion to obtain the carton hue image; A pixel segmentation module, used for performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image; A feature extraction module, used to extract features from the super-pixel hue image to obtain an image feature vector; A pixel clustering module, used for inputting the image feature vector into a pre-trained superpixel classification model and outputting superpixel clustering centers; A curve fitting module, used for performing curve fitting according to the superpixel cluster center and the image feature vector to obtain a hue fitting function; The defect detection module is used to make defect judgment according to the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the carton surface coloring detection method based on machine vision as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Image significance detection method of fusion color contrast graph and color space distribution graph

    CN107392968A

  • Image segmentation system and method based on Spiking-SOM (Spiking-Self Organizing Feature Map) neural network clustering

    CN108876797A

  • Automatic segmentation method based on PCANet depth learning model

    CN109447998A

  • Image segmentation method based on weak supervision multi-kernel classification optimization combination

    CN110930413A

  • Superpixel clustering method and equipment based on multiple features

    CN111709483A