Color identification method and device, electronic equipment and storage medium

By acquiring the three primary color channel parameters of sample and background images, calculating gradient values ​​and updating color parameters, and combining gradient descent and weighted summation methods, the problem of low accuracy in bottle flake color classification in existing technologies is solved, thus improving recycling efficiency.

CN121788846APending Publication Date: 2026-04-03GUANGDONG GONGYE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-19
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

In existing technologies, the color sorting accuracy of recycled plastic bottle flakes is low, resulting in low recycling efficiency.

Method used

By acquiring the three primary color channel parameters of the sample image and the background image, calculating the gradient value and updating the initial color parameters, and combining the gradient descent method and the weighted summation method, the color category of the sample is determined and background interference is reduced.

Benefits of technology

This improved the accuracy of color sorting, thereby increasing the efficiency of bottle flake recycling.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121788846A_ABST
    Figure CN121788846A_ABST
Patent Text Reader

Abstract

The invention discloses a color recognition method and device, electronic equipment and a storage medium, and relates to the technical field of color recognition, and the color recognition method comprises the steps: obtaining a sample image which is configured as an image containing a single sample; acquiring a corresponding background image in the sample image; calculating a gradient value based on the three-primary-color channel parameter of the sample image, the three-primary-color channel parameter of the corresponding background image and a preset initial color parameter; updating the initial color parameter based on the gradient value to obtain a color parameter; according to the color classification method and device, the color category of the sample (namely the bottle flake) is obtained through the sample picture and the background picture, interference of the background on final color identification is avoided, and the color classification accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] Technology Neighborhood This application relates to the field of color recognition technology, and in particular to a color recognition method, apparatus, electronic device and storage medium. Background Technology

[0002] Recycled plastics produce a lot of fragments, namely bottle flakes, after being processed by a crusher. These bottle flakes are usually dyed in different colors, and they need to be sorted by color before they can be recycled. However, the color sorting methods of existing technologies are not very accurate, resulting in low efficiency in bottle flake recycling. Summary of the Invention

[0003] This application aims to address at least one of the technical problems existing in the prior art. To this end, this application proposes a color recognition method, apparatus, electronic device, and storage medium, which can obtain the color category of a sample (i.e., bottle flakes) based on a sample image and a background image, thereby improving the accuracy of color classification.

[0004] The color recognition method according to the first aspect of this application includes: Acquire a sample image, which is configured to contain an image of a single sample; Obtain the background image corresponding to the sample image; The gradient value is calculated based on the three primary color channel parameters of the sample image, the corresponding three primary color channel parameters of the background image, and the preset initial color parameters; Based on the gradient value, the initial color parameters are updated to obtain the color parameters; Based on the color parameters, the color category of the sample is determined.

[0005] The color recognition method according to the embodiments of this application has at least the following beneficial effects: by acquiring a sample image to obtain an image containing a single sample, the color of the single sample can be classified subsequently; a corresponding background image is acquired through the sample image; color parameters are calculated using the three primary color channel parameters of the sample image and the corresponding background image, as well as preset initial color parameters; and the color category of the corresponding sample is determined using the color parameters. In addition to the sample image, the background image is also introduced for calculation when calculating the color parameters in this application to reduce the interference of the background on the determination of the sample color category, thereby improving the accuracy of color classification and thus improving the efficiency of bottle flake recycling.

[0006] According to some embodiments of this application, obtaining the sample image includes: Acquire sample images, which are configured to contain images of multiple said samples; Obtain the coordinate position of each sample in the sample image to form a corresponding bounding box; Based on each of the bounding boxes, the sample images are segmented to obtain multiple sample images.

[0007] According to some embodiments of this application, obtaining the background image corresponding to the sample image includes: The sample corresponding to the sample image is removed to obtain the first original image; The first original image is compared with a plurality of preset pre-selected images one by one to calculate the similarity, and the pre-selected image with the highest similarity is used as the background image.

[0008] According to some embodiments of this application, obtaining the background image corresponding to the sample image includes: Using the sample image as the target sample image, obtain multiple neighboring images that are adjacent to the bounding box of the target sample image in the sample image; Among the multiple neighboring images, neighboring images that contain the bounding boxes of the other sample images besides the target sample image are selected and removed; The remaining neighboring images are compared with the original image one by one, and the neighboring image with the highest similarity is taken as the target neighboring image. An image with the same resolution as the sample image is cropped from the target neighboring image and used as the background image.

