A carton surface coloring detection method and system based on machine vision

Through machine vision technology, the color space conversion, superpixel segmentation and feature extraction of the carton surface image are performed, and the superpixel classification model is combined to perform curve fitting and deviation value judgment. This solves the problem of poor recognition of complex color patterns on the carton surface and achieves high-precision color defect detection.

CN119991609BActive Publication Date: 2025-10-03宜宾四合宜包装有限公司
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The existing method for detecting carton surface coloring has poor recognition effect on complex color patterns and low detection accuracy. Especially when the grayscale threshold is set simply and the color is single, it is difficult to accurately identify abnormal color on the carton surface.

Method used

A carton surface coloration detection method based on machine vision is adopted, which includes acquiring carton surface images and performing color space conversion, superpixel segmentation and feature extraction, and using superpixel classification models for curve fitting and deviation value threshold judgment to realize the detection of coloration defects.

Benefits of technology

It improves the accuracy and efficiency of carton surface coloring detection, can effectively identify complex color patterns, reduce the impact of changes in lighting conditions, and enhance the ability to analyze the color characteristics of the carton surface.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119991609B_ABST
    Figure CN119991609B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of machine vision technology, and discloses a method and system for detecting carton surface coloration based on machine vision. The method comprises 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 to output a superpixel cluster center; performing curve fitting based on the superpixel cluster center and the image feature vector to obtain a hue fitting function; and performing defect judgment based on the hue fitting function and a preset deviation value threshold to obtain a coloration defect detection result. The method has the following effects: the method can improve the efficiency of detecting carton surface coloration defects.
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, not prone to errors, and able to detect specific areas. The use of machine vision technology can achieve full automation and intelligence in the production of industrial products, 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. This method proposes binarizing the carton surface image by setting a grayscale threshold, and using the binarized image to determine color anomalies on the carton surface. This method is simple to determine, has poor recognition effect on complex color patterns on the carton surface, and has low detection accuracy. There is also a method for automatically detecting defects in carton surface images based on regional features. This method segments the grayscale image by setting three color thresholds, obtains the target area in the grayscale image, calculates the degree of anomaly in the target area, and uses regional features for classification and judgment. This method sets three color thresholds, which makes color threshold selection difficult and has a single feature, affecting detection accuracy. There is also a method, terminal, and storage medium for identifying defects in carton surface images based on a convolutional neural network. This method extracts carton surface image features through a convolutional neural network, constructs a convolutional neural network classification library, and classifies and judges carton images. However, the construction efficiency of the convolutional neural network is low, sample data acquisition is difficult, and a large amount of experimental data is required to obtain empirical parameters.

[0004] In the existing technology, the method of using image grayscale threshold to determine abnormalities on the carton surface is simple and direct, but the threshold is set and only involves problems such as single color, too dark color, and too light color. It has poor recognition effect on complex color patterns on the carton surface and low detection accuracy. 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 a first aspect, in order to solve the above technical problems, the present invention provides a method for detecting carton surface coloration based on machine vision, comprising:

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

[0008] Performing superpixel segmentation on the carton hue image to obtain a superpixel hue image;

[0009] Performing feature extraction on the superpixel hue image to obtain an image feature vector;

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

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

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

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

[0014] Extracting the three-color channel intensities 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] Where S is the pixel saturation, min(R',G',B') is the minimum value of R',G',B', and 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 the 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 the 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 chroma.

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

[0028] Initialize the compaction 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 and update the cluster center accordingly;

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

[0033] In an optional embodiment, 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 chroma dimension, the brightness dimension, the saturation dimension and a superpixel number.

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

[0040] A superpixel classification model is constructed based on the historical image feature vectors, the model is trained, and the training is determined to be complete after the loss function of the detection model meets the conditions, thereby obtaining a trained superpixel classification model;

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

[0042] In an optional implementation, performing curve fitting based on 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 embodiment, 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 using the following formula:

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

[0049] Among them, Deviation is the deviation value, H predicted is the super-pixel 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 embodiment, the step of inputting the image feature vector into a pre-trained superpixel classification model and outputting superpixel cluster centers includes:

[0054] Initialize seed point and drift bandwidth;

[0055] The spatial density of all points is calculated using 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] Performing weighted averaging based on the seed point, the drift bandwidth, and the spatial density 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 coloration detection system based on machine vision, comprising:

