Color identification method and system for plastic product and storage medium
By segmenting the plastic product images and removing lighting information, calculating and inputting the color parameter set to the recognition model, the problem of inaccurate color recognition of plastic products in the prior art is solved, and higher recognition accuracy and comprehensiveness are achieved.
Patent Information
- Application Number
- CN202411747161.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-02
- Publication Date
- 2025-04-11
AI Technical Summary
The prior art has limitations in the color recognition of plastic products, especially inaccurate color recognition of background-related colors such as transparency, white and black, and is affected by light sources, which affects the accuracy and comprehensiveness of the recognition results.
By segmenting the plastic product image, removing lighting information, calculating the transparent color, black, white and mixed color parameter sets, and inputting these parameters to the preset color recognition model to achieve color recognition.
Accurately identifying the background-related colors in plastic products, improve the accuracy and comprehensiveness of color recognition, and overcome the problems of light source influence and color recognition limitations in the prior art.
Smart Images

Figure CN119810215A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of plastic identification technology, and in particular to a color identification method, system and storage medium for plastic products. Background Art
[0002] Nowadays, plastic products are widely used in all aspects of daily life. During the entire life cycle of plastic products, from raw material processing, molding, quality inspection to final packaging and distribution, plastic products need to be accurately identified. The rapid development of artificial intelligence technology has provided new ideas for plastic identification, but artificial intelligence technology still faces many challenges in the color recognition of plastic products.
[0003] At present, the market mainly uses color space algorithms such as HSV, Cielab, SMYK, RGB to identify colors. Plastic products are usually transparent, black, and white as the main colors, and also include blue, green, purple, and other colors. Therefore, these algorithms have certain limitations in identifying plastic products with multiple colors. On the one hand, the color recognition results of existing color space algorithms are affected by the light source, which in turn affects the accuracy of the recognition results. On the other hand, existing color space algorithms are difficult to identify background-related colors such as transparent, white, and black in plastic products, which affects the accuracy and comprehensiveness of the recognition results. Therefore, how to adapt to the particularity and diversity of plastic products, accurately identify background-related colors in plastic products, and then improve the accuracy and comprehensiveness of color recognition is of research significance. Summary of the invention
[0005] The present application provides a color recognition method, system and storage medium for plastic products, so as to accurately identify the background-related colors in plastic products and improve the accuracy and comprehensiveness of color recognition.
[0006] In a first aspect, the present application provides a method for color recognition of a plastic product, comprising:
[0007] Capturing an image of a plastic product, and segmenting the image to obtain a first foreground area and a first background area;
[0008] Removing the illumination information in the first foreground area to obtain a second foreground area, and respectively calculating a transparent color parameter pair, a black parameter pair, a white parameter pair, and a mixed color parameter set based on the second foreground area and the first background area, wherein the parameter pair includes a main parameter and an auxiliary parameter;
[0009] The transparent color parameter pair, the black color parameter pair, the white color parameter and the mixed color parameter set pair are input into a preset color recognition model to obtain a color recognition result.
[0010] The embodiment of the present application can accurately separate the first foreground area and the first background area by segmenting the acquired plastic product image, so as to facilitate the subsequent accurate calculation of transparent color parameter pairs, black parameter pairs, white parameter pairs and mixed color parameter sets, and further facilitate the subsequent identification of background-related colors in plastic products; by removing the lighting information in the first foreground area, the influence of factors such as light sources on the calculation results of transparent color parameter pairs, black parameter pairs, white parameter pairs and mixed color parameter sets can be removed, thereby improving the accuracy of color recognition results; by inputting the transparent color parameter pairs, the black parameter pairs and the white parameter pairs into a preset color recognition model, the colors that may exist in the plastic product can be identified based on different color parameters, thereby improving the accuracy and comprehensiveness of color recognition. Compared with the prior art, the present application can accurately identify background-related colors in plastic products, thereby improving the accuracy and comprehensiveness of color recognition.
[0011] Furthermore, the image is segmented to obtain a first foreground area and a first background area, specifically:
[0012] Performing feature extraction and downsampling processing on the image to obtain a first feature map;
[0013] Performing upsampling processing on the first feature map to obtain a second feature map;
[0014] Concatenate the first feature map and the second feature map to obtain a fused feature map;
[0015] Feature extraction is performed on the fused feature map to obtain a first foreground area and a first background area.
[0016] In this way, by segmenting the acquired plastic product image, the first foreground area and the first background area can be accurately separated, which facilitates the subsequent accurate calculation of transparent color parameter pairs, black parameter pairs, white parameter pairs and mixed color parameter sets, and further facilitates the subsequent identification of background-related colors in plastic products.
[0017] Furthermore, before respectively calculating the transparent color parameter pair, the black parameter pair, the white parameter pair and the mixed color parameter set based on the second foreground area and the first background area, the method further includes:
[0018] Determine a maximum inscribed matrix in the first background area, and determine a second background area based on the maximum inscribed matrix;
[0019] The second background area is resampled based on a preset standard shape image to obtain a third background area.
[0020] By processing the first background area in this way, the influence of the size factor on the color recognition result can be removed, which facilitates the subsequent recognition of the color in the plastic product and improves the accuracy of color recognition.
[0021] Furthermore, before respectively calculating the transparent color parameter pair, the black parameter pair and the white parameter pair based on the second foreground area and the background area, the method further includes:
[0022] Determining an outer contour of the first foreground area, and determining a corresponding inflection point based on the outer contour;
[0023] The first foreground region is transformed into a third foreground region of a standard shape based on the inflection point.
[0024] In this way, by processing the first foreground area, the influence of the size factor on the color recognition result can be removed, which facilitates the subsequent recognition of the color in the plastic product and improves the accuracy of color recognition.
[0025] Furthermore, removing the illumination information in the first foreground area to obtain the second foreground area is specifically:
[0026] Converting the first foreground area into a grayscale image, and obtaining a grayscale value corresponding to the grayscale image;
[0027] Constructing a corresponding first grayscale histogram based on the grayscale value, and performing smoothing on the grayscale histogram to obtain a second grayscale histogram;
[0028] Determine a peak or a trough of the second grayscale histogram, and determine a segmentation threshold based on the peak or the trough;
[0029] Binarization segmentation is performed based on the segmentation threshold to obtain a second foreground area.
[0030] In this way, by removing the illumination information in the first foreground area, the influence of factors such as light source on the color recognition result can be removed, which facilitates the subsequent recognition of the color in the plastic product and improves the accuracy of color recognition.
[0031] Furthermore, the transparent color parameter pair, the black color parameter pair, the white color parameter pair and the mixed color parameter set are input into a preset color recognition model to obtain a color recognition result, specifically:
[0032] Respectively judging whether the transparent color parameter pair, the black parameter pair, the white parameter pair and the mixed color parameter set meet preset thresholds corresponding to the transparent color recognition model, the black recognition model, the white recognition model and the mixed color recognition model, and obtaining respective judgment results;
[0033] Based on each of the judgment results, a color recognition result corresponding to the plastic product is determined.
[0034] In this way, by inputting the transparent color parameter pair, the black parameter pair and the white parameter pair into a preset color recognition model, the colors that may exist in the plastic product can be identified based on different color parameters, thereby improving the accuracy and comprehensiveness of color recognition.
[0035] Furthermore, the expression of the color recognition model is specifically:
[0036]
[0037] C=k(H,S,V)=C i (low(h,s,v),high(h,s,v));
[0038] Z i (d j )=G(g m ,g n );
[0039] In the formula, Z i is the i-th color to be identified; T is transparent; B is black; W is white; C is color; → represents the order; x is the main parameter, including D, K and L, D is the main parameter of transparent plastic products, K is the main parameter of black plastic products, and L is the main parameter of white plastic products; [α i ,β i ] represents the main interval; [α j β j ] represents the transition interval; yi is the auxiliary parameter, including P, A and B, P is the auxiliary parameter of transparent plastic products, A and B are the auxiliary parameters of black plastic products and white plastic products; y k is the definition interval of the auxiliary parameter; f(x) is the function of the main parameter in the definition interval; k is the calculation function of a single color; C i is the color of the i-th plastic product in the mixed color product; G is the color grade; H represents hue; S represents saturation; V represents brightness; Z i (d j ) is used to classify the depth of the same color, [g m , g n ] is the gray value range.
[0040] Furthermore, the color recognition method of the plastic product also includes:
[0041] Extracting pixel points in the second foreground area, and clustering the pixel points to obtain a color clustering result;
[0042] The color clustering result is input into a preset color mixing recognition model to obtain a color mixing recognition result.
[0043] In this way, by clustering the pixels of the second foreground area, different color clustering results can be obtained, and then the mixed color recognition model is applied to accurately identify the specific color of each color clustering result.
[0044] In a second aspect, the present application provides a color recognition system for plastic products, including: a collection module, a processing module and a recognition module;
[0045] The acquisition module is used to acquire an image of a plastic product and segment the image to obtain a first foreground area and a first background area;
[0046] The processing module is used to remove the illumination information in the first foreground area to obtain a second foreground area, and respectively calculate a transparent color parameter pair, a black parameter pair, a white parameter pair and a mixed color parameter set based on the second foreground area and the first background area, wherein the parameter pair includes a main parameter and an auxiliary parameter;
[0047] The recognition module is used to input the transparent color parameter pair, the black parameter pair, the white parameter and the mixed color parameter set pair into a preset color recognition model to obtain a color recognition result.
[0048] The embodiment of the present application can accurately separate the first foreground area and the first background area by segmenting the acquired plastic product image, so as to facilitate the subsequent accurate calculation of transparent color parameter pairs, black parameter pairs, white parameter pairs and mixed color parameter sets, and further facilitate the subsequent identification of background-related colors in plastic products; by removing the lighting information in the first foreground area, the influence of factors such as light sources on the calculation results of transparent color parameter pairs, black parameter pairs, white parameter pairs and mixed color parameter sets can be removed, thereby improving the accuracy of color recognition results; by inputting the transparent color parameter pairs, the black parameter pairs and the white parameter pairs into a preset color recognition model, the colors that may exist in the plastic product can be identified based on different color parameters, thereby improving the accuracy and comprehensiveness of color recognition. Compared with the prior art, the present application can accurately identify background-related colors in plastic products, thereby improving the accuracy and comprehensiveness of color recognition.
[0049] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the color recognition method for plastic products as described in the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 It is a schematic diagram of a flow chart of an embodiment of a method for color recognition of plastic products provided by the present application;
[0051] Figure 2 This application provides Figure 1 A schematic diagram of the process of step S102 in FIG.
[0052] Figure 3 This is a schematic diagram of determining a segmentation threshold based on the peak or the trough provided by the present application;
[0053] Figure 4 It is a schematic diagram of a flow chart of an embodiment of a color recognition system for plastic products provided in the present application. DETAILED DESCRIPTION
[0054] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0055] It should be understood that the step numbers used in this article are only for the convenience of description and are not intended to limit the order in which the steps are executed.
[0056] It should be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, the singular forms "a", "an" and "the" are intended to include plural forms unless the context clearly indicates otherwise.
[0057] The terms “include” and “comprising” indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0058] The term "and / or" means and includes any and all possible combinations of one or more of the associated listed items.
[0059] Nowadays, plastic products are widely used in various fields of life, and plastic products need to be accurately identified throughout their life cycle. AI technology brings new perspectives to plastic identification, but it still faces challenges in color recognition. HSV, CIELAB, SMYK, RGB and other algorithms are commonly used in the market to identify colors, but plastic products come in a variety of colors, mainly transparent, black, and white, as well as other colors. These algorithms have limitations. First, the recognition is inaccurate due to the influence of the light source, and second, it is difficult to identify background colors such as transparent, white, and black, affecting accuracy and comprehensiveness. Therefore, it is of great significance to study how to adapt to the characteristics and diversity of plastic products, accurately identify background-related colors, and improve recognition accuracy and comprehensiveness.
[0060] Next, the nouns involved in this application are analyzed:
[0061] Artificial intelligence (AI) is a new technical science that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence. AI is a branch of computer science that attempts to understand the essence of intelligence and produce a new type of intelligent machine that can respond in a similar way to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing and expert systems. AI can simulate the information process of human consciousness and thinking. AI is also a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0062] The U2Net algorithm is a deep learning algorithm for the task of salient object detection (SOD), which aims to segment the most attractive target area from the image. Unlike semantic segmentation, salient object detection focuses more on local detail information and global contrast information rather than deep semantic information. Therefore, the main research direction of the U2Net algorithm is multi-level and multi-scale feature extraction. The architecture of U2Net mainly consists of two main parts: the contracting path and the expanding path, forming a symmetrical U-shaped structure, in which the contracting path is used to gradually reduce the spatial resolution of the feature map and increase the depth of the feature map to extract the context information of the image; and the expanding path is used to gradually restore the spatial resolution of the feature map compressed in the contracting path, and at the same time combine the high-resolution features of the jump connection to achieve image segmentation.
[0063] The foreground area usually refers to the part of the image that is of main concern or interest, which can be the subject, target or important element in the image. The background area refers to the part of the image that is used to set off or supplement the foreground area. It is usually not the main focus of the image, but they play an important role in constructing the overall atmosphere of the image, providing contextual information or enhancing the visual effect.
[0064] Gaussian filtering is an effective curve smoothing method that achieves smoothing effects by applying a weight matrix generated by a Gaussian function to an image or curve data. Gaussian filtering is mainly used in the field of image processing, where images are smoothed by convolution operations to reduce noise and details and make the image look smoother. This method is also applicable to one-dimensional data, such as curve data, by applying a Gaussian filter to each dimension of the curve for smoothing. The basic principle of Gaussian filtering is based on the weight distribution mode of the Gaussian function, which takes into account the spatial relationship between pixels. The closer the distance, the greater the weight of the pixel point, and the farther the distance, the smaller the weight of the pixel point. This weighted average method can effectively reduce random noise while retaining most of the details of the image. The effect of the Gaussian filter depends on the selected Gaussian kernel size (standard deviation σ) and shape. The size of σ determines the width of the Gaussian function, which affects the degree of smoothing.
[0065] Based on this, the embodiments of the present application provide a color recognition method, system and storage medium for plastic products, which can accurately identify the background-related colors in plastic products and improve the accuracy and comprehensiveness of color recognition.
[0066] The embodiments of the present application provide a color recognition method, system and storage medium for plastic products, which are specifically described through the following embodiments. First, the color recognition method for plastic products in the embodiments of the present application is described.
[0067] The color recognition method for plastic products provided in the embodiment of the present application relates to the field of plastic recognition technology. The color recognition method for plastic products provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements a color recognition method for plastic products, etc., but is not limited to the above forms.
[0068] The present application can also be used in numerous general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0069] Embodiment 1
[0070] Please refer to Figure 1 , Figure 1 It is a flow chart of an embodiment of the method for color recognition of plastic products provided by the present application, including steps S101 to S103;
[0071] Step S101, collecting an image of a plastic product, and segmenting the image to obtain a first foreground area and a first background area;
[0072] It can be understood that the plastic products of the present application may be but are not limited to plastic bottles, plastic boxes and plastic trays, etc., and may be but are not limited to being photographed by a camera device and stored as 24-bit image data in red-green-blue (RGB) mode to obtain an image of the plastic product, wherein the camera device includes but is not limited to a camera and a mobile phone, etc.
[0073] After obtaining the image of the plastic product, the image can be segmented by using the U2Net algorithm, but is not limited to, to distinguish the first foreground area and the first background area in the image. Specifically, first, the image is subjected to feature extraction and downsampling processing to obtain a first feature map, wherein multiple convolutional layers and pooling layers (or downsampling layers) can be alternately implemented, the convolutional layer is used for image feature extraction, and the pooling layer (or downsampling layer) is used for image downsampling processing. Secondly, the first feature map is upsampled to obtain a second feature map, wherein the upsampling process can be implemented by an upsampling layer (such as transposed convolution, bilinear interpolation, or nearest neighbor interpolation) to restore its spatial resolution to a size close to that of the original image. Thirdly, the first feature map and the second feature map are spliced to obtain a fused feature map, wherein the first feature map is directly copied and cropped, and the second feature map is channel-spliced to retain detail information to enhance feature fusion. Finally, feature extraction is performed on the fused feature map to obtain a first foreground area and a first background area, wherein a convolution operation needs to be performed on the fused feature map. These convolution layers may contain multiple output channels, each channel corresponding to a category, and by applying a softmax function or a similar activation function, these feature maps can be converted into probability maps, thereby obtaining the probability that each pixel belongs to the foreground or the background, and based on these probability maps, the segmentation results of the first foreground area and the first background area can be generated.
[0074] It should be noted that the convolution kernel size of the convolution operation is: 3x3, which means that the width and height of the convolution kernel are both 3 pixels. Specifically, each convolution kernel covers a 3x3 pixel area and moves on the input feature map in a sliding window manner to extract local features of the image. The formula for the convolution operation is: In the formula, output: the width or height of the output feature map, input: the width or height of the input feature map. At the same time, the number of pixels that need to be added to the edge of the input feature map is used to keep the size of the output feature map unchanged. Common padding options include "valid (no padding)" and "same (padding to make the output size the same as the input)". In addition, a ReLU activation function needs to be added after each 3x3 convolution operation to ensure that the network introduces nonlinearity during the feature extraction process, so that the network can learn and express more complex features.
[0075] It should be noted that the pooling layer plays a role in reducing spatial resolution, reducing the amount of calculation, retaining important features and improving invariance. In U-Net, the maximum pooling layer (Max Pooling) is used to select the maximum value of the local area, emphasize significant features, avoid feature smoothing, and improve feature selectivity. The calculation process of the maximum pooling layer: (1) Select the window size: Select a 2*2 window in U-Net, that is, select the maximum value in each 2*2 local area. (2) Sliding window: Slide on the input feature map with a stride (stride = 2), that is, slide two pixels each time. (3) Select the maximum value: Select the maximum value in each window as the corresponding pixel value of the output feature map.
[0076] It should be noted that in U-Net, upsampling convolution uses 2x2 transposed convolution with a stride of 2. By using a 2x2 convolution kernel, the spatial resolution of the feature map can be doubled. At the same time, by setting the number of convolution kernels of the transposed convolution to half the number of input channels, the number of feature channels can be halved. By reducing the number of channels, high-resolution feature information can be more effectively integrated while reducing computational complexity. Specifically, the transposed convolution doubles each dimension of the output feature map by inserting zero elements in the input feature map and using a convolution kernel with a stride of 2 for convolution operations.
[0077] In this way, by segmenting the acquired plastic product image, the first foreground area and the first background area can be accurately separated, which facilitates the subsequent accurate calculation of transparent color parameter pairs, black parameter pairs, white parameter pairs and mixed color parameter sets, and further facilitates the subsequent identification of background-related colors in plastic products.
[0078] Step S102, removing the illumination information in the first foreground area to obtain a second foreground area, and respectively calculating a transparent color parameter pair, a black parameter pair, a white parameter pair and a mixed color parameter set based on the second foreground area and the first background area, wherein the parameter pair includes a main parameter and an auxiliary parameter;
[0079] In some embodiments, since the first foreground area is irregular after the image is segmented, which is not conducive to the overall color extraction of the image, it is necessary to transform the extracted first foreground area, that is, the target object, into a standard shape, specifically: first, determine the outer contour of the first foreground area, and determine the corresponding inflection point based on the outer contour, wherein the outer contour of the first foreground area can be found through an image processing algorithm, and the outer contour is usually represented by a series of points or line segments, which together define the outer shape of the first foreground area, and the inflection point in the outer contour is detected by an inflection point detection algorithm; finally, based on the inflection point, the first foreground area is transformed into a third foreground area of a standard shape, the transformation matrix can be calculated based on the inflection point, and the transformation matrix is applied to transform the first foreground area into a third foreground area of a standard shape, wherein the transformation matrix defines a mapping relationship from the target image to the standard shape.
[0080] It should be noted that the region normalization of the first foreground region may be performed after removing the illumination or may be performed before removing the illumination.
[0081] By processing the first background area in this way, the influence of the size factor on the color recognition result can be removed, which facilitates the subsequent recognition of the color in the plastic product and improves the accuracy of color recognition.
[0082] In some embodiments, in order to facilitate subsequent color extraction, it is also necessary to perform regional standardization on the first background area, specifically: first, determine the maximum inscribed matrix in the first background area, and determine the second background area based on the maximum inscribed matrix, wherein the minimum circumscribed rectangle of the first background area is calculated by a bounding box algorithm, and then the maximum inscribed matrix is determined, and the maximum inscribed rectangle is used as the cropping area to crop the second background area from the first background area; finally, resize the second background area based on a preset standard shape image to obtain a third background area, so as to resample the second background area to a standard size to unify the size with the third foreground area.
[0083] In this way, by processing the first foreground area, the influence of the size factor on the color recognition result can be removed, which facilitates the subsequent recognition of the color in the plastic product and improves the accuracy of color recognition.
[0084] Since color recognition is affected by the reflected and absorbed irradiation light source, in order to accurately recognize the color, it is necessary to remove the illumination information. In some embodiments, step S102 may include, but is not limited to, steps S201 to S204;
[0085] Step S201, converting the first foreground area into a grayscale image, and obtaining a grayscale value corresponding to the grayscale image;
[0086] It can be understood that the RGB image can be converted into a grayscale image by the weighted averaging method, that is, the pixel values of the red, green and blue channels are weighted averaged according to certain weights to obtain the pixel values of the grayscale image. The conversion formula is: Grayscale value Gray (V) = x*R+y*G+z*B, where R, G, B represent the pixel values of the red, green and blue channels respectively, and x, y, z represent the freely set weights respectively.
[0087] Step S202, constructing a corresponding first grayscale histogram based on the grayscale value Gray (V), and performing smoothing processing on the grayscale histogram to obtain a second grayscale histogram;
[0088] It can be understood that after obtaining the grayscale value corresponding to the grayscale image, it is necessary to first define the grayscale value of the pixel. The grayscale value ranges from 0 (black) to 255 (white), and by counting the number of pixels at each grayscale level (from 0 to 255) in the image, the formula for counting the number of pixels is: P(rk) = nk / MN, where rk is the grayscale level of the pixel, nk is the number of pixels with grayscale rk, and MN is the total number of pixels in the image, that is, directly counting the value of nk, and arranging the number of pixels nk in order of grayscale value to form a first grayscale histogram, where the horizontal axis represents the grayscale level and the vertical axis represents the number of pixels with the grayscale level. After determining the first grayscale histogram, it is also necessary to perform curve smoothing on the first grayscale histogram through Gaussian filtering to obtain a second grayscale histogram.
[0089] It should be noted that when implementing Gaussian filtering, first, a Gaussian weight matrix (or Gaussian kernel) needs to be generated. This matrix is calculated based on a two-dimensional Gaussian function. Then, this matrix is applied to each pixel position of the image, and the smoothed pixel value is obtained by calculating the weighted sum of the pixel and its neighborhood values. For curve data, this process is similar, but it only acts on one-dimensional data points. It should be noted that smoothing is not the focus of this application, so it will not be expanded here.
[0090] Step S203, determining a peak or a trough of the second grayscale histogram, and determining a segmentation threshold based on the peak or the trough;
[0091] It can be understood that after obtaining the second grayscale histogram, the peak or trough of the second grayscale histogram can be determined by, but not limited to, comparison discrimination method, first-order difference combined with comparison discrimination method, second-order difference discrimination method, zero-crossing point detection combined with maximum value detection discrimination method, and extreme point detection + maximum value discrimination within a period + iterative update discrimination method, and the segmentation threshold is determined based on the peak or the trough, wherein the schematic diagram of determining the segmentation threshold based on the peak or the trough is as shown in Figure 3 shown.
[0092] It should be noted that the comparison judgment method is to judge the peaks and troughs by comparing the function value of the current point with the function value of its adjacent points. Specifically, if the function value of a point is greater than the function values of its two adjacent points, it is a peak; conversely, if its function value is less than the function values of its two adjacent points, it is a trough. The first-order difference combined with the comparison judgment method is to judge the peaks and troughs by calculating the first-order difference. If the sign of the first-order difference changes (that is, the signs are different), and the function value of the current point is greater than (peak) or less than (trough) the function value of the previous point, it can be judged as a peak or trough. The second-order difference judgment method is to judge the peaks and troughs by calculating the second-order difference. If the first-order difference has different signs and the second-order difference is less than zero, it is a peak; if the first-order difference has different signs and the second-order difference is greater than zero, it is a trough. The zero-crossing point detection combined with the extreme value detection method is to first detect the zero-crossing point, then find the extreme value between two adjacent zero-crossing points, and judge the point as a peak or trough according to the extreme value. The extreme value point detection + extreme value judgment within the cycle + iterative update judgment method is to first find all suspected extreme value points according to the comparison judgment method, and then backtrack and trace back on this basis, judge the position of the real peak or trough according to the extreme value within the cycle, and perform iterative updates.
[0093] Step S204: performing binary segmentation based on the segmentation threshold to obtain a second foreground area.
[0094] It can be understood that after the segmentation threshold is determined, the grayscale image needs to be binarized according to the segmentation threshold, and the illuminated area is found through contour extraction, for example, using the canny operator, and the image RGB mean or maximum interval range value is calculated as the filling value T (Rt, Gt, Bt). Then, T (Rt, Gt, Bt) is assigned to the illuminated area of the original RGB image to achieve illumination removal and obtain the second foreground area.
[0095] In this way, by removing the illumination information in the first foreground area, the influence of factors such as light source on the color recognition result can be removed, which facilitates the subsequent recognition of the color in the plastic product and improves the accuracy of color recognition.
[0096] When the second foreground area is obtained, it is necessary to calculate the transparent color parameter pair, black parameter pair, white parameter pair and mixed color parameter set based on the second foreground area and the first background area, respectively, wherein the parameter pair includes main parameters and auxiliary parameters. The process of calculating the transparent color parameter pair (D, P) is as follows: First, it is necessary to calculate the RGB difference between the second foreground area and the first background area R=R1-R2, G=G1-G2B=B1-B2, wherein R1, G1 and B1 are the average values of the RGB channels of the second foreground area, and R2, G2 and B2 are the average values of the RGB channels of the first background area; secondly, calculate the average value of the R value between the second foreground area and the first background area to obtain the average value rmean; finally, based on the RGB difference and the average value, calculate the main color difference parameter D between the second foreground area and the first background area, that is, the main parameter D of the transparent plastic product, and the formula is:
[0097] D=sqrt((2+rmean / 256)*(R**2)+4*(G**2)+(2+(255-rmean) / 256)*(B**2));
[0098] In the formula, D is the main parameter of transparent plastic products, rmean is the average value, and R, G, and B represent the corresponding differences. At the same time, the auxiliary parameters of transparent plastic products can be obtained with the help of P=(S+V) / 2. In the formula, P represents the auxiliary parameters of transparent plastic products, S represents saturation, and V represents lightness, so the transparent color parameter pair (D, P) can be obtained.
[0099] The process of calculating the black parameter pair (K, A, B) is as follows: In the CMYK color mode, based on the light absorption characteristics of printing ink on paper, each pixel in the image is composed of indigo (C), magenta (M), yellow (Y) and black (K) in different proportions. Each printing ink of each pixel will be assigned a percentage value. The brightest (highlight) color is assigned a lower printing ink color percentage value, and the darker (shadow) color is assigned a higher percentage value. Therefore, the CMYK value can be converted to RGB value, and the K value can be used to identify black plastic products. The parameter conversion formula for converting CMYK value to RGB value is:
[0100] R=255*(100-C)*(100-K) / 1000;
[0101] G=255*(100-M)*(100-K) / 10000;
[0102] B=255*(100-Y)*(100-K) / 10000;
[0103] Among them, C is indigo, M is magenta, Y is yellow, and K is black. Therefore, when the RGB corresponding to the second foreground area and the first background area is determined, the parameter conversion formula can be used to obtain the corresponding K, which is the main parameter of the black plastic product. The A and B calculated above are also auxiliary parameters of the black plastic product. Therefore, the black parameter pair (K, A, B) can be obtained.
[0104] The specific process of calculating the white parameter pair (L, A, B) is as follows: first, the RGB color space corresponding to the second foreground area and the first background area needs to be converted to the Lab color space with the help of the XYZ color space, that is, the RGB color space is converted to the XYZ color space, and then the XYZ color space is converted to the Lab color space. The conversion formula from the RGB color space to the XYZ color space is:
[0105] [X]=[0.412453 0.357580 0.180423]*[R];
[0106] [Y]=[0.212671 0.715160 0.072169]*[G];
[0107] [Z]=[0.019334 0.119193 0.950227]*[B];
[0108] Then, convert the XYZ color space to the Lab color space, and the conversion formula is:
[0109] X=X / Xn, Y=Y / Yn, Z=Z / Zn;
[0110] fx=f(X), fy=f(Y), fz=f(Z);
[0111] L=116*fy-16, A=500*(fx-fy), B=200*(fy-fz);
[0112] Wherein, Xn, Yn and Zn are the standard values of the reference white point, L is the main parameter of the white plastic product, A and B are the auxiliary parameters of the white plastic product, so the white parameter pair (L, A, B) can be obtained.
[0113] The process of calculating the color mixing parameter set (H, S, V) is as follows: the RGB color space can be converted to the HSV color space through the HSV algorithm, where each component of RGB (R, G, B) needs to be converted to a value between [0, 1] through a mapping function f(x). The formula of the HSV algorithm is:
[0114] H = f(I-0.5)*6;
[0115] S = 1-f(I-0.5);
[0116] V = f(I-0.5);
[0117] Wherein, f(x) is a mapping function, H represents hue, S represents saturation, and V represents brightness, so the color mixing parameter set (H, S, V) can be obtained.
[0118] It should be noted that after calculating the transparent color parameter pair, the black color parameter pair, the white color parameter and the mixed color parameter set, the color recognition model can be constructed using SVM (support vector machine), specifically: (1) Data preparation: First, a set of labeled training samples, namely the transparent color parameter pair, the black color parameter pair, the white color parameter and the mixed color parameter set, is required. Each sample has a set of features and a corresponding category label. (2) Finding the optimal hyperplane: Samples of different categories are separated by finding a hyperplane with the largest interval. The hyperplane is a (d-1)-dimensional linear subspace, where d is the dimension of the feature. (3) Kernel function conversion: If the data is not linearly separable, SVM can map the samples from the original feature space to a high-dimensional feature space by using a kernel function, so that the samples are linearly separable in the high-dimensional space. Commonly used kernel functions include linear kernels, polynomial kernels, Gaussian kernels, etc. (4) Solving the optimization problem: SVM finds an optimal hyperplane by solving a convex optimization problem. The goal of the optimization problem is to maximize the interval, and the distance between the correctly classified samples and the hyperplane is maximized. (5) Output result: For a sample to be classified, the category to which the sample belongs is determined based on the position of the hyperplane. If the sample is on one side of the hyperplane, it belongs to one category; if it is on the other side, it belongs to another category, and an SVM color recognition model is generated. The process of constructing a color recognition model with SVM is not the focus of this application, so it will not be expanded.
[0119] Step S103, inputting the transparent color parameter pair, the black color parameter pair, the white color parameter and the mixed color parameter set pair into a preset color recognition model to obtain a color recognition result.
[0120] It can be understood that the transparent color parameter pair, the black parameter pair, the white parameter and the mixed color parameter set are input into the preset color recognition model, and the transparent color parameter pair, the black parameter pair, the white parameter pair and the mixed color parameter set are judged respectively whether they meet the preset thresholds corresponding to the transparent color recognition model, the black recognition model, the white recognition model and the mixed color recognition model to obtain each judgment result; and based on each of the judgment results, the color recognition result corresponding to the plastic product is determined. By way of example and not limitation, when the transparent parameter pair meets the preset threshold, it is determined that the plastic product has a transparent color. If it does not meet the preset threshold, there is no transparent color. After the transparent color parameter pair, the black parameter pair, the white parameter and the mixed color parameter set are judged, the color recognition result in the plastic product can be determined. Since the color recognition model defines the recognition order of transparent color, black, white and mixed color, the color recognition result is a color recognition result composed of multiple colors and having a specific order. Among them, the expression of the color recognition model is specifically as follows;
[0121]
[0122] C=k(H,S,V)=C i (low(h,s,v),high(h,s,v));
[0123] Z i (d j )=G(g m ,g n );
[0124] In the formula, Z i is the i-th color to be identified; T is transparent; B is black; W is white; C is color; → represents the order; x is the main parameter, including D, K and L, D is the main parameter of transparent plastic products, K is the main parameter of black plastic products, and L is the main parameter of white plastic products; [α i ,β i ] represents the main interval; [α j β j ] represents the transition interval; yi is the auxiliary parameter, including P, A and B, P is the auxiliary parameter of transparent plastic products, A and B are the auxiliary parameters of black plastic products and white plastic products; y k is the definition interval of the auxiliary parameter; f(x) is the function of the main parameter in the definition interval; k is the calculation function of a single color; C i is the color of the i-th plastic product in the mixed color product; G is the color grade; H represents hue; S represents saturation; V represents brightness; Z i (d j ) is used to classify the depth of the same color, [g m, g n ] is the gray value range.
[0125] In this way, by inputting the transparent color parameter pair, the black parameter pair and the white parameter pair into a preset color recognition model, the colors that may exist in the plastic product can be identified based on different color parameters, thereby improving the accuracy and comprehensiveness of color recognition.
[0126] The color recognition model is established according to the difference in absorption or reflection of light, and the recognition order is: transparent plastic products, black plastic products, white plastic products and mixed color plastic products. The color recognition model includes: transparent color recognition model, black recognition model, white recognition model, mixed color recognition model and color depth recognition model. The expression of the transparent color recognition model is specifically:
[0127]
[0128] In the formula, T is the transparent color, D is the main parameter of the transparent product, P is the auxiliary parameter of the transparent product, [α i ,β i ] represents the main interval, [α j β j ] represents the transition interval, P k Definition range of auxiliary parameters for transparent products, y k1 and y k2 are the corresponding intervals respectively.
[0129] The expression of the black recognition model is specifically:
[0130]
[0131] In the formula, B is black, K is the main parameter of black products, A and B are auxiliary parameters of black products, [α i ,β i ] represents the main interval, [α j β j ] represents the transition interval, A k and B l All are definition intervals of auxiliary parameters for black products; k1 ,y k2 ,y l1 and l2 are the corresponding intervals respectively.
[0132] The expression of the white recognition model is specifically:
[0133]
[0134] Where W is white, L is the main parameter of white products, A and B are auxiliary parameters of white products, [α i ,β i ] represents the main interval, [α j β j ] represents the transition interval, A k and B l All are the definition ranges of auxiliary parameters for white products; k1 ,y k2 ,y l1 and l2 are the corresponding intervals respectively.
[0135] The expression of the mixed color recognition model is specifically:
[0136] C=k(H,S,V)=C i (low(h,s,v),high(h,s,v));
[0137] In the formula, H represents hue; S represents saturation; V represents brightness; Z represents i (d j ) is used to classify the depth of the same color, [g m , g n ] is the gray value range. The parameter values of the mixed color recognition model are shown in Table 1.
[0138] Table 1 Parameter values of the mixed color recognition model
[0139]
[0140] Among them, the expression of the color depth recognition model is specifically:
[0141] Z i (d j )=G(g m ,g n );
[0142] In the formula, Z i (d j ) is used to classify the depth of the same color, [g m , g n ] is the gray value range.
[0143] When the color of the plastic product is a mixed color, the pixel points in the second foreground area can be extracted, and a suitable clustering algorithm can be selected to cluster the pixel points to obtain a color clustering result, which can be understood as a color classification area; and the color clustering result is input into a preset mixed color recognition model to obtain a mixed color recognition result, so that the specific color of each color classification area in the mixed color plastic product can be identified, wherein the clustering algorithm can be but is not limited to K-means, Gaussian Mixture Models (GMM), Mean shift, etc.
[0144] It should be noted that clustering pixels using the K-means algorithm includes four steps: (1) Randomly select an initial cluster center. (2) Calculate the Euclidean distance between each pixel and the initial cluster center, and assign each pixel to the initial cluster center with the closest Euclidean distance. (3) Recalculate the average value of all pixels and the initial cluster center, and determine the second cluster center based on the average value. (4) Repeat (2) until the cluster center no longer changes, and the color clustering result can be obtained.
[0145] It should be noted that clustering of the pixels can be achieved through existing technologies and is not the focus of this application, so it will not be expanded here.
[0146] In this way, by clustering the pixels of the second foreground area, different color clustering results can be obtained, and then the mixed color recognition model is applied to accurately identify the specific color of each color clustering result.
[0147] The embodiment of the present application can accurately separate the first foreground area and the first background area by segmenting the acquired plastic product image, so as to facilitate the subsequent accurate calculation of transparent color parameter pairs, black parameter pairs, white parameter pairs and mixed color parameter sets, and further facilitate the subsequent identification of background-related colors in plastic products; by removing the lighting information in the first foreground area, the influence of factors such as light sources on the calculation results of transparent color parameter pairs, black parameter pairs, white parameter pairs and mixed color parameter sets can be removed, thereby improving the accuracy of color recognition results; by inputting the transparent color parameter pairs, the black parameter pairs and the white parameter pairs into a preset color recognition model, the colors that may exist in the plastic product can be identified based on different color parameters, thereby improving the accuracy and comprehensiveness of color recognition. Compared with the prior art, the present application can accurately identify background-related colors in plastic products, thereby improving the accuracy and comprehensiveness of color recognition.
[0148] Embodiment 2
[0149] Please refer to Figure 4 , Figure 41 is a schematic structural diagram of an embodiment of a color recognition system for plastic products provided in the present application, comprising a collection module 100, a processing module 200 and a recognition module 300;
[0150] The acquisition module 100 is used to acquire an image of a plastic product and segment the image to obtain a first foreground area and a first background area;
[0151] The processing module 200 is used to remove the illumination information in the first foreground area to obtain a second foreground area, and calculate a transparent color parameter pair, a black parameter pair, a white parameter pair and a mixed color parameter set based on the second foreground area and the first background area, wherein the parameter pair includes a main parameter and an auxiliary parameter;
[0152] The recognition module 300 is used to input the transparent color parameter pair, the black color parameter pair, the white color parameter and the mixed color parameter set pair into a preset color recognition model to obtain a color recognition result.
[0153] The information interaction, execution process, etc. between the modules within the above-mentioned plastic product color recognition system are based on the same concept as the embodiment of the plastic product color recognition method of the first aspect of the present invention, and the technical effects achieved are basically the same. For specific contents, please refer to the description in Embodiment 1 of the method of the present invention, and will not be repeated here.
[0154] The device embodiments described above are merely illustrative, wherein the modules described as separate components may or may not be physically separated, i.e., may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the method of this embodiment.
[0155] The present invention further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the color recognition method of plastic products as described in the first embodiment above is implemented.
[0156] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-monitorable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0157] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only a specific embodiment of the present application and is not intended to limit the scope of protection of the present application.
[0158] It is particularly pointed out that for those skilled in the art, any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. A method for color recognition of plastic products, characterized in that: include: Capturing an image of a plastic product, and segmenting the image to obtain a first foreground area and a first background area; Removing the illumination information in the first foreground area to obtain a second foreground area, and respectively calculating a transparent color parameter pair, a black parameter pair, a white parameter pair, and a mixed color parameter set based on the second foreground area and the first background area, wherein the parameter pair includes a main parameter and an auxiliary parameter; The transparent color parameter pair, the black color parameter pair, the white color parameter and the mixed color parameter set pair are input into a preset color recognition model to obtain a color recognition result.
2. The color recognition method of plastic products according to claim 1, characterized in that: The image is segmented to obtain a first foreground area and a first background area, specifically: Performing feature extraction and downsampling processing on the image to obtain a first feature map; Performing upsampling processing on the first feature map to obtain a second feature map; Concatenate the first feature map and the second feature map to obtain a fused feature map; Feature extraction is performed on the fused feature map to obtain a first foreground area and a first background area.
3. The color recognition method of plastic products according to claim 1, characterized in that: Before respectively calculating the transparent color parameter pair, the black parameter pair, the white parameter pair and the mixed color parameter set based on the second foreground area and the first background area, the method further includes: Determine a maximum inscribed matrix in the first background area, and determine a second background area based on the maximum inscribed matrix; The second background area is resampled based on a preset standard shape image to obtain a third background area.
4. The color recognition method of plastic products according to claim 1, characterized in that: Before respectively calculating the transparent color parameter pair, the black parameter pair and the white parameter pair based on the second foreground area and the background area, the method further includes: Determining an outer contour of the first foreground area, and determining a corresponding inflection point based on the outer contour; The first foreground region is transformed into a third foreground region of a standard shape based on the inflection point.
5. The color recognition method of plastic products according to claim 1, characterized in that: The step of removing the illumination information in the first foreground area to obtain the second foreground area is specifically: Converting the first foreground area into a grayscale image, and obtaining a grayscale value corresponding to the grayscale image; Constructing a corresponding first grayscale histogram based on the grayscale value, and performing smoothing on the grayscale histogram to obtain a second grayscale histogram; Determine a peak or a trough of the second grayscale histogram, and determine a segmentation threshold based on the peak or the trough; Binarization segmentation is performed based on the segmentation threshold to obtain a second foreground area.
6. The color recognition method of plastic products according to claim 1, characterized in that: The transparent color parameter pair, the black color parameter pair, the white color parameter pair and the mixed color parameter set are input into a preset color recognition model to obtain a color recognition result, specifically: Respectively judging whether the transparent color parameter pair, the black parameter pair, the white parameter pair and the mixed color parameter set meet preset thresholds corresponding to the transparent color recognition model, the black recognition model, the white recognition model and the mixed color recognition model, and obtaining respective judgment results; Based on each of the judgment results, a color recognition result corresponding to the plastic product is determined.
7. The color recognition method of plastic products according to claim 1, characterized in that: The expression of the color recognition model is specifically: C=k(H,S,V)=C i (low(h,s,v),high(h,s,v)); Z i (d j )=G(g m ,g n ); In the formula, Z i is the i-th color to be identified; T is transparent; B is black; W is white; C is color; → represents the order of precedence; x is the main parameter, including D, K and L, D is the main parameter of transparent plastic products, K is the main parameter of black plastic products, and L is the main parameter of white plastic products; [α i ,β i ] represents the main interval; [α j β j ] represents the transition interval; yi is the auxiliary parameter, including P, A and B, P is the auxiliary parameter of transparent plastic products, A and B are the auxiliary parameters of black plastic products and white plastic products; y k is the definition interval of the auxiliary parameter; f(x) is the function of the main parameter in the definition interval; k is the calculation function of a single color; C i is the color of the i-th plastic product in the mixed color product; G is the color grade; H represents hue; S represents saturation; V represents brightness; Z i (d j ) is used to classify the depth of the same color, [g m , g n ] is the gray value range.
8. The color recognition method of plastic products according to claim 1, characterized in that: Also includes: Extracting pixel points in the second foreground area, and clustering the pixel points to obtain a color clustering result; The color clustering result is input into a preset color mixing recognition model to obtain a color mixing recognition result.
9. A color recognition system for plastic products, characterized in that: include: Acquisition module, processing module and recognition module; The acquisition module is used to acquire an image of a plastic product and segment the image to obtain a first foreground area and a first background area; The processing module is used to remove the illumination information in the first foreground area to obtain a second foreground area, and respectively calculate a transparent color parameter pair, a black parameter pair, a white parameter pair and a mixed color parameter set based on the second foreground area and the first background area, wherein the parameter pair includes a main parameter and an auxiliary parameter; The recognition module is used to input the transparent color parameter pair, the black parameter pair, the white parameter and the mixed color parameter set pair into a preset color recognition model to obtain a color recognition result.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the color recognition method for plastic products as described in any one of claims 1 to 8 is implemented.