[0009] According to some embodiments of this application, obtaining the background image corresponding to the sample image includes: The sample corresponding to the sample image is removed to obtain the second original image; The second original image is filled with image to obtain the background image.

[0010] According to some embodiments of this application, updating the initial color parameters based on the gradient to obtain the color parameters includes: Based on the initial color parameters, the gradient value is constrained to correct the gradient value; Based on the constrained gradient value, the initial color parameters are updated using the gradient descent method to obtain the color parameters.

[0011] According to some embodiments of this application, determining the color category of the sample based on the color parameters includes: The target color parameters are obtained by performing a weighted summation on the color parameters. Convert the target color parameters to a preset color space; Based on a preset threshold, the converted target color parameters are classified into the corresponding color categories to obtain the color category of the sample.

[0012] A color recognition device according to a second aspect embodiment of this application includes: An image processing module is configured to acquire a sample image, wherein the sample image is configured to contain a single sample; and acquire a corresponding background image in the sample image; The parameter calculation module is configured to calculate gradient values ​​based on the three primary color channel parameters of the sample image, the corresponding three primary color channel parameters of the background image, and preset initial color parameters; and update the initial color parameters based on the gradient values ​​to obtain color parameters. The category determination module is configured to determine the color category of the sample based on the color parameters.

[0013] An electronic device according to a third aspect of this application includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the color recognition method described in the first aspect of this application.

[0014] According to a fourth aspect embodiment of the present application, a computer-readable storage medium stores a computer program that, when executed by a processor, implements the color recognition method described in the first aspect embodiment of the present application.

[0015] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0016] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a flowchart illustrating the steps of the color recognition method according to an embodiment of this application; Figure 2 This is a schematic diagram of a specific process for step S101; Figure 3 This is a schematic diagram of a specific process for step S102; Figure 4 This is another specific flowchart of step S102; Figure 5 This is another specific flowchart of step S102; Figure 6 This is a schematic diagram of a specific process for step S104; Figure 7 This is another specific flowchart of step S105; Figure 8This is a schematic diagram of the mechanism of the color recognition device according to an embodiment of this application; Figure 9 This is an example of the color recognition method in this application that obtains a foreground image from a background image and a sample image. Figure 10 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation

[0017] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0018] In the description of this application, it should be understood that the orientation descriptions, such as up, down, front, back, left, right, etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.

[0019] In the description of this application, "several" means one or more, "more than" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.

[0020] In the description of this application, unless otherwise expressly defined, terms such as "setup," "installation," and "connection" should be interpreted broadly, and those skilled in the art can reasonably determine the specific meaning of the above terms in this application in conjunction with the specific content of the technical solution.

[0021] Currently, recycled plastics produce a lot of fragments, namely bottle flakes, after being processed by a crusher. These bottle flakes are usually dyed in different colors, and they need to be sorted by color before further recycling. However, existing technologies usually achieve color classification by setting relevant color thresholds within the required color space, thereby achieving the effect of color detection. But due to imaging errors, background interference, and lighting effects, the color detection effect achieved by this existing technology is difficult to achieve high reliability and accuracy.

[0022] Based on this, this application proposes a color recognition method, device, electronic device and storage medium, which aims to obtain the color category of a sample (i.e., bottle flake) based on a sample image and a background image, so as to improve the accuracy of color classification.

[0023] The first aspect of this application is based on... Figure 1 A diagram illustrating a color recognition method. (Refer to...) Figure 1 , Figure 1 This is a flowchart illustrating the steps of a color recognition method according to an embodiment of this application. Figure 1 The illustrated process steps include, but are not limited to, steps S101 to S105.

[0024] Step S101: Obtain a sample image, which is configured to contain a single sample.

[0025] Step S102: Obtain the background image corresponding to the sample image.

[0026] Step S103: Calculate the gradient value based on the three primary color channel parameters of the sample image, the three primary color channel parameters of the corresponding background image, and the preset initial color parameters.

[0027] Step S104: Update the initial color parameters based on the gradient value to obtain the color parameters.

[0028] Step S105: Determine the color category of the sample based on the color parameters.