[0061] The 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, configured to perform super-pixel segmentation on the carton hue image to obtain a super-pixel hue image;

[0063] A feature extraction module, configured to extract features from the superpixel hue image to obtain an image feature vector;

[0064] A pixel clustering module, configured to input the image feature vector into a pre-trained superpixel classification model and output superpixel cluster centers;

[0065] A curve fitting module, configured to perform curve fitting based on the superpixel cluster center and the image feature vector to obtain a hue fitting function;

[0066] The defect detection module is used to perform defect judgment based on 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 also 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 also 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 to the existing technology, 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 to output a superpixel cluster center; performing curve fitting based on the superpixel cluster center and the image feature vector to obtain a hue fitting function; and performing defect judgment based on the hue fitting function and a preset deviation value threshold to obtain a coloration defect detection result. The present method has the following effects: The present method can improve the efficiency of detecting carton surface coloration defects.

[0070] Specifically, in a machine vision-based method for detecting carton surface coloration, the process of acquiring a carton surface image and performing color space conversion to obtain a carton hue image involves a series of computational steps. These steps extract brightness, saturation, and chroma from the original image's color information, essentially converting it to the HSV color model. This process helps more accurately analyze carton surface color characteristics, thereby effectively detecting the quality of carton surface coloration. First, the three-channel intensity of the carton surface image—the red, green, and blue channels—is extracted. These intensity values ​​are then normalized to obtain normalized red, green, and blue channel intensities. This ensures comparability between images and reduces the impact of varying lighting conditions. Next, the brightness value of each pixel is calculated using a formula. This formula selects the maximum of the three normalized channel intensities as the brightness value, ensuring that brightness represents the brightest component of the color, which is important for assessing color brightness. Subsequently, the saturation of the pixel is calculated based on the given conditions. When the pixel brightness is 0, the saturation is set to 0; otherwise, a formula is used to calculate the saturation, which represents the minimum of the three channel intensities. Saturation reflects the purity of the color, with higher saturation indicating more vivid colors. Finally, a series of logical decisions and calculations are performed to determine the pixel's chromaticity, or the angular position of the color. The calculation of chromaticity depends on the difference between the maximum and minimum color components, as well as the channel (red, green, or blue) to which the maximum color component belongs. Different maximum color components correspond to different calculation methods, resulting in a chromaticity value ranging from 0 to 360 degrees, representing the color's angular position on the color wheel. After the above steps, each pixel in 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 carton surface coloring defects.

[0071] Furthermore, for machine vision-based cardboard surface color detection methods, feature extraction and superpixel classification model training are crucial steps to ensure detection accuracy and efficiency. Technical advancements in this process primarily lie in the precise calculation of image feature vectors and the effective training of superpixel classification models. During the feature extraction phase, for superpixel hue images, the pixel chromaticity variance, saturation variance and mean, and brightness mean are calculated for each superpixel class. These statistics are used as the dimensions of the feature vector, enabling a quantitative description of color distribution and variation within the image. In particular, normalizing the chromaticity variance to construct the chromaticity dimension of the image feature vector effectively reduces the impact of chromaticity differences between superpixels of different classes, improving the consistency of feature representation. The saturation dimension, calculated by dividing the saturation variance by the saturation mean, highlights variations in color purity, providing more detailed color feature information for subsequent classification. Furthermore, directly using the brightness mean as the brightness dimension of the image feature vector simplifies the calculation process while retaining a basic description of image brightness.

[0072] The core of superpixel classification model training lies in using historical image feature vectors to build and optimize the model. By setting a loss function and continuously adjusting the model parameters until the loss function meets the preset conditions, the model is guaranteed to learn effective classification rules from the training data. Once training is complete, when a new image feature vector is input, the model can quickly and accurately determine the cluster center to which each superpixel belongs, thereby automatically classifying and identifying the coloration of the cardboard surface. This method not only enhances the ability to understand the complex color patterns on the cardboard surface, but also improves detection speed and accuracy.

