Color recognition method, device and storage device
By converting the RGB color space information of the region of interest in the image into HSI color space information, and calculating the color distance and matching score, the problem of color detection matching in the prior art is solved, and efficient and effective color matching recognition is achieved .
Patent Information
- Application Number
- CN202010600426.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-28
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2040-06-28
AI Technical Summary
The prior art is difficult to achieve efficient and real-time color detection matching, affecting the performance of machine vision systems.
By obtaining the RGB color space information of the region of interest in the image and converting it into HSI color space information, the color distance and matching score between the color and each known color in the pre-established color library are calculated to determine the color matching result.
It improves the real-time color matching, while ensuring the effectiveness of matching results, and is suitable for various machine vision application scenarios.
Smart Images

Figure CN111898616B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the fields of image processing and computer vision, and in particular to a color recognition method, device and storage device. Background Art
[0002] In actual production applications, it is necessary to rely on machine vision to extract color features, such as: Rubik's cube color detection, target color detection, etc. Through color feature extraction, it can provide the machine vision system with a basis for detection and matching, thereby completing the matching and recognition of specific colors and guiding the machine vision system to complete the corresponding functions. Up to now, in order to ensure the effectiveness and real-time performance of color detection and matching, a simple and efficient color recognition method is still needed to be put into actual production applications. Summary of the invention
[0003] The present application provides a color recognition method, device and storage device, which can achieve the purpose of improving the real-time performance of color matching and ensuring the validity of matching results.
[0004] In order to solve the above technical problems, a technical solution adopted by the present application is to provide a color recognition method, comprising:
[0005] Get the RGB color space information of the region of interest in the input image;
[0006] The RGB color space information is converted into HSI color space information, wherein the conversion formula includes:
[0007]
[0008] and
[0009]
[0010] in, is the average R value of the pixels in the region of interest, represents the G average value of the pixels in the region of interest, represents the average value of B of the pixels in the region of interest; n is the number of bits of the image;
[0011] Calculate the color distance between the color of the region of interest and each known color in a pre-established color library according to the HSI color space information;
[0012] The matching scores between the color of the region of interest and each known color in the color library are calculated according to the color distance, and the color in the color library with the highest matching score with the color of the region of interest is used as the color matching result of the region of interest.
[0013] In order to solve the above technical problems, another technical solution adopted by the present application is: to provide a color recognition device, the device comprising a processor and a memory coupled to the processor, wherein:
[0014] The memory stores program instructions for implementing the above-mentioned color recognition method;
[0015] The processor is used to execute the program instructions stored in the memory to achieve color recognition.
[0016] In order to solve the above technical problem, another technical solution adopted by the present application is: providing a storage device storing a program file capable of implementing the above color recognition method.
[0017] The beneficial effects of the present application are as follows: the color recognition method, device and storage device of the present invention obtain the RGB color space information of the region of interest in the input image; convert the RGB color space information into HSI color space information; calculate the color distance between the color of the region of interest and each known color in the pre-established color library according to the HSI color space information; calculate the matching score between the color of the region of interest and each known color in the color library according to the color distance, and use the color in the color library with the highest matching score with the color of the region of interest as the color matching result of the region of interest. In the above manner, the real-time performance of color matching is improved while ensuring the validity of the matching result. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 is a schematic flow chart of a color recognition method according to a first embodiment of the present invention;
[0019] Figure 2 is a flow chart of a color recognition method according to a second embodiment of the present invention;
[0020] Figure 3 is a first structural schematic diagram of a color recognition device according to an embodiment of the present invention;
[0021] Figure 4 is a second structural schematic diagram of the color recognition device according to an embodiment of the present invention;
[0022] Figure 5 Schematic diagram of the structure of a storage device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0023] 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.
[0024] The terms "first", "second", "third" in this application are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the features defined as "first", "second", "third" can expressly or implicitly include at least one of the features. In the description of this application, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined. In the embodiments of this application, all directional indications (such as up, down, left, right, front, back...) are only used to explain the relative position relationship, movement, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication also changes accordingly. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the steps or units listed, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices.
[0025] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0026] Figure 1 FIG. 1 is a flow chart of the color recognition method of the first embodiment of the present invention. It should be noted that if there is substantially the same result, the method of the present invention is not limited to the method of FIG. Figure 1 The process sequence shown is limited. Figure 1 As shown, the method comprises the steps of:
[0027] Step S101: establishing a color library, which includes HSI color space information of multiple known colors.
[0028] Optionally, in step S101, multiple images of known colors are input in sequence, and the RGB color space information of each known color is extracted respectively, and then the RGB color space information of each known color is converted into HSI color space information through a conversion formula, where H represents hue, S represents saturation, and I represents intensity. Finally, a color library is established based on the mapping relationship between each known color and the corresponding HSI color space information.
[0029] Optionally, the RGB color space information of each known color includes the pixel information in the area where the known color is located. and The corresponding calculation formula is as follows
[0030]
[0031] Wherein, N is the total number of pixels, which in step S101 is specifically the total number of pixels in the area corresponding to the known color, R i represents the R value of the i-th pixel, G i represents the G value of the i-th pixel, B i represents the B value of the i-th pixel, Represents the R average value of the pixels in the area corresponding to the known color. Represents the G average value of the pixels in the area corresponding to the known color. Indicates the B average value of the pixels in the area corresponding to the known color.
[0032] Optionally, the conversion formula includes:
[0033]
[0034] and
[0035]
[0036] Wherein, n is the number of image bits, specifically the number of bits of the pixel values of the pixels in the image. In step S101, specifically the number of bits of the pixel values of the pixels in the image corresponding to the known color, optionally, n is 8.
[0037] Optionally, if the H value obtained by the above conversion formula is a negative number, then H=H+360.
[0038] Through the above method, the HSI color space information of each known color is extracted using a statistical method, and then a color library is established in advance. In the actual application process, only color matching and recognition need to be performed, which greatly improves the real-time performance of the algorithm; and the method in this embodiment can establish a corresponding color library for specific application scenarios, thereby ensuring the effectiveness of the matching results.
[0039] Step S102: Obtain HSI color space information of the region of interest.
[0040] Optionally, in step S102, the image where the region of interest is located is first input, then the RGB color space information of the region of interest is obtained, and finally the RGB color space information of the region of interest is converted into HSI color space information by the aforementioned conversion formula.
[0041] Optionally, the method for obtaining the RGB color space information of the region of interest is the same as the method for obtaining the RGB color space information of the known color in step S101, and for the sake of brevity, it is not repeated here.
[0042] Step S103: Calculate the color distance between the color of the region of interest and each known color in the color library.
[0043] Optionally, in step S103, the color distances between the color of the region of interest and each known color in a pre-established color library are calculated using a first formula, and the first formula is:
[0044]
[0045] Wherein, d represents the color distance, H1, S1 and I1 are the HSI color space information of the region of interest, H0, S0 and I0 are the HSI color space information of any known color, and n is the number of image bits, specifically the number of bits of the pixel value of the pixel in the image, and optionally, n is 8.
[0046] Step S104: Calculate the matching scores between the color of the region of interest and each known color in the color library, and use the color in the color library with the highest matching score with the color of the region of interest as the color matching result of the region of interest.
[0047] Optionally, in step S104, the matching scores between the color of the region of interest and each known color in the color library are calculated respectively by a second formula, and the second formula is:
[0048]
[0049] Wherein, score represents the matching score, d represents the corresponding color distance, and n represents the number of image bits, specifically the number of bits of the pixel values of the pixels in the image. Optionally, n is 8.
[0050] Optionally, after calculating the matching scores between the color of the region of interest and each known color in the color library, the color in the color library with the highest matching score with the color of the region of interest is output as the color matching result of the region of interest to complete the color recognition process.
[0051] The color recognition method of the first embodiment of the present invention extracts the RGB color space information of each known color through a statistical method, and then converts it into HSI color space information through the conversion formula in the present invention, and pre-establishes a color library. In actual application, it is only necessary to extract the HSI color space information of the area of interest, and then perform color matching and recognition, which greatly improves the real-time performance of the algorithm and makes the entire recognition process simple and efficient. In addition, this embodiment can establish a corresponding color library for specific application scenarios to ensure the effectiveness of the matching results.
[0052] Figure 2 FIG. 1 is a flow chart of a color recognition method according to a second embodiment of the present invention. It should be noted that if substantially the same results are achieved, the method of the present invention is not limited to the method of FIG. Figure 2 The process sequence shown is limited. Figure 2 As shown, the method comprises the steps of:
[0053] Step S201: establishing a color library, which includes HSI color space information of multiple known colors.
[0054] Step S202: Obtain HSI color space information of the region of interest.
[0055] Step S203: Calculate the color distance between the color of the region of interest and each known color in the color library.
[0056] Step S204: Calculate the matching scores between the color of the region of interest and each known color in the color library, and use the color in the color library with the highest matching score with the color of the region of interest as the color matching result of the region of interest.
[0057] In this embodiment, Figure 2 Steps S201 to S204 in Figure 1 Steps S101 to S104 in are similar and will not be described again for simplicity.
[0058] Step S205: Calculate the confidence of the color matching result, and determine the validity of the color matching result according to the confidence.
[0059] Optionally, in step S205, the confidence of the color matching result is calculated by a third formula, and the third formula is:
[0060]
[0061] Wherein, c represents the confidence, score1 is the highest matching score among the matching scores calculated in step S204, score2 is the second highest matching score among the matching scores calculated in step S204, and M is a preset parameter. Optionally, M is 1.01.
[0062] It should be noted that when there is only one matching score among the matching scores calculated by step S204, score2 in the sixth formula is 0. Confidence is a parameter for judging the validity of matching results. The larger the confidence value, the larger the gap between the highest matching score and the second highest matching score, and the more reliable the matching result is, which is a valid matching result. The smaller the value, the smaller the gap between the highest matching score and the second highest matching score, and the less reliable the matching result is, and there is a matching error. When the highest matching score and the second highest matching score are equal, the calculated confidence is 0, indicating that the matching result is unreliable. In the above manner, the user can judge whether it is necessary to change external conditions such as taking pictures and re-acquire image information according to the calculated confidence to ensure the validity of the matching result.
[0063] The color recognition method of the second embodiment of the present invention is to establish a color library, which includes HSI color space information of multiple known colors; obtain HSI color space information of the region of interest; calculate the color distance between the color of the region of interest and each known color in the color library; calculate the matching score between the color of the region of interest and each known color in the color library, and use the color in the color library with the highest matching score with the color of the region of interest as the color matching result of the region of interest; calculate the confidence of the color matching result, and determine the validity of the color matching result according to the confidence. Through the above method, while improving the real-time performance of color matching, the validity of the color matching result is further guaranteed.
[0064] See also Figure 3 , Figure 3 FIG. 1 is a first structural diagram of a color recognition device according to an embodiment of the present invention. Figure 3 As shown, the device 30 includes an acquisition module 31 , a conversion module 32 , a color distance calculation module 33 and a matching score calculation module 34 .
[0065] The acquisition module 31 is used to acquire the RGB color space information of the region of interest in the input image. Optionally, the RGB color space information includes the pixels in the region of interest. and is the average R value of the pixels in the region of interest, represents the average G value of the pixels in the region of interest, Represents the B average value of the pixels in the region of interest.
[0066] The conversion module 32 is coupled to the acquisition module 31 and is used to convert the RGB color space information into the HSI color space information, wherein the conversion formula includes:
[0067]
[0068] and
[0069]
[0070] Wherein, n is the number of bits of the image, and optionally, n is 8.
[0071] Optionally, if the H value obtained by the conversion formula is a negative number, then H=H+360.
[0072] The color distance calculation module 33 is coupled to the conversion module 32 and is used to calculate the color distance between the color of the region of interest and each known color in the pre-established color library according to the HSI color space information.
[0073] The matching score calculation module 34 is coupled to the color distance calculation module 33 and is used to calculate the matching score between the color of the region of interest and each known color in the color library according to the color distance, and take the color in the color library with the highest matching score with the color of the region of interest as the color matching result of the region of interest.
[0074] Optionally, the acquisition module 31 is further configured to acquire RGB color space information of each known color.
[0075] Optionally, the conversion module 32 is further configured to convert RGB color space information of each known color into HSI color space information.
[0076] Optionally, the device 30 further includes a color library establishing module 35 , which is coupled to the conversion module 32 and is used to establish a color library based on a mapping relationship between each known color and the corresponding HSI color space information.
[0077] Optionally, the color distance calculation module 33 is further coupled to the color library establishment module 35 , and the color distance calculation module 33 calculates the color distance between the color of the region of interest and each known color in the pre-established color library based on the first formula.
[0078] Optionally, the first formula is:
[0079]
[0080] Among them, H1, S1 and I1 are the HSI color space information of the region of interest, and H0, S0 and I0 are the HSI color space information of the known color.
[0081] Optionally, the matching score calculation module 34 calculates the matching score between the color of the region of interest and each known color in the color library based on the second formula.
[0082] Optionally, the second formula is:
[0083]
[0084] Optionally, the device 30 further includes a confidence calculation module 36, which is coupled to the matching score calculation module 34 and is used to calculate the confidence of the color matching result and determine the validity of the color matching result according to the confidence.
[0085] Optionally, the confidence calculation module 36 calculates the confidence of the color matching result based on a third formula. Optionally, the third formula is:
[0086]
[0087] Wherein, score1 is the highest matching score among the matching scores calculated by the matching score calculation module 34, score2 is the second highest matching score among the matching scores calculated by the matching score calculation module 34, and M is a preset parameter. Optionally, M is 1.01.
[0088] See also Figure 4 , Figure 4 FIG. 2 is a second structural diagram of a color recognition device according to an embodiment of the present invention. Figure 4 As shown, the device 40 includes a processor 41 and a memory 42 coupled to the processor 41 .
[0089] The memory 42 stores program instructions for implementing the color recognition method described in any of the above embodiments.
[0090] The processor 41 is used to execute program instructions stored in the memory 42 to achieve color recognition.
[0091] The processor 41 may also be referred to as a CPU (Central Processing Unit). The processor 41 may be an integrated circuit chip having the ability to process signals. The processor 41 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0092] See also Figure 5 , Figure 5Schematic diagram of the structure of the storage device of the embodiment of the present invention. The storage device of the embodiment of the present invention stores a program file 51 that can implement all the above methods, wherein the program file 51 can be stored in the above storage device in the form of a software product, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage device includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes, or terminal devices such as computers, servers, mobile phones, tablets, etc.
[0093] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0094] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional units. The above is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by using the contents of the specification and drawings of this application, or directly or indirectly used in other related technical fields, is also included in the patent protection scope of the present application.
Claims
1. A color recognition method, characterized in that: include: Get the RGB color space information of the region of interest in the input image; The RGB color space information is converted into HSI color space information, wherein the conversion formula includes: and in, is the average R value of the pixels in the region of interest, represents the G average value of the pixels in the region of interest, represents the average value of B of the pixels in the region of interest; n is the number of bits of the image; Calculate the color distance between the color of the region of interest and each known color in a pre-established color library according to the HSI color space information; Calculating the matching score between the color of the region of interest and each known color in the color library according to the color distance, and taking the color in the color library with the highest matching score with the color of the region of interest as the color matching result of the region of interest; The method for establishing the color library comprises: Obtain the RGB color space information of each known color respectively; Convert the RGB color space information of each of the known colors into HSI color space information; The color library is established based on the mapping relationship between each known color and the corresponding HSI color space information; the color distance d between the color of the region of interest and each known color in the pre-established color library is calculated based on a first formula, and the first formula is: Among them, H1, S1 and I1 are the HSI color space information of the region of interest, H0, S0 and I0 are the HSI color space information of the known color, and n is the number of bits of the pixel value of the pixel in the image.
2. The method according to claim 1, characterized in that The matching score between the color of the region of interest and each known color in the color library is calculated based on a second formula, where the second formula is:
3. The method according to claim 2, characterized in that Also includes: Calculating the confidence of the color matching result; The validity of the color matching result is determined according to the confidence level.
4. The method according to claim 3, characterized in that The confidence of the color matching result is calculated based on a third formula, and the third formula is: Among them, score1 is the highest matching score among the matching scores, score2 is the second highest matching score among the matching scores, and M is a preset parameter.
5. The method according to claim 4, characterized in that The M is 1.
01.
6. The method according to any one of claims 1 to 5, characterized in that If the obtained H value is a negative number, then H=H+360.
7. A color recognition device, characterized in that: The device comprises a processor and a memory coupled to the processor, wherein: The memory stores program instructions for implementing the color recognition method according to any one of claims 1 to 6; The processor is used to execute the program instructions stored in the memory to achieve color recognition.
8. A storage device, characterized in that: A program file capable of implementing the color recognition method according to any one of claims 1 to 6 is stored.
Citation Information
Patent Citations
Method and device for color matching
CN103024354A