[0029] The color recognition method according to the embodiments of this application has at least the following beneficial effects: by acquiring a sample image to obtain an image containing a single sample, the color of the single sample can be classified subsequently; a corresponding background image is acquired through the sample image; color parameters are calculated using the three primary color channel parameters of the sample image and the corresponding background image, as well as preset initial color parameters; and the color category of the corresponding sample is determined using the color parameters. In addition to the sample image, the background image is also introduced for calculation when calculating the color parameters in this application to reduce the interference of the background on the determination of the sample color category, thereby improving the accuracy of color classification and thus improving the efficiency of bottle flake recycling.

[0030] In some embodiments, refer to Figure 2 Step S101 may include, but is not limited to, steps S201 to S203.

[0031] Step S201: Obtain a sample image, which is configured to contain multiple samples.

[0032] Step S202: Obtain the coordinate position of each sample in the sample image to form the corresponding bounding box.

[0033] Step S203: Based on each bounding box, the sample image is segmented to obtain multiple sample images.

[0034] In step S201 of some embodiments, the bottle flakes are transported by a belt and, when passing through the imaging area of ​​the line scan camera, are captured by the camera to obtain a three-primary-color image containing multiple bottle flakes, i.e., a sample image, where the three primary colors refer to RGB (red, green, and blue).

[0035] In step S202 of some embodiments, for the sample image, a heuristic segmentation algorithm, a depth segmentation algorithm and other pre-processing algorithms are used to calculate the specific coordinate position of each bottle piece in the sample image, and form a corresponding rectangular bounding box to frame the bottle piece, with one bounding box corresponding to one bottle piece.

[0036] In step S203 of some embodiments, image cutting or other methods are used to cut along the boundaries of the bounding boxes to separate multiple bounding boxes from the sample image, and then these separated bounding boxes are used as the sample image.

[0037] Steps S201 to S203 of this application involve separating multiple bottle fragments contained in the sample image one by one to obtain multiple sample images. Each sample image contains only one sample, so that each sample can be specifically classified by color in the subsequent process.

[0038] In some embodiments, refer to Figure 3 Step S102 may include, but is not limited to, steps S301 to S302.

[0039] Step S301: Remove the sample corresponding to the sample image to obtain the first original image.

[0040] Step S302: Calculate the similarity between the first original image and a plurality of preset pre-selected images one by one, and use the pre-selected image with the highest similarity as the background image.

[0041] In step S301 of some embodiments, in order to take into account the interference of the background, the background of the bottle flake needs to be taken into account in the color recognition method of this application. Therefore, it is necessary to obtain the background image corresponding to the sample image. When the background is fixed or known, the corresponding sample in the sample image needs to be removed first to obtain the first original image, wherein the part of the first original image in which the sample has been removed is blank.

[0042] In step S302 of some embodiments, a background image library is set in advance, which stores multiple pre-selected images. When the background is fixed or known, the similarity between the first original image and the multiple pre-selected images needs to be calculated one by one to obtain multiple similarities. Then, the multiple similarities are sorted, and the pre-selected image with the highest similarity is used as the background image corresponding to this sample image.

[0043] It should be noted that similarity metrics can be measured using structural similarity, correlation, etc., and the appropriate metric can be selected based on the specific circumstances.

[0044] In other embodiments, reference is made to Figure 4 Step S102 may include, but is not limited to, steps S401 to S403.

[0045] Step S401: Using the sample image as the target sample image, acquire multiple neighboring images that are adjacent to the bounding box of the target sample image in the sample image.

[0046] Step S402: Among multiple neighboring images, filter out the neighboring images that contain the bounding boxes of the other sample images besides the target sample image, and remove them.

[0047] Step S403: Calculate the similarity between the remaining neighborhood images and the original image one by one, and take the neighborhood image with the highest similarity as the target neighborhood image. Crop an image with the same resolution as the sample image from the target neighborhood image as the background image.

