A color recognition method, apparatus, device and medium
By obtaining the component values and weighted changes of the three primary colors of the sample being tested, and combining them with the calibrated reference value, the problem of large color recognition deviation in the existing technology is solved, and more accurate color recognition is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-10
- Publication Date
- 2026-03-06
AI Technical Summary
In existing technologies, color identification is performed by quantizing the three primary colors of the sample being tested. However, the identification results deviate significantly from the actual colors, and the image processing methods are costly.
By acquiring the component values of the three primary colors of the sample being tested, the amount of change in the primary colors is determined, and the sample color is judged according to the weight of the change. The calibrated reference value is used for calibration to reduce external interference and achieve accurate color recognition.
It improves the accuracy of color recognition, reduces the impact of light source and hardware errors on recognition results, and lowers costs.
Smart Images

Figure CN115372275B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of color recognition technology, and in particular to a color recognition method, apparatus, device, and medium. Background Technology
[0002] Currently, colors are generally identified by the quantization values and quantization ratios of the three primary colors of the sample being tested. However, this method has too large a deviation and is not suitable for color differentiation. On the other hand, image processing methods are too costly. Summary of the Invention
[0003] This invention provides a color recognition method, apparatus, device, and medium to solve the problem in the prior art that directly uses the quantization values of the three primary colors of the sample to obtain the quantization ratio for color recognition, which results in a large deviation between the recognized color and the actual color of the sample.
[0004] To solve the above problems, the present invention adopts the following technical solution:
[0005] In a first aspect, the present invention provides a color recognition method, the method comprising:
[0006] Obtain the component values of the three primary colors of the sample being tested;
[0007] The variation amount of the three primary colors is determined based on the component values of the three primary colors and the preset calibrated reference values of the three primary colors.
[0008] Determine whether the changes in the three primary colors all exceed the set values;
[0009] If the changes in the three primary colors all exceed the set value, then the weights of the changes in the three primary colors are determined based on the changes in the three primary colors.
[0010] The color of the sample being tested is determined based on the weights of the changes in the three primary colors.
[0011] A further technical solution is that determining the weights of the changes in the three primary colors based on their changes includes:
[0012] The total amount of change of the three primary colors is determined based on the amount of change of the three primary colors.
[0013] The weights of the changes in the three primary colors are determined based on the amount of change in the three primary colors and the total amount of change in the three primary colors.
[0014] A further technical solution is that the changes in the three primary colors include changes in red, green, and blue. Determining the color of the sample to be tested based on the weights of the changes in the three primary colors includes:
[0015] Determine whether the following conditions are met simultaneously: the weight of the red change is greater than the weight of the green change, and the weight of the green change is greater than the weight of the blue change.
[0016] If the weight of the red change is greater than the weight of the green change and the weight of the green change is greater than the weight of the blue change, then the color of the sample being tested is determined to be orange.
[0017] A further technical solution is that determining the color of the sample to be tested based on the weights of the changes in the three primary colors includes:
[0018] Determine whether the following conditions are met simultaneously: the weight of the green change is greater than the weight of the red change, and the weight of the red change is greater than the weight of the blue change.
[0019] If the weight of the green change is greater than the weight of the red change and the weight of the red change is greater than the weight of the blue change, then the color of the sample being tested is determined to be beige.
[0020] A further technical solution is that determining the color of the sample to be tested based on the weights of the changes in the three primary colors includes:
[0021] Determine whether the following conditions are met simultaneously: the weight of the blue change is greater than the weight of the green change, and the weight of the green change is greater than the weight of the red change.
[0022] If the weight of the blue change is greater than the weight of the green change and the weight of the green change is greater than the weight of the red change, then the color of the sample being tested is determined to be white.
[0023] A further technical solution is that, before obtaining the component values of the three primary colors of the sample being tested, the method further includes:
[0024] Obtain the quantization values of the three primary colors of the tray;
[0025] The average value of the quantization values of the three primary colors is determined based on their respective quantization values, and the average value is used as the reference value for the three primary colors to be calibrated.
[0026] The reference values of the three primary colors to be calibrated are calibrated to obtain the reference values of the three primary colors that have been calibrated.
[0027] A further technical solution is that, after determining whether the changes in the three primary colors all exceed a set value, the method further includes:
[0028] If at least one of the changes in the three primary colors does not exceed the set value, then return to the step of determining whether the changes in the three primary colors all exceed the set value.
[0029] In a second aspect, the present invention also provides a color recognition device, including a unit for performing the method as described in the first aspect.
[0030] Thirdly, the present invention also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0031] Memory, used to store computer programs;
[0032] When a processor executes a program stored in memory, it implements the steps of the method described in the first aspect.
[0033] Fourthly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method described in the first aspect.
[0034] The technical solution provided by this invention has the following advantages compared with the prior art:
[0035] In this invention, the component values of the three primary colors of the sample to be tested are first obtained; then, the change amount of the three primary colors is determined based on the component values of the three primary colors and the preset calibrated reference values of the three primary colors; next, it is determined whether the change amount of the three primary colors exceeds the set value; if the change amount of the three primary colors exceeds the set value, it means that the sample to be tested has been placed in the testing device, and the weight of the change amount of the three primary colors is determined based on the change amount of the three primary colors; finally, the color of the sample to be tested is determined based on the weight of the change amount of the three primary colors. Therefore, calculating the color of the sample to be tested by using the weight of the change amount of the three primary colors of the sample to be tested can ensure accuracy. At this time, no matter how the light source, hardware error, or other factors change, the weight of the change amount of the three primary colors remains basically unchanged or changes very little. Thus, compared with the method of directly identifying the color by the quantization value of the three primary colors of the sample to be tested, this invention makes the color recognition result more accurate. Attached Figure Description
[0036] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0037] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0038] Figure 1 This is a schematic flowchart of a color recognition method provided in Embodiment 1 of the present invention;
[0039] Figure 2 This is a structural block diagram of a color recognition device provided in Embodiment 2 of the present invention;
[0040] Figure 3 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. Detailed Implementation
[0041] To better understand the technical content of the present invention, the technical solution of the present invention will be further introduced and explained below with reference to specific embodiments, but is not limited thereto.
[0042] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0043] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0044] It should also be understood that the term “and / or” as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0045] Example 1
[0046] See Figure 1 , Figure 1 This is a flowchart illustrating a color recognition method provided in Embodiment 1 of the present invention. Specifically, as shown... Figure 1 As shown, the method includes the following steps S101-S105.
[0047] S101, obtain the component values of the three primary colors of the sample being tested.
[0048] Specifically, the processor acquires the component values of the three primary colors of the sample being tested.
[0049] S102, determine the amount of change of the three primary colors based on the component values of the three primary colors and the preset reference values of the three primary colors that have been calibrated.
[0050] Specifically, the processor determines the changes in the red, green, and blue primary colors of the sample under test based on the component values of the red, green, and blue primary colors and the preset calibrated reference values of the three primary colors. The changes in the red, green, and blue primary colors of the sample under test are obtained by subtracting the reference value from the component values of the red, green, and blue primary colors of the sample under test. The preset calibrated reference values of the three primary colors are obtained by sampling and detecting a series of data using a three-primary-color sensor on an empty tray, and then the processor calculates and calibrates the series of data.
[0051] S103, determine whether the changes in the three primary colors all exceed the set values.
[0052] Specifically, the processor determines whether to place the sample to be tested in the three primary color sensor by judging whether the changes in the three primary colors of red, green and blue all exceed the set value.
[0053] S104, if the changes in the three primary colors all exceed the set values, then the weights of the changes in the three primary colors are determined based on the changes in the three primary colors.
[0054] Specifically, when the changes in the three primary colors of red, green, and blue all exceed the set values, it indicates that the sample to be tested has been placed in the three primary color sensor, and the processor begins to identify and determine which color the sample to be tested is.
[0055] S105, determine the color of the sample to be tested based on the weights of the changes in the three primary colors.
[0056] Specifically, the processor then determines the color of the sample being tested based on the weights of the changes in the three primary colors.
[0057] In one embodiment, determining the weights of the changes in the three primary colors based on the changes in the three primary colors includes:
[0058] The total amount of change of the three primary colors is determined based on the amount of change of the three primary colors.
[0059] The weights of the changes in the three primary colors are determined based on the amount of change in the three primary colors and the total amount of change in the three primary colors.
[0060] Specifically, the processor adds the changes in the three primary colors to obtain the total change in the three primary colors, and then determines the weight of the changes in the three primary colors based on the changes in the three primary colors and the total change in the three primary colors. The weight of each of the three primary colors is the ratio of the change in the three primary colors to the total change in the three primary colors. This ratio reflects the weight of the changes in the three primary colors. The larger the weight of the change in a primary color, the higher the color content of that primary color.
[0061] In one embodiment, the changes in the three primary colors include changes in red, green, and blue. Determining the color of the sample to be detected based on the weights of the changes in the three primary colors includes:
[0062] Determine whether the following conditions are met simultaneously: the weight of the red change is greater than the weight of the green change, and the weight of the green change is greater than the weight of the blue change.
[0063] If the weight of the red change is greater than the weight of the green change and the weight of the green change is greater than the weight of the blue change, then the color of the sample being tested is determined to be orange.
[0064] Specifically, when the weight of the red change is greater than the weight of the green change and the weight of the green change is greater than the weight of the blue change, the processor determines that the color of the sample being detected is orange.
[0065] In one embodiment, determining the color of the sample to be detected based on the weights of the changes in the three primary colors includes:
[0066] Determine whether the following conditions are met simultaneously: the weight of the green change is greater than the weight of the red change, and the weight of the red change is greater than the weight of the blue change.
[0067] If the weight of the green change is greater than the weight of the red change and the weight of the red change is greater than the weight of the blue change, then the color of the sample being tested is determined to be beige.
[0068] Specifically, when the weight of the green change is greater than the weight of the red change and the weight of the red change is greater than the weight of the blue change, the processor determines that the color of the sample being tested is beige.
[0069] In one embodiment, determining the color of the sample to be detected based on the weights of the changes in the three primary colors includes:
[0070] Determine whether the following conditions are met simultaneously: the weight of the blue change is greater than the weight of the green change, and the weight of the green change is greater than the weight of the red change.
[0071] If the weight of the blue change is greater than the weight of the green change and the weight of the green change is greater than the weight of the red change, then the color of the sample being tested is determined to be white.
[0072] Specifically, when the weight of the blue change is greater than the weight of the green change, and the weight of the green change is greater than the weight of the red change, the processor determines that the color of the sample being tested is white. The determination processes for orange, beige, and white are performed in parallel. Therefore, by comparing the weights of the changes in the three primary colors, it determines which color the synthesized color is more inclined towards, thereby determining the color of the sample being tested and achieving rapid identification of a limited set of specified colors, that is, quickly identifying whether the color of the sample being tested is one of the specified orange, beige, or white colors.
[0073] In one embodiment, before acquiring the component values of the three primary colors of the sample being tested, the method further includes: acquiring the quantization values of the three primary colors of the tray respectively;
[0074] The average value of the quantization values of the three primary colors is determined based on their respective quantization values, and the average value is used as the reference value for the three primary colors to be calibrated.
[0075] The reference values of the three primary colors to be calibrated are calibrated to obtain the reference values of the three primary colors that have been calibrated.
[0076] Specifically, based on the reference values of the three calibrated primary colors, it is possible to identify whether the sample being tested is in the detection position and to make the color recognition results more accurate and more resistant to external interference.
[0077] In one embodiment, calibrating the reference values of the three primary colors to be calibrated to obtain the calibrated reference values of the three primary colors includes:
[0078] Real-time acquisition of light intensity information within the tray;
[0079] Determine whether the light intensity inside the tray has changed based on the light intensity information inside the tray;
[0080] If the light intensity inside the tray changes, the quantization values of the three primary colors of the tray are obtained.
[0081] The average value of the quantization values of the three primary colors is determined based on their respective quantization values, and the average value is used as the reference value for the calibrated three primary colors.
[0082] Specifically, the reference values for the three primary colors are measured without a sample in the capsule holder (i.e., testing the tray in an empty state). These reference values serve as the basis for determining the presence or absence of a sample and for color determination. Due to external interference such as mechanical structure errors and different lighting conditions (e.g., when testing the sample, the capsule holder must be removed and placed back on, so the position of the capsule holder may change, which will cause changes in the reference values of the three primary colors; or due to individual differences in the supplementary lighting, the light intensity inside the tray may change, thus causing changes in the reference values of the three primary colors), the reference values are calibrated to achieve more accurate identification. That is, when the movement of the tray is detected or the light intensity inside the tray changes, the quantization values of the three primary colors of the tray are re-acquired, and the average value of the quantization values of the three primary colors of the tray is taken to obtain the average value of the quantization values of the three primary colors. The average value of the quantization values of the three primary colors is used as the calibrated reference values of the three primary colors, so that the reference values of the three primary colors are obtained after calibration. Therefore, when testing a sample, the change in the three primary colors of the sample is calculated based on the calibrated reference values of the three primary colors. Thus, based on the calibrated reference values of the three primary colors, it is possible to identify whether the sample is in the detection position and to make the color recognition results more accurate and more resistant to external interference.
[0083] In one embodiment, after determining whether the changes in the three primary colors all exceed a set value, the method further includes:
[0084] If at least one of the changes in the three primary colors does not exceed the set value, then return to the step of determining whether the changes in the three primary colors all exceed the set value.
[0085] Specifically, if at least one of the changes in the three primary colors of red, green, and blue does not exceed the set value, it indicates that no sample to be tested has been placed in the three primary color sensor. In this case, the process returns to the step of determining whether the changes in the three primary colors all exceed the set value, so as to continue to detect whether a sample to be tested has been placed.
[0086] Example 2
[0087] like Figure 2 As shown, this embodiment of the invention also provides a color recognition device 400, which includes a first acquisition unit 401, a first determination unit 402, a first judgment unit 403, a second determination unit 404, and a third determination unit 405.
[0088] The first acquisition unit 401 is used to acquire the component values of the three primary colors of the sample being tested;
[0089] The first determining unit 402 is used to determine the amount of change of the three primary colors based on the component values of the three primary colors and the preset reference values of the three primary colors that have been calibrated.
[0090] The first judgment unit 403 is used to determine whether the change amount of the three primary colors exceeds the set value;
[0091] The second determining unit 404 is used to determine the weight of the change amount of the three primary colors based on the change amount of the three primary colors if the change amount of the three primary colors all exceed the set value.
[0092] The third determining unit 405 is used to determine the color of the sample being tested based on the weights of the changes in the three primary colors.
[0093] In one embodiment, determining the weights of the changes in the three primary colors based on the changes in the three primary colors includes:
[0094] The total amount of change of the three primary colors is determined based on the amount of change of the three primary colors.
[0095] The weights of the changes in the three primary colors are determined based on the amount of change in the three primary colors and the total amount of change in the three primary colors.
[0096] In one embodiment, the changes in the three primary colors include changes in red, green, and blue. Determining the color of the sample to be detected based on the weights of the changes in the three primary colors includes:
[0097] Determine whether the following conditions are met simultaneously: the weight of the red change is greater than the weight of the green change, and the weight of the green change is greater than the weight of the blue change.
[0098] If the weight of the red change is greater than the weight of the green change and the weight of the green change is greater than the weight of the blue change, then the color of the sample being tested is determined to be orange.
[0099] In one embodiment, determining the color of the sample to be detected based on the weights of the changes in the three primary colors includes:
[0100] Determine whether the following conditions are met simultaneously: the weight of the green change is greater than the weight of the red change, and the weight of the red change is greater than the weight of the blue change.
[0101] If the weight of the green change is greater than the weight of the red change and the weight of the red change is greater than the weight of the blue change, then the color of the sample being tested is determined to be beige.
[0102] In one embodiment, determining the color of the sample to be detected based on the weights of the changes in the three primary colors includes:
[0103] Determine whether the following conditions are met simultaneously: the weight of the blue change is greater than the weight of the green change, and the weight of the green change is greater than the weight of the red change.
[0104] If the weight of the blue change is greater than the weight of the green change and the weight of the green change is greater than the weight of the red change, then the color of the sample being tested is determined to be white.
[0105] In one embodiment, before acquiring the component values of the three primary colors of the sample being tested, the method further includes: acquiring the quantization values of the three primary colors of the tray respectively;
[0106] The average value of the quantization values of the three primary colors is determined based on their respective quantization values, and the average value is used as the reference value for the three primary colors to be calibrated.
[0107] The reference values of the three primary colors to be calibrated are calibrated to obtain the reference values of the three primary colors that have been calibrated.
[0108] In one embodiment, after determining whether the changes in the three primary colors all exceed a set value, the method further includes:
[0109] If at least one of the changes in the three primary colors does not exceed the set value, then return to the step of determining whether the changes in the three primary colors all exceed the set value.
[0110] Example 3
[0111] See Figure 3 The present invention also provides an electronic device, including a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112 and the memory 113 communicate with each other through the communication bus 114.
[0112] Memory 113 is used to store computer programs;
[0113] The processor 111 is used to execute the program stored in the memory 113 to implement the color recognition method provided in any of the foregoing method embodiments.
[0114] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed by processor 111, implements the steps of the color recognition method provided in any of the foregoing method embodiments.
[0115] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0116] The above description is merely a specific embodiment of the present invention, enabling those skilled in the art to understand or implement the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features of the invention herein.
Claims
1. A color recognition method characterized by, The method comprises: obtaining component values of three primary colors of a detected sample; determining variation amounts of the three primary colors according to the component values of the three primary colors and preset calibrated reference values of the three primary colors; wherein the reference values of the three primary colors are measured without a sample capsule, i.e. the reference values of the three primary colors are measured in an empty tray, and the reference values of the three primary colors are used as a reference for judging whether there is a sample and color judgment; determining whether the variation amounts of the three primary colors all exceed a set value; if the variation amounts of the three primary colors all exceed the set value, determining a total amount of the variation amounts of the three primary colors according to the variation amounts of the three primary colors; determining weights of the variation amounts of the three primary colors according to the variation amounts of the three primary colors and the total amount of the variation amounts of the three primary colors; determining a color of the detected sample according to the weights of the variation amounts of the three primary colors, wherein the color is orange, beige or white; the variation amounts of the three primary colors include a red variation amount, a green variation amount and a blue variation amount; wherein the determination of the color of the detected sample according to the weights of the variation amounts of the three primary colors comprises: determining whether the red variation amount is greater than the green variation amount and the green variation amount is greater than the blue variation amount; if the red variation amount is greater than the green variation amount and the green variation amount is greater than the blue variation amount, determining that the color of the detected sample is orange; determining whether the green variation amount is greater than the red variation amount and the red variation amount is greater than the blue variation amount; if the green variation amount is greater than the red variation amount and the red variation amount is greater than the blue variation amount, determining that the color of the detected sample is beige; determining whether the blue variation amount is greater than the green variation amount and the green variation amount is greater than the red variation amount; if the blue variation amount is greater than the green variation amount and the green variation amount is greater than the red variation amount, determining that the color of the detected sample is white.
2. The color recognition method according to claim 1, characterized in that, Before the obtaining of the component values of the three primary colors of the detected sample, the method further comprises: obtaining quantized values of the three primary colors of the tray; determining an average value of the quantized values of the three primary colors according to the quantized values of the three primary colors, and taking the average value as reference values of the three primary colors to be calibrated; calibrating the reference values of the three primary colors to be calibrated to obtain the calibrated reference values of the three primary colors.
3. The color recognition method of claim 1, wherein, After the determination of whether the variation amounts of the three primary colors all exceed the set value, the method further comprises: if at least one of the variation amounts of the three primary colors does not exceed the set value, returning to the step of determining whether the variation amounts of the three primary colors all exceed the set value.
4. A color recognition device, characterized by, The device comprises units for performing the method of any one of claims 1-3.
5. An electronic device, comprising: The device comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete communication with each other through the communication bus; the memory is used for storing a computer program; and the processor is used for executing the computer program stored in the memory. A processor for implementing the steps of the method according to any one of claims 1-3 when executing a program stored on a memory.
6. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program, when executed by a processor, implements the steps of the method according to any one of claims 1-3.
Citation Information
Patent Citations
Color signal correction method
JP2002084546A
Item processing verification using imaging
US9248965B1