[0073] Furthermore, using absolute difference as a metric for measuring the gap between predicted and actual values ​​is an intuitive and direct approach. This method effectively quantifies the difference between two chromaticity values ​​without considering directionality, thus improving the efficiency of color defect detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0074] Figure 1 This is a 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 This is a structural 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 clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall 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, not prone to errors, and able to detect specific areas. The use of machine vision technology can achieve full automation and intelligence in the production of industrial products, 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. This method proposes binarizing the carton surface image by setting a grayscale threshold, and using the binarized image to determine color anomalies on the carton surface. This method is simple to determine, has poor recognition effect on complex color patterns on the carton surface, and has low detection accuracy. There is also a method for automatically detecting defects in carton surface images based on regional features. This method segments the grayscale image by setting three color thresholds, obtains the target area in the grayscale image, calculates the degree of anomaly in the target area, and uses regional features for classification and judgment. This method sets three color thresholds, which makes color threshold selection difficult and has a single feature, affecting detection accuracy. There is also a method, terminal, and storage medium for identifying defects in carton surface images based on a convolutional neural network. This method extracts carton surface image features through a convolutional neural network, constructs a convolutional neural network classification library, and classifies and judges carton images. However, the construction efficiency of the convolutional neural network is low, sample data acquisition is difficult, and a large amount of experimental data is required to obtain empirical parameters.

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

[0080] To solve the above problems, refer to Figure 1 The first embodiment of the present invention provides a method for detecting carton surface coloration 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, performing feature extraction on 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 cluster 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, the carton surface image is acquired and color space conversion is performed to obtain a carton hue image.

[0088] In one embodiment, a uniform and moderately intense light source 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 images of the carton surface.

[0089] In one embodiment, the three-color channel intensities of the carton surface image are 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] Where S is the pixel saturation, min(R',G',B') is the minimum value of R',G',B', and 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 the 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 the 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 chroma.

[0102] It's worth noting that the HSV color space is a nonlinear transformation model designed based on the human eye's color perception. It represents colors as points in a cylindrical coordinate system. Chroma is measured as an angle ranging from 0° to 360°, representing the color's position on the color wheel. For example, red corresponds to an angle of 0°, green to 120°, and blue to 240°. Saturation ranges from 0.0 to 1.0, reflecting the color's purity. When S = 0, the color is gray, devoid of color components; as the S value increases, the color becomes increasingly vivid. 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 is well-suited for color recognition and segmentation tasks because it intuitively describes color features and easily adjusts the threshold for specific colors for object 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 embodiment, a compactness factor and the number of superpixels are initialized; cluster centers are initialized based on 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's worth noting that the process of performing superpixel segmentation on the carton hue image to generate a superpixel hue image is actually an application of a clustering-based image segmentation technique. The core of this method is the Simple Linear Iterative Clustering (SLIC) algorithm, which is essentially a K-means clustering process, but specifically designed to generate compact and regular superpixels. The compactness factor is a key parameter that balances color similarity and spatial proximity. A larger compactness factor places greater emphasis on spatial proximity, resulting in more compact and smooth superpixels. Conversely, a smaller compactness factor allows superpixels to better fit image boundaries, even if this results in less regular shapes. The number of superpixels specifies how many superpixels are desired to be extracted from the image. This value directly impacts the refinement of the final segmentation result. More superpixels can capture smaller objects or features, but also increases computational complexity. Cluster centers are points randomly selected or set according to a specific rule during the initialization phase. They serve as the starting position for each potential superpixel. In the SLIC algorithm, these initial cluster centers are evenly distributed across the image. The primary purpose of this approach is to simplify image representation and reduce the amount of data required for subsequent processing.

[0106] In step S13, feature extraction is performed on the superpixel 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's worth noting that for each superpixel, the standard deviation or variance of the chromaticity values ​​of all pixels within it is first calculated. This step measures the degree of color variation within the region. A larger variance indicates that the superpixel contains more pixels of different hues, while a smaller variance indicates more consistent colors. Similarly, the mean and standard deviation of the saturation values ​​of all pixels within each superpixel are calculated. Saturation reflects the intensity or purity of a color; high saturation indicates a vivid color, while low saturation approaches gray. A unique method is used to construct the saturation dimension: dividing the saturation variance by its mean. This method not only accounts for variations in color intensity but also reflects the relative proportion of these variations to the overall intensity. The average luminance value of all pixels within each superpixel is directly calculated. Luminance is directly related to the perceived degree of brightness and darkness in visual perception: higher luminance values ​​correspond to brighter colors, and vice versa. In addition to the three color space-based features described above, each superpixel is assigned a unique number. This number is not a physical measurement, 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 embodiment, 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 the superpixel cluster center.

[0111] In one embodiment, the inputting 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 using 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] Performing weighted averaging based on the seed point, the drift bandwidth, and the spatial density 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 from them as training samples. Each sample should contain characteristic values ​​such as hue, 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 gives it 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 based on the superpixel cluster centers and the image feature vectors to obtain a hue fitting function.