[0048] In step S401 of some embodiments, if the background is not fixed or known, but has repeating textures, such as belt lines, then the sample image needs to be used as the target sample image, and the eight neighboring images of the target sample image near the bounding box in the sample image are obtained. The eight neighboring images are the top left neighbor, top neighbor, top right neighbor, left neighbor, right neighbor, bottom left neighbor, bottom neighbor, and bottom right neighbor. The bounding box corresponding to the target sample image is surrounded by these eight neighboring images. The specific calculation principle is as follows: assuming the coordinates of the top left corner of the bounding box corresponding to the target sample image are (X... LT Y LT The coordinates of the upper right corner are (X... RB Y RB If the width W is X, then the width W is X. RB -X LT High H is Y RB -Y LT The scaling factor is s; at this point, the corresponding coordinates of the top-left corner and bottom-right corner of the top-left neighborhood are (X... LT -sW,Y LT -sH) and (X LT ,YLT The coordinates of the top left and bottom right corners of the upper neighbor are (X) and (X) respectively. LT +W / 2-sW / 2,Y LT -sH) and (X LT +W / 2+sW / 2,Y LT The coordinates of the top-left corner and the bottom-right corner of the top-right neighbor are (X...). RB ,Y LT -sH) and (X RB +sW,Y LT The top-left and bottom-right coordinates of the left neighbor are (X...) LT -sW,Y LT +H / 2-sH / 2) and (X LT ,Y LT +H / 2+sH / 2), the coordinates of the top left and bottom right corners of the right neighbor are respectively (X RB ,Y LT +H / 2-sH / 2) and (X RB +sW,Y LT +H / 2+sH / 2), the coordinates of the top left and bottom right corners of the lower left neighborhood are respectively (X LT -sW,Y RB ) and (X LT ,Y RB +sH), the top-left and bottom-right coordinates of the lower neighbor are respectively (X LT +W / 2-sW / 2,Y RB )-(X LT +W / 2+sW / 2,Y RB +sH), the coordinates of the top left and bottom right corners of the lower right neighborhood are (X) RB ,Y RB ) and (X RB +sW,Y RB +sH); where s is a preset fixed constant, generally greater than 1, to expand the search area.

[0049] In step S402 of some embodiments, the coordinates of the bounding boxes other than the bounding box corresponding to the target sample image are obtained. When the coordinate range of a certain neighboring image overlaps with the coordinate range of the bounding boxes other than the bounding box corresponding to the target sample image, the neighboring image is removed to prevent other sample images from affecting the color recognition of the target sample image.

[0050] In step S403 of some embodiments, the convolutional similarity between the target sample image and the remaining neighboring images is calculated one by one to obtain multiple correlation heatmaps. Each correlation heatmap corresponds one-to-one with a remaining neighboring image. The location with the highest correlation in the heatmaps is identified, and the peak similarity and coordinates corresponding to this location are recorded. The peak similarities of the multiple correlation heatmaps are sorted, and the neighboring image with the highest peak similarity is selected as the target neighboring image. Based on the previously recorded coordinates, an image of the same resolution is cropped from the location with the highest correlation in the target neighboring image to serve as the background image corresponding to the target sample image.

[0051] In other embodiments, reference is made to Figure 5 Step S102 may include, but is not limited to, steps S501 to S502.

[0052] Step S501: Remove the sample corresponding to the sample image to obtain the second original image.

[0053] Step S502: Fill the second original image with image to obtain the background image.

[0054] In step S501 of some embodiments, when the background is neither fixed or known, nor a repeating texture, it is necessary to first remove the corresponding sample from the sample image to obtain a second original image, wherein the portion of the second original image from which the sample has been removed is blank.

[0055] In step S502 of some embodiments, a deep learning filling algorithm is used to fill the blank parts of the second original image to obtain the background image corresponding to the sample image.

[0056] Steps S301 to S302, S401 to S403, and S501 to S502 of this application disclose methods for calculating background images in three cases, which broadens the application scenarios and scope of the color recognition method of this application and also improves the accuracy of color recognition.

[0057] In step S103 of some embodiments, the color parameters finally obtained by this application include the three primary color channel parameters and transparency. All subsequent formulas in the color recognition method of this application are based on a color mixing formula, which is: M C =A·F C +(1-A)·B C ; In this formula, the sample removed from the sample image is used as the foreground image. The foreground image is a four-channel (red, green, blue, and transparency) color image containing only the color information of the bottle flakes. In this formula, c can be r, g, or b, i.e., the three primary colors (red, green, and blue). Taking one pixel as an example, M... CF represents the color parameter in the pixel sample image. C B represents the color parameter in the foreground image for that pixel. C Let A be the color parameter in the background image of this pixel, and let A be the transparency of this pixel.

[0058] The color parameters (red, green, blue, and transparency) in the foreground image are the final color parameters required by this color recognition method. The background image, foreground image, and sample image correspond one-to-one, and each pixel in these images also has a one-to-one correspondence; that is, the pixels to be calculated in the foreground image have corresponding pixels in both the background and foreground images. Furthermore, the background image, foreground image, and sample image are all of the same size, determined by the sample image. Based on the above color mixing formula, the formula for calculating the foreground color parameters can be obtained: ; ; ; In this formula, (F r F g F b F a ) represents the four-channel color (red, green, blue, and transparency) of a single pixel in the foreground image, (B) r B g B b ) represents the three primary color channels (red, green, blue) of the corresponding pixels in the background image, (M) r M g M b ) represents the three primary color channels (red, green, and blue) of the corresponding pixel in the sample image.

[0059] However, the calculation formula for the foreground color parameters described above requires four solutions, but only three constraints, making it an underdetermined system of equations. Since underdetermined systems of equations have infinitely many solutions, the required foreground color parameters cannot be obtained. Therefore, the color recognition method of this application uses the following prior information (known conditions): 1. In the foreground image, adjacent pixels have the same color but different transparency.

[0060] 2. In the foreground image, the color of the edge pixels is always (1.0, 1.0, 1.0, 0.0), meaning the edge pixels are always pure white and completely transparent. In the sample image, if the bottle fragment is close to the edge of the sample image, the bounding box can be expanded by 1 pixel in all directions before image segmentation to obtain the sample image. This will not affect the subsequent calculation results of the color recognition method of this application.

[0061] Based on prior information, the above formulas for calculating foreground color parameters can be reorganized into a new formula for calculating foreground color parameters: ; ; ; ; ; ; In this formula, the pixel obtained from the foreground image is taken as the first target pixel, and the pixel adjacent to and below the first target pixel is taken as the second target pixel. That is, the first target pixel and the second target pixel are two pixels that are vertically adjacent. In this formula, (F r1 F g1 F b1 F a1 ) represents the four-channel color parameters (red, green, blue, and transparency) of the first target pixel in the foreground image, (B) r1 B g1 B b1 ) represents the three primary color channel parameters (red, green, blue) of the pixel corresponding to the first target pixel in the background image, (M) r1 M g1 M b1 ) represents the three primary color channel parameters (red, green, blue) of the pixel corresponding to the first target pixel in the sample image; (F r2 F g2 F b2 F a2 ) represents the four-channel color parameters (red, green, blue, and transparency) of the second target pixel in the foreground image, (B) r2 B g2 B b2 ) represents the three primary color channel parameters (red, green, blue) of the pixel corresponding to the second target pixel in the background image, (M) r2 M g2 M b2 The three primary color channel parameters (red, green, and blue) of the pixel corresponding to the second target pixel in the sample image are given. Thus, the color parameters of each pixel in the foreground image can be obtained by using the calculation formula of the new foreground color parameters. However, the accuracy may be insufficient if the calculation is performed directly by using the calculation formula of the new foreground color parameters. Therefore, the color recognition method of this application introduces gradient values ​​to improve accuracy.

[0062] This application first presets an initial color parameter as the color parameter of each pixel in the foreground image, for example: (1,1,1,0.3). This initial color parameter is a value obtained through the operator's past experience in order to reduce the number of iterations required in subsequent iterations.

[0063] The gradient value is obtained by substituting the three primary color channel parameters of the sample image, the corresponding three primary color channel parameters of the background image, and the initial color parameters into the Jacobian matrix formula derived from the calculation formula of the new foreground color parameters. The Jacobian matrix formula is as follows: ; ; ; In this formula, c can be R, G, or B (i.e., the three primary colors: red, green, and blue), and F... C J represents the parameters of the three primary color channels of the first target pixel in the foreground image. C B represents the gradient value of the three primary colors of the first target pixel. C M represents the parameters of the three primary color channels of the first target pixel in the background image. C B represents the parameter of the three primary color channels of the first target pixel in the sample image. B C M represents the parameters of the three primary color channels of the second target pixel in the background image. B C A1 represents the transparency of the first target pixel in the foreground image, A2 represents the transparency of the second target pixel in the foreground image, and J represents the transparency of the second target pixel in the foreground image. A1 J represents the gradient value of the transparency of the first target pixel. A2 The gradient value of the transparency of the second target pixel.

[0064] In some embodiments, refer to Figure 6 Step S104 may include, but is not limited to, steps S601 to S602.