[0120] In one embodiment, 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, the hue fitting function uses a linear function determined by the three dimensions of the image feature vector. The least squares method aims to minimize the sum of the squared distances from all data points to the fitted line. The hue fitting function is used for prediction: given a new image feature vector, the hue value can be predicted using this function.

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

[0123] In one embodiment, 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 super-pixel 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 color consistency within 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; between 5 and 10, although slight differences can be seen, it does not affect the overall aesthetics; once it exceeds 10, it will significantly 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 image acquisition and color space conversion steps, 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. 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 required for subsequent processing. Specifically, after initializing the compaction 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 center, and updating the location of the cluster center until a predetermined number of iterations is reached or a specific convergence condition is met. Superpixel segmentation not only helps reduce computational complexity, but also captures smaller objects or features, enhancing the understanding of the surface details of the cardboard box.

[0132] After completing 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 within it, the average saturation value and its standard deviation, and the average brightness value 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 cluster centers, realizing 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. This function can predict the theoretical chromaticity distribution pattern based on the relationship between the superpixel cluster centers and the image feature vectors.

[0134] Finally, in the defect judgment link, the difference between the actual measurement value and the theoretical prediction 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 indicates that there is a significant visual impact. This method allows the numerical difference to be converted into a specific defect grade assessment result, 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 coloration detection system based on machine vision, comprising:

[0136] The 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 is used to perform super-pixel segmentation on the carton hue image to obtain a super-pixel hue image;

[0138] A feature extraction module, configured to extract features from the superpixel hue image to obtain an image feature vector;

[0139] A pixel clustering module, configured to input the image feature vector into a pre-trained superpixel classification model and output superpixel cluster centers;

[0140] A curve fitting module, configured to perform curve fitting based on the superpixel cluster center and the image feature vector to obtain a hue fitting function;

[0141] The defect detection module is used to perform defect judgment based on 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] Obtain the carton surface image and perform color space conversion to obtain the carton hue image, including:

[0144] Extracting the three-color channel intensities 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] Where S is the pixel saturation, min(R',G',B') is the minimum value of R',G',B', and 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 the 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 the 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 chroma.

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

[0157] Performing superpixel segmentation on the carton hue image to obtain a superpixel hue image includes:

[0158] Initialize the compaction 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 and update the cluster center accordingly;

[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 superpixel 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 chroma 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 the superpixel cluster center;

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

[0173] A superpixel classification model is constructed based on the historical image feature vectors, the model is trained, and the training is determined to be complete after the loss function of the detection model meets the conditions, thereby obtaining a trained superpixel classification model;

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

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

[0176] Initialize seed point and drift bandwidth;

[0177] The spatial density of all points is calculated using 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 based on the seed point, the drift radius, and the spatial density to update 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 to:

[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 based on the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result, including:

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

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

[0191] Among them, Deviation is the deviation value, H predicted is the super-pixel 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 embodiment. The working principles and beneficial effects of the two correspond one to one, so they will not be repeated here.

[0196] An 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 of 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 the modules / units in the above-mentioned device embodiments are realized, 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, and the instruction segments 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, notebook, PDA, or smart tablet. The electronic device may include, but is not limited to, a processor and memory. Those skilled in the art will appreciate that the aforementioned components are merely examples of electronic devices and do not constitute a limitation of the electronic device. The electronic device may include more or fewer components than those described above, or a combination of certain components, or different components. For example, the electronic device may also include input / output devices, network access devices, buses, and the like.

[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, connecting various parts of the entire electronic device using various interfaces and lines.

[0200] The memory can be used to store the computer programs and / or modules, and the processor realizes various functions of the electronic device by running or executing the computer programs and / or modules 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, at least one application required for a function (such as a sound playback function, an image playback function, etc.); the data storage area can store data created based on the use of the mobile phone (such as audio data, a phone book, 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 device.

[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 this understanding, the present invention implements all or part of the process 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. When the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. 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, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), 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 illustrative, 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 across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the 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 can understand and implement the present invention without inventive effort.

[0203] The specific embodiments described above further illustrate the objectives, technical solutions, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. In particular, it should be noted that any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included within the scope of protection of the present invention for those skilled in the art.

Claims

1. A method for detecting carton surface coloration 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 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 the superpixel cluster center; Performing curve fitting based on the superpixel cluster center and the image feature vector to obtain a hue fitting function; Defect judgment is performed based on the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result; Wherein, curve fitting is performed according to the superpixel cluster center and the image feature vector to obtain a hue fitting function, including: 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.

2. The method for detecting carton surface coloration based on machine vision according to claim 1, 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 intensities 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: , in, is the pixel brightness, is the normalized red channel intensity , normalized green channel intensity , normalized blue channel intensity The maximum value of Pixel saturation is calculated according to the following formula: , in, is the pixel saturation, for The minimum value of Indicates otherwise; Pixel chromaticity is calculated according to the following formula: , in, is the intermediate process quantity, is the maximum value of the normalized three-color intensity, is the normalized minimum value of the three color channels, is the pixel chroma, is the normalized red channel intensity, is the normalized green channel intensity, is the normalized blue channel intensity; The carton hue image corresponds one-to-one to the 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 chroma.

3. The method for detecting carton surface coloration based on machine vision according to claim 1, characterized in that: The step of performing super-pixel segmentation on the carton hue image to obtain a super-pixel hue image includes: Initialize the compaction 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 and update the cluster center accordingly; 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 coloration 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 chroma dimension, the brightness dimension, the saturation dimension and a superpixel number.

5. The method for detecting carton surface coloration 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 historical image feature vectors, the model is trained, and the training is determined to be complete 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 the superpixel cluster center.

6. The method for detecting carton surface coloration 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 using the following formula: , in, is the deviation value, is the super-pixel chromaticity prediction value corresponding to the hue fitting function, 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.

7. The method for detecting carton surface coloration based on machine vision according to claim 1, characterized in that: The image feature vector is input into a pre-trained superpixel classification model to output a superpixel cluster center, including: Collect historical images and extract corresponding image feature vectors from them as training samples. Each sample should contain the hue, saturation, brightness calculated from the superpixel, as well as the correct cluster center to which they belong; Select the support vector machine as the basic model and find a hyperplane that can maximize the "interval" between two categories; by defining the optimization function and then using the gradient descent method to optimize the hyperparameters, we can obtain the hyperplane corresponding to the optimal optimization function and obtain the cluster center.

8. A carton surface coloration detection system based on machine vision, characterized in that: A method for detecting carton surface coloration based on machine vision according to any one of claims 1 to 7, comprising: The 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 is used to perform super-pixel segmentation on the carton hue image to obtain a super-pixel hue image; A feature extraction module, configured to extract features from the superpixel hue image to obtain an image feature vector; A pixel clustering module, configured to input the image feature vector into a pre-trained superpixel classification model and output superpixel cluster centers; A curve fitting module, configured to perform curve fitting based on the superpixel cluster center and the image feature vector to obtain a hue fitting function; The defect detection module is used to perform defect judgment based on the hue fitting function and a preset deviation value threshold to obtain a coloring defect detection result.

9. 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 segmentation method based on weak supervision multi-kernel classification optimization combination

    CN110930413A

  • Super-pixel-based flexible IC substrate color change defect detection method and device

    CN112991302A