[0065] Step S601: Based on the initial color parameters, constrain the gradient value to correct the gradient value.

[0066] Step S602: Based on the constrained gradient values, the initial color parameters are updated using the gradient descent method to obtain the color parameters.

[0067] In step S601 of some embodiments, to improve the accuracy of color parameters, the color recognition method of this application introduces constraint terms to correct the gradient values. This application introduces color smoothing constraint terms and transparency smoothing constraint terms. The meaning of the color smoothing constraint term is: for the same bottle piece, adjacent pixels within four neighboring areas should have similar colors; the meaning of the transparency constraint term is: for the same bottle piece, adjacent pixels should have similar transparency. The color smoothing term is divided into horizontal and vertical directions. The calculation formula for the horizontal direction of the color smoothing term is: ; ; ; In this formula, S Rx S Gx and S Bx F represents the color smoothing constraint term of the three primary colors (red, green, and blue) of the first target pixel in the horizontal direction. R F G and F B ω represents the parameters of the three primary color channels of the first target pixel in the foreground image. S The smoothing coefficient is used (generally a value between 0 and 1, and 0.625 is used in this application), i is the row index of the first target pixel in the image, and j is the column index of the first target pixel in the image.

[0068] It should be noted that since the sample image, background image, and foreground image are all the same size, the row and column indices of the first target pixel can be applied to these three types of images. (The same applies to the second target pixel).

[0069] The formula for calculating the vertical direction of the color smoothing term is: ; ; ; In this formula, S Ry S Gy and S By F represents the color smoothing constraint term of the three primary colors (red, green, and blue) of the first target pixel in the vertical direction. R F G and F B ω represents the parameters of the three primary color channels of the first target pixel in the foreground image. S The smoothing coefficient is used (generally a value between 0 and 1, and 0.625 is used in this application), i is the row index of the first target pixel in the image, and j is the column index of the first target pixel in the image.

[0070] Therefore, the gradient values ​​of the three primary colors are adjusted based on the obtained color constraints in the horizontal and vertical directions, and the adjustment formula is as follows: ; Where c can be R, G, or B, J C S represents the gradient values ​​of the three primary colors. cy For the color smoothing constraint term of the three primary colors (red, green, and blue) in the vertical direction of the first target pixel, S cx The first target pixel is a color smoothing constraint term for the three primary colors (red, green, and blue) in the horizontal direction, where i is the row index of the first target pixel in the image and j is the column index of the first target pixel in the image.

[0071] The formula for calculating the transparency smoothing constraint is: ; ; ; In this formula, S A1x Let A1 be the transparency smoothing constraint term for the first target pixel, and ω be the transparency of the first target pixel. a S is the smoothing coefficient (generally a value between 0 and 1; in this application, it is 0.125). A2x Let A2 be the transparency smoothing constraint term for the second target pixel, i be the row index of the first or second target pixel in the image, j be the column index of the first or second target pixel in the image, and S be the transparency of the second target pixel. A12 This is a combined smoothing constraint term for the first target pixel and the second target pixel.

[0072] Therefore, the gradient values ​​of the transparency of the first and second target pixels are adjusted based on the obtained transparency smoothing constraint term, and the adjustment formula is as follows: ; ; In this formula, J A1 J represents the gradient value of the transparency of the first target pixel. A2 The gradient value representing the transparency of the second target pixel, where i is the row index of the first or second target pixel in the image, j is the column index of the first or second target pixel in the image, and S... A1x Let A1 be the transparency smoothing constraint term for the first target pixel, and ω be the transparency of the first target pixel. a S is the smoothing coefficient (generally a value between 0 and 1; in this application, it is 0.125). A2x S is the transparency smoothing constraint term for the second target pixel.A12 This is a combined smoothing constraint term for the first target pixel and the second target pixel.

[0073] Finally, we obtain the gradient values ​​of the three primary colors of the first target pixel, the gradient value of the transparency of the first target pixel, and the gradient value of the transparency of the second target pixel after constraints.

[0074] In step S602 of some embodiments, the initial color parameters are updated and calculated using the standard gradient descent method based on the gradient values ​​of the three primary colors of the first target pixel after constraint, the gradient value of the transparency of the first target pixel, and the gradient value of the transparency of the second target pixel, so as to obtain the color parameters of the first target pixel. The color parameters of each pixel in the foreground image are obtained in the same way, and finally the color parameters of the foreground image are obtained.

[0075] In other embodiments, the color recognition method of this application introduces an error value. Before step S601, the error value needs to be calculated for use in other gradient calculation formulas that require error values, and the color parameters are updated in the direction of gradually decreasing error values ​​according to the gradient values ​​of the three primary colors and transparency. For example, when the error value corresponding to the updated color parameter is greater than a preset threshold, the color parameter is used as the initial color parameter and gradient calculation is performed again to update the initial color parameter, thereby achieving continuous iterative optimization until the error value corresponding to the final output color parameter is less than or equal to the preset threshold. The error value calculation step of the color recognition method of this application is as follows: substitute the obtained color parameter into the above-mentioned calculation formula for the new foreground color parameter, keep the right side of the formula at zero, and then square the values ​​on the left side of the formula and add them together to obtain the error value. For example, substituting the obtained color parameter into the above-mentioned calculation formula for the new foreground color parameter, four expressions are obtained: 2=0, -5=0, 3=0 and 1=0. In this embodiment, only the values ​​of the expressions on the left side of the equal sign are squared and then added together: 2 2 + (-5) 2 +3 2 +1 2 =39, and this 39 is the error value we are looking for.

[0076] It should be noted that the final result is the color parameters of the foreground image. The process described above only shows the process of obtaining the color parameters of one pixel in the foreground image.

[0077] Steps S601 to S602 of this application introduce gradient values ​​and constrain the gradient values, and then update the initial color parameters based on the gradient values ​​to obtain color parameters, thereby further improving the accuracy of the color parameters.

[0078] In some embodiments, refer to Figure 7 Step S105 may include, but is not limited to, steps S701 to S703.

[0079] Step S701: Perform a weighted summation of the color parameters to obtain the target color parameters.

[0080] Step S702: Convert the target color parameters to a preset color space.

[0081] Step S703: Based on a preset threshold, the converted target color parameters are classified into the corresponding color categories to obtain the color category of the sample.

[0082] In step S701 of some embodiments, the color parameters are weighted and summed to obtain the target color parameters, wherein the formula for the weighted summation is: ; In this formula, c can be R, G, or B, and O C The value of the color parameter after weighted summation of the three primary colors, i.e., the target color parameter, F. A1 F is the transparency parameter of the first target pixel in the foreground image. C Let i be the three primary color parameters of the first target pixel in the foreground image, i be the row index of the first target pixel, and j be the column index of the first target pixel.

[0083] In step S702 of some embodiments, the target color parameters are converted to the desired color space, such as the HSV color space. In traditional color recognition methods, the color space is usually converted before the color parameters of the bottle are sampled. Compared with the present application, which directly calculates the color parameters by sampling the sample image of the bottle from the camera and then converts them, the accuracy may be lower due to interference or errors in the conversion process.

[0084] In step S703 of some embodiments, the converted target color parameters are classified according to a preset threshold judgment rule to obtain the color category corresponding to the bottle slice. The main reason for using transparency as a weight is that the color parameters of each pixel in the foreground image are different (some have high transparency, some have low transparency, some are bluish, some are purplish, etc.). Using transparency as a weight can further eliminate background interference, so as to filter out the areas that are truly colored and eliminate interference from other areas (such as areas with too light a color), thereby improving the accuracy of the final color classification.

[0085] Steps S701 to S702 of this application further improve the accuracy of color parameters by weighted summation, so as to obtain more accurate color classification results.

[0086] The final effect achieved by the color recognition method in this application is as follows: Figure 9 ,from Figure 9It can be seen that, after incorporating the background image, the foreground image output by this color recognition method can eliminate background interference, such as... Figure 9 In the output image, regardless of whether the background is white or checkerboard, the color of the bottle pieces in the image will not be affected.

[0087] Reference Figure 8 , Figure 8 This is a schematic diagram of the structure of a color recognition device according to a second aspect embodiment of this application; the color recognition device according to this application embodiment includes: Image processing module 801 is configured to acquire a sample image, wherein the sample image is configured to contain a single sample; and acquire the corresponding background image in the sample image. The parameter calculation module 802 is configured to calculate gradient values ​​based on the three primary color channel parameters of the sample image, the three primary color channel parameters of the corresponding background image, and the preset initial color parameters; and update the initial color parameters based on the gradient values ​​to obtain the color parameters. The category determination module 803 is configured to determine the color category of a sample based on color parameters.

[0088] An embodiment of the third aspect of this application also provides an electronic device, which includes a memory 1002 and a processor 1001. The memory 1002 stores a computer program, and the processor 1001 executes the computer program to implement the color recognition method of the first aspect embodiment described above. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.

[0089] Reference Figure 10 , Figure 10 This is a schematic diagram of the structure of an electronic device according to one embodiment. The electronic device includes: The processor 1001 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 1002 can be implemented as a read-only memory, static storage device, dynamic storage device, or random access memory (RAM). The memory 1002 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1002 and is called and executed by the processor 1001 using the television bezel laser etching method of the embodiments of this application. Input / output interface 1003 is used to implement information input and output; The communication interface 1004 is used to enable communication and interaction between this device and other devices. Communication can be achieved via wired or wireless means. Bus 1005 transmits information between the various components of the device; The processor 1001, memory 1002, input / output interface 1003 and communication interface 1004 are connected to each other within the device via bus 1005.

[0090] A fourth aspect of this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the color recognition method of the first aspect embodiment described above.

[0091] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0092] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. Those skilled in the art will know that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0093] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.

[0094] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0095] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or appropriate combinations thereof.

[0096] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0097] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0098] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0099] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0100] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0101] If the integrated unit is implemented as 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 technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0102] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. A color recognition method, characterized in that, include: Acquire a sample image, which is configured to contain an image of a single sample; Obtain the background image corresponding to the sample image; The gradient value is calculated based on the three primary color channel parameters of the sample image, the corresponding three primary color channel parameters of the background image, and the preset initial color parameters; Based on the gradient value, the initial color parameters are updated to obtain the color parameters; Based on the color parameters, the color category of the sample is determined.

2. The color recognition method according to claim 1, characterized in that, The acquisition of sample images includes: Acquire sample images, which are configured to contain images of multiple said samples; Obtain the coordinate position of each sample in the sample image to form a corresponding bounding box; Based on each of the bounding boxes, the sample images are segmented to obtain multiple sample images.

3. The color recognition method according to claim 1, characterized in that, The step of obtaining the background image corresponding to the sample image includes: The sample corresponding to the sample image is removed to obtain the first original image; The first original image is compared with a plurality of preset pre-selected images one by one to calculate the similarity, and the pre-selected image with the highest similarity is used as the background image.

4. The color recognition method according to claim 1, characterized in that, The step of obtaining the background image corresponding to the sample image includes: Using the sample image as the target sample image, obtain multiple neighboring images that are adjacent to the bounding box of the target sample image in the sample image; Among the multiple neighboring images, neighboring images that contain the bounding boxes of the other sample images besides the target sample image are selected and removed; The remaining neighboring images are compared with the original image one by one, and the neighboring image with the highest similarity is taken as the target neighboring image. An image with the same resolution as the sample image is cropped from the target neighboring image and used as the background image.

5. The color recognition method according to claim 1, characterized in that, The step of obtaining the background image corresponding to the sample image includes: The sample corresponding to the sample image is removed to obtain the second original image; The second original image is filled with image to obtain the background image.

6. The color recognition method according to claim 1, characterized in that, The process of updating the initial color parameters based on the gradient to obtain the color parameters includes: Based on the initial color parameters, the gradient value is constrained to correct the gradient value; Based on the constrained gradient value, the initial color parameters are updated using the gradient descent method to obtain the color parameters.

7. The color recognition method according to claim 1, characterized in that, The step of determining the color category of the sample based on the color parameters includes: The target color parameters are obtained by performing a weighted summation on the color parameters. Convert the target color parameters to a preset color space; Based on a preset threshold, the converted target color parameters are classified into the corresponding color categories to obtain the color category of the sample.

8. A color recognition device, characterized in that, include: An image processing module is configured to acquire a sample image, the sample image being configured to contain an image of a single sample; Obtain the background image corresponding to the sample image; The parameter calculation module is configured to calculate gradient values ​​based on the three primary color channel parameters of the sample image, the corresponding three primary color channel parameters of the background image, and preset initial color parameters. Based on the gradient value, the initial color parameters are updated to obtain the color parameters; The category determination module is configured to determine the color category of the sample based on the color parameters.

9. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the color recognition method according to any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the color recognition method according to any one of claims 1 to 8.