[go: up one dir, main page]

CN116403009A - A Color Recognition Method Based on Template Matching - Google Patents

A Color Recognition Method Based on Template Matching Download PDF

Info

Publication number
CN116403009A
CN116403009A CN202211575996.XA CN202211575996A CN116403009A CN 116403009 A CN116403009 A CN 116403009A CN 202211575996 A CN202211575996 A CN 202211575996A CN 116403009 A CN116403009 A CN 116403009A
Authority
CN
China
Prior art keywords
image
template
color
hue
method based
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211575996.XA
Other languages
Chinese (zh)
Inventor
王培�
覃高鄂
陈宗民
邹骏宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuxi Xinje Electric Co Ltd
Original Assignee
Wuxi Xinje Electric Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuxi Xinje Electric Co Ltd filed Critical Wuxi Xinje Electric Co Ltd
Priority to CN202211575996.XA priority Critical patent/CN116403009A/en
Publication of CN116403009A publication Critical patent/CN116403009A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/74Image or video pattern matching; Proximity measures in feature spaces
    • G06V10/75Organisation of the matching processes, e.g. simultaneous or sequential comparisons of image or video features; Coarse-fine approaches, e.g. multi-scale approaches; using context analysis; Selection of dictionaries
    • G06V10/751Comparing pixel values or logical combinations thereof, or feature values having positional relevance, e.g. template matching
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/20Image preprocessing
    • G06V10/25Determination of region of interest [ROI] or a volume of interest [VOI]
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/40Extraction of image or video features
    • G06V10/50Extraction of image or video features by performing operations within image blocks; by using histograms, e.g. histogram of oriented gradients [HoG]; by summing image-intensity values; Projection analysis
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/40Extraction of image or video features
    • G06V10/56Extraction of image or video features relating to colour
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/74Image or video pattern matching; Proximity measures in feature spaces
    • G06V10/761Proximity, similarity or dissimilarity measures

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Multimedia (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Evolutionary Computation (AREA)
  • General Health & Medical Sciences (AREA)
  • Medical Informatics (AREA)
  • Software Systems (AREA)
  • Databases & Information Systems (AREA)
  • Computing Systems (AREA)
  • Artificial Intelligence (AREA)
  • Health & Medical Sciences (AREA)
  • Image Analysis (AREA)

Abstract

本发明涉及图像处理技术领域,具体是一种基于模板匹配的颜色识别方法,包括颜色模板学习与颜色识别,包括如下步骤:步骤(1)设置矩形感兴趣区域;步骤(2)将感兴趣区域内RGB图像转换为HSV空间;步骤(3)计算色调与饱和度直方图数组;步骤(4)标注颜色;步骤(5)计算待识别图像色调与饱和度直方图;步骤(6)计算待识别和模板图像的距离;步骤(7)获取得分值;步骤(8)分值最高对应的模板即为识别图像的颜色。本方法操作简单,无需人为设置过多参数,自动学习特征,可灵活扩充模板库,实现识别多种颜色的目的,识别准确率高,可以避免因光照、阴影、反射等因素影响而偏离对象原本的颜色。

Figure 202211575996

The present invention relates to the technical field of image processing, in particular to a color recognition method based on template matching, including color template learning and color recognition, comprising the following steps: step (1) setting a rectangular region of interest; step (2) setting the region of interest Inner RGB image is converted into HSV space; step (3) calculates the hue and saturation histogram array; step (4) marks the color; step (5) calculates the hue and saturation histogram of the image to be identified; step (6) calculates the image to be identified and the distance from the template image; step (7) obtains the score; step (8) the template corresponding to the highest score is the color of the recognition image. This method is easy to operate, does not need to manually set too many parameters, automatically learns features, can flexibly expand the template library, and realize the purpose of recognizing multiple colors. s color.

Figure 202211575996

Description

一种基于模板匹配的颜色识别方法A Color Recognition Method Based on Template Matching

技术领域technical field

本发明涉及图像处理技术领域,尤其涉及一种基于模板匹配的颜色识别方法。The invention relates to the technical field of image processing, in particular to a color recognition method based on template matching.

背景技术Background technique

利用色彩空间来描述物体的颜色,以及对色彩进行处理和识别是计算机视觉与图像处理领域中非常常见的应用。我们常用的RGB色彩空间其实并不能很好地反映出物体具体的颜色信息,而HSV空间却能够将色彩的表述分解为色相、饱和度和亮度三个因素,很适合人类进行理解,同时更符合人类大脑的视觉感知规律,非常直观的表达了色彩的明暗,色调,以及鲜艳程度,方便进行颜色之间的对比。因此,将图像从RGB色彩空间转换到HSV色彩空间进行颜色识别,更能精准地识别出物体的颜色。Using color space to describe the color of objects, and to process and recognize colors is a very common application in the field of computer vision and image processing. Our commonly used RGB color space does not reflect the specific color information of the object very well, but the HSV space can decompose the expression of color into three factors: hue, saturation and brightness, which is very suitable for human understanding and more in line with The visual perception rules of the human brain express the lightness, hue, and vividness of colors very intuitively, which facilitates the comparison between colors. Therefore, converting the image from the RGB color space to the HSV color space for color recognition can more accurately identify the color of the object.

当前,颜色是人们感知世界、描述物品最直观的属性之一,在工业上,存在大量的场景需要根据颜色来区分产品,即给定物体的一张图片,用计算机判断出人们用什么颜色表示它,比如将衣服分为红、黄、蓝等若干类分别装箱,通常,区分的过程由人工完成,但由于人体的生物特性,易发生误识别等现象,对企业来说,雇佣成本也是巨大的负担。。At present, color is one of the most intuitive attributes for people to perceive the world and describe objects. In the industry, there are a large number of scenes that need to distinguish products based on color, that is, given a picture of an object, the computer can determine what color people use to represent it. It, for example, divides clothes into red, yellow, blue and other categories and packs them separately. Usually, the process of distinguishing is done manually, but due to the biological characteristics of the human body, it is prone to misidentification. For enterprises, the cost of employment is also high. huge burden. .

发明内容Contents of the invention

本发明的目的在于克服上述现有技术的问题,提供了一种基于模板匹配的颜色识别方法,以解决传统方法中人工依赖度高,受外界影响大,识别精度低的问题。The purpose of the present invention is to overcome the above-mentioned problems in the prior art and provide a color recognition method based on template matching to solve the problems of high artificial dependence, large external influence and low recognition accuracy in the traditional method.

上述目的是通过以下技术方案来实现:Above-mentioned purpose is to realize through following technical scheme:

一种基于模板匹配的颜色识别方法,包括颜色模板学习与颜色识别,包括如下步骤:A color recognition method based on template matching, including color template learning and color recognition, comprising the following steps:

步骤(1)设置矩形感兴趣区域;Step (1) sets a rectangular region of interest;

步骤(2)将感兴趣区域内RGB图像转换为HSV空间;Step (2) converts the RGB image into the HSV space in the region of interest;

步骤(3)计算色调与饱和度直方图数组;Step (3) calculates hue and saturation histogram array;

步骤(4)标注颜色;Step (4) marking color;

步骤(5)计算待识别图像色调与饱和度直方图;Step (5) calculate the hue and saturation histogram of the image to be identified;

步骤(6)计算待识别和模板图像的距离;Step (6) calculates the distance to be identified and the template image;

步骤(7)获取得分值;Step (7) obtains the score value;

步骤(8)分值最高对应的模板即为识别图像的颜色。The template corresponding to the highest score in step (8) is the color of the recognized image.

进一步地,步骤(1)具体为在所述RGB图像中设置感兴趣区域,所述感兴趣区域包括识别目标,根据所述识别目标的颜色,设置相应的颜色数组。Further, step (1) is specifically setting a region of interest in the RGB image, the region of interest includes a recognition target, and setting a corresponding color array according to the color of the recognition target.

进一步地,所述步骤(2)还包括获取像素r、g、b分量中的最大值pmax和最小值pmin,其中Further, the step (2) also includes obtaining the maximum value pmax and the minimum value pmin in the pixel r, g, and b components, wherein

pmax=max(r,g,b) (1)pmax = max(r, g, b) (1)

pmin=min(r,g,b) (2)。pmin=min(r,g,b) (2).

进一步地,所述步骤(3)具体为:计算色调h,公式如下:Further, the step (3) is specifically: calculating the hue h, the formula is as follows:

Figure SMS_1
Figure SMS_1

计算饱和度s,公式如下:Calculate the saturation s, the formula is as follows:

Figure SMS_2
Figure SMS_2

生成色调与饱和度直方图数组arr_h和arr_s,大小分别为360和256;Generate hue and saturation histogram arrays arr_h and arr_s, the sizes are 360 and 256 respectively;

其中arr_h[i](0≤i≤359)和arr_s[j](0≤j≤255)分别表示当前图像中色调值为i和饱和度值为j的像素个数。Among them, arr_h[i] (0≤i≤359) and arr_s[j] (0≤j≤255) respectively represent the number of pixels with hue value i and saturation value j in the current image.

进一步地,所述步骤(5)具体为根据公式(1)~(4)将待识别图像转换到HSV空间中,得到该图像的色调与饱和度直方图数组,记作cur_h[360]和cur_s[256]。Further, the step (5) is specifically to convert the image to be recognized into the HSV space according to the formulas (1)-(4), and obtain the hue and saturation histogram array of the image, denoted as cur_h[360] and cur_s [256].

进一步地,所述步骤(6)中采用欧氏距离法计算待识别和模板图像的距离,包括:Further, in the step (6), the Euclidean distance method is used to calculate the distance between the image to be identified and the template image, including:

设定极端情况下模板色相直方图为(0,0,......,ni,......,0),待识别色相直方图为(0,0,......,nj,.....,0),两个直方图各包含360个数据;Set the hue histogram of the template to be (0, 0, ..., n i , ..., 0) in extreme cases, and the hue histogram to be recognized is (0, 0, .... .., n j ,..., 0), each of the two histograms contains 360 data;

其中,ni=nj=num,且i≠j,num表示像素总个数,定义最大距离

Figure SMS_3
则计算待识别图与模板距离dist的公式如下:Among them, n i =n j =num, and i≠j, num represents the total number of pixels, and defines the maximum distance
Figure SMS_3
The formula for calculating the distance dist between the image to be recognized and the template is as follows:

Figure SMS_4
Figure SMS_4

进一步地,所述步骤(6)中采用曼哈顿距离法计算待识别和模板图像的距离,包括:Further, in the step (6), the Manhattan distance method is used to calculate the distance to be identified and the template image, including:

定义最大距离max Dist=2×num,则计算待识别图与模板距离dist的公式如下:Define the maximum distance max Dist=2×num, then the formula for calculating the distance dist between the image to be recognized and the template is as follows:

Figure SMS_5
Figure SMS_5

进一步地,所述步骤(7)中最终得分score的公式如下:Further, the formula of the final score score in the step (7) is as follows:

Figure SMS_6
Figure SMS_6

有益效果Beneficial effect

本发明所提供的一种基于模板匹配的颜色识别方法,操作简单,无需人为设置过多参数,自动学习特征,可灵活扩充模板库,实现识别多种颜色的目的,识别准确率高,可以避免因光照、阴影、反射等因素影响而偏离对象原本的颜色。A color recognition method based on template matching provided by the present invention is simple to operate, does not need to manually set too many parameters, automatically learns features, can flexibly expand the template library, realizes the purpose of recognizing multiple colors, and has high recognition accuracy, which can avoid Deviation from the original color of the object due to factors such as lighting, shadows, and reflections.

附图说明Description of drawings

图1为本发明所述一种基于模板匹配的颜色识别方法的流程图;Fig. 1 is a flow chart of a color recognition method based on template matching according to the present invention;

图2为本发明所述一种基于模板匹配的颜色识别方法中实施例模板图;Fig. 2 is a template diagram of an embodiment in a color recognition method based on template matching according to the present invention;

图3为本发明所述一种基于模板匹配的颜色识别方法中实施例待识别图像图。Fig. 3 is a diagram of an image to be recognized in an embodiment of a color recognition method based on template matching according to the present invention.

具体实施方式Detailed ways

下面根据附图和实施例对本发明作进一步详细说明。所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的范围。The present invention will be described in further detail below according to the drawings and embodiments. The described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.

如图1所示,一种基于模板匹配的颜色识别方法,包括颜色模板学习与颜色识别,As shown in Figure 1, a color recognition method based on template matching, including color template learning and color recognition,

其中颜色模板学习包括如下步骤:The color template learning includes the following steps:

步骤(1)设置矩形感兴趣区域;Step (1) sets a rectangular region of interest;

步骤(2)将感兴趣区域内RGB图像转换为HSV空间;Step (2) converts the RGB image into the HSV space in the region of interest;

步骤(3)计算色调与饱和度直方图数组;Step (3) calculates hue and saturation histogram array;

步骤(4)标注颜色;Step (4) marking color;

其中颜色识别包括如下步骤:The color recognition includes the following steps:

步骤(5)计算待识别图像色调与饱和度直方图;Step (5) calculate the hue and saturation histogram of the image to be identified;

步骤(6)计算待识别和模板图像的距离;Step (6) calculates the distance to be identified and the template image;

步骤(7)获取得分值;Step (7) obtains the score value;

步骤(8)分值最高对应的模板即为识别图像的颜色。The template corresponding to the highest score in step (8) is the color of the recognized image.

本实施例中步骤(1)具体为在所述RGB图像中设置感兴趣区域,所述感兴趣区域包括识别目标,根据所述识别目标的颜色,设置相应的颜色数组。还包括获取像素r、g、b分量中的最大值pmax和最小值pmin,其中:Step (1) in this embodiment is specifically setting a region of interest in the RGB image, the region of interest includes a recognition target, and setting a corresponding color array according to the color of the recognition target. It also includes obtaining the maximum value pmax and minimum value pmin in the r, g, and b components of pixels, where:

pmax=max(r,g,b) (1)pmax = max(r, g, b) (1)

pmin=min(r,g,b) (2)。pmin=min(r,g,b) (2).

本实施例中所述步骤(3)具体为:计算色调h,公式如下:The step (3) described in this embodiment is specifically: calculate the hue h, the formula is as follows:

Figure SMS_7
Figure SMS_7

计算饱和度s,公式如下:Calculate the saturation s, the formula is as follows:

Figure SMS_8
Figure SMS_8

生成色调与饱和度直方图数组arr_h和arr_s,大小分别为360和256;Generate hue and saturation histogram arrays arr_h and arr_s, the sizes are 360 and 256 respectively;

其中arr_h[i](0≤i≤359)和arr_s[j](0≤j≤255)分别表示当前图像中色调值为i和饱和度值为j的像素个数。Among them, arr_h[i] (0≤i≤359) and arr_s[j] (0≤j≤255) respectively represent the number of pixels with hue value i and saturation value j in the current image.

本实施例中所述步骤(5)具体为:根据公式(1)~(4)将待识别图像转换到HSV空间中,得到该图像的色调与饱和度直方图数组,记作cur_h[360]和cur_s[256]。The step (5) described in this embodiment is specifically: according to the formulas (1)-(4), the image to be recognized is converted into the HSV space, and the hue and saturation histogram array of the image is obtained, denoted as cur_h[360] and cur_s[256].

本实施例中所述步骤(6)中可采用欧氏距离法或曼哈顿距离法计算待识别和模板图像的距离,具体如下:In step (6) described in the present embodiment, can adopt Euclidean distance method or Manhattan distance method to calculate the distance to be identified and template image, specifically as follows:

采用欧氏距离法计算待识别和模板图像的距离,包括:The Euclidean distance method is used to calculate the distance between the image to be recognized and the template image, including:

设定极端情况下模板色相直方图为(0,0,......,ni,......,0),待识别色相直方图为(0,0,......,nj,......,0),两个直方图各包含360个数据;Set the hue histogram of the template to be (0, 0, ..., n i , ..., 0) in extreme cases, and the hue histogram to be recognized is (0, 0, .... .., n j ,..., 0), each of the two histograms contains 360 data;

其中,ni=nj=num,且i≠j,num表示像素总个数,定义最大距离

Figure SMS_9
则计算待识别图与模板距离dist的公式如下:Among them, n i =n j =num, and i≠j, num represents the total number of pixels, and defines the maximum distance
Figure SMS_9
The formula for calculating the distance dist between the image to be recognized and the template is as follows:

Figure SMS_10
Figure SMS_10

采用曼哈顿距离法计算待识别和模板图像的距离,包括:The Manhattan distance method is used to calculate the distance between the image to be recognized and the template image, including:

定义最大距离max Dist=2×num,则计算待识别图与模板距离dist的公式如下:Define the maximum distance max Dist=2×num, then the formula for calculating the distance dist between the image to be recognized and the template is as follows:

Figure SMS_11
Figure SMS_11

所述步骤(7)中计算最终得分score的公式如下:The formula for calculating the final score score in the step (7) is as follows:

Figure SMS_12
Figure SMS_12

其中模板数可能有多个,对应多个得分,采用冒泡排序法从高到低对得分排序,得分越高,说明待识别产品为该颜色的概率越大。There may be multiple templates, corresponding to multiple scores, and the bubble sort method is used to sort the scores from high to low. The higher the score, the greater the probability that the product to be recognized is the color.

本方法主要包括模板学习(颜色模板学习)和模板匹配(颜色识别)2个步骤:This method mainly includes two steps of template learning (color template learning) and template matching (color recognition):

1)模板学习,一般情况下,一批产品的颜色种类数是已知的,各抽取每种颜色的一个产品,采用工业相机拍摄图像,学习其颜色特征,并标注具体颜色名称;1) Template learning, under normal circumstances, the number of color types of a batch of products is known, and each product of each color is extracted, and an industrial camera is used to capture images, learn its color characteristics, and mark the specific color name;

2)模板匹配,比较待识别产品图像与模板的相似度,计算得到若干分值,分值最高对应的模板名称为待识别产品实际颜色。2) Template matching, compare the similarity between the image of the product to be recognized and the template, and calculate several scores, the name of the template corresponding to the highest score is the actual color of the product to be recognized.

本方案中所涉及的颜色特指人们通过眼睛和大脑活动所产生的视觉效应,有别于物理意义上的光线波长定义。The colors involved in this proposal refer specifically to the visual effects produced by people through eye and brain activities, which are different from the definition of light wavelengths in the physical sense.

为验证基于模板匹配的颜色识别方法的性能,本实施例采集了四种颜色产品的图像,共12张进行实验测试,其中,4张作为模板,8张作为测试图像。In order to verify the performance of the color recognition method based on template matching, this embodiment collects images of four color products, a total of 12 images are used for experimental testing, of which 4 are used as templates and 8 are used as test images.

首先进行模板学习,测试图像中共有四种颜色,各选取一幅图像作为模板,如图2所示,分别设置矩形感兴趣区域(需要尽可能包含图像中的产品部分),分别标注为红、绿、蓝和黄;First, template learning is carried out. There are four colors in the test image. Each image is selected as a template. As shown in Figure 2, rectangular regions of interest (need to include the product part in the image as much as possible) are set respectively, marked as red, green, blue and yellow;

对8幅测试图像进行模板匹配(如图3所示),采用曼哈顿距离法得到相似度值,结果如表1所示。Template matching is performed on 8 test images (as shown in Figure 3), and the similarity value is obtained by using the Manhattan distance method. The results are shown in Table 1.

表1 样本匹配相似度值及识别结果Table 1 Sample matching similarity value and recognition results

Figure SMS_13
Figure SMS_13

Figure SMS_14
Figure SMS_14

以表1中的样本2为例,该样本与红、绿、蓝、黄四种模板的相似度分别为0.8775、0.4973、0.5093、0.5381,与红色模板的相似度最高为0.8775,因此将该样本判定为红色,该样本对应于图3-样本2,观察可知,识别正确。Taking sample 2 in Table 1 as an example, the similarities between this sample and the four templates of red, green, blue, and yellow are 0.8775, 0.4973, 0.5093, and 0.5381, respectively, and the highest similarity with the red template is 0.8775, so the sample It is judged as red, and this sample corresponds to Figure 3-Sample 2. It can be seen from observation that the identification is correct.

以上所述仅为说明本发明的实施方式,并不用于限制本发明,对于本领域的技术人员来说,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above description is only to illustrate the implementation of the present invention, and is not intended to limit the present invention. For those skilled in the art, any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention, All should be included within the protection scope of the present invention.

Claims (8)

1.一种基于模板匹配的颜色识别方法,其特征在于,包括颜色模板学习与颜色识别,包括如下步骤:1. a color recognition method based on template matching, is characterized in that, comprises color template study and color recognition, comprises the steps: 步骤(1)设置矩形感兴趣区域;Step (1) sets a rectangular region of interest; 步骤(2)将感兴趣区域内RGB图像转换为HSV空间;Step (2) converts the RGB image into the HSV space in the region of interest; 步骤(3)计算色调与饱和度直方图数组;Step (3) calculates hue and saturation histogram array; 步骤(4)标注颜色;Step (4) marking color; 步骤(5)计算待识别图像色调与饱和度直方图;Step (5) calculate the hue and saturation histogram of the image to be identified; 步骤(6)计算待识别和模板图像的距离;Step (6) calculates the distance to be identified and the template image; 步骤(7)获取得分值;Step (7) obtains the score value; 步骤(8)分值最高对应的模板即为识别图像的颜色。The template corresponding to the highest score in step (8) is the color of the recognized image. 2.根据权利要求1所述的一种基于模板匹配的颜色识别方法,其特征在于,步骤(1)具体为在所述RGB图像中设置感兴趣区域,所述感兴趣区域包括识别目标,根据所述识别目标的颜色,设置相应的颜色数组。2. a kind of color recognition method based on template matching according to claim 1, is characterized in that, step (1) is specifically set interest area in described RGB image, and described interest area comprises recognition target, according to For the color of the identified target, set the corresponding color array. 3.根据权利要求1所述的一种基于模板匹配的颜色识别方法,其特征在于,所述步骤(2)还包括获取像素r、g、b分量中的最大值pmax和最小值pmin,其中3. a kind of color recognition method based on template matching according to claim 1, is characterized in that, described step (2) also comprises obtaining pixel r, g, maximum value pmax and minimum value pmin in component b, wherein pmax=max(r,g,b) (1)pmax = max(r, g, b) (1) pmin=min(r,g,b) (2)。pmin=min(r,g,b) (2). 4.根据权利要求3所述的一种基于模板匹配的颜色识别方法,其特征在于,所述步骤(3)具体为:计算色调h,公式如下:4. a kind of color recognition method based on template matching according to claim 3, is characterized in that, described step (3) is specifically: calculate hue h, and formula is as follows:
Figure FDA0003987447030000011
Figure FDA0003987447030000011
计算饱和度s,公式如下:Calculate the saturation s, the formula is as follows:
Figure FDA0003987447030000012
Figure FDA0003987447030000012
生成色调与饱和度直方图数组arr_h和arr_s,大小分别为360和256;Generate hue and saturation histogram arrays arr_h and arr_s, the sizes are 360 and 256 respectively; 其中arr_h[i](0≤i≤359)和arr_s[j](0≤j≤255)分别表示当前图像中色调值为i和饱和度值为j的像素个数。Among them, arr_h[i] (0≤i≤359) and arr_s[j] (0≤j≤255) respectively represent the number of pixels with hue value i and saturation value j in the current image.
5.根据权利要求4所述的一种基于模板匹配的颜色识别方法,其特征在于,所述步骤(5)具体为根据公式(1)~(4)将待识别图像转换到HSV空间中,得到该图像的色调与饱和度直方图数组,记作cur_h[360]和cur_s[256]。5. a kind of color recognition method based on template matching according to claim 4, is characterized in that, described step (5) is specifically according to formula (1)~(4) image to be recognized is transformed into HSV space, Get the hue and saturation histogram array of the image, denoted as cur_h[360] and cur_s[256]. 6.根据权利要求1所述的一种基于模板匹配的颜色识别方法,其特征在于,所述步骤(6)中采用欧氏距离法计算待识别和模板图像的距离,包括:6. a kind of color recognition method based on template matching according to claim 1, is characterized in that, adopts Euclidean distance method to calculate the distance to be identified and template image in the described step (6), comprising: 设定极端情况下模板色相直方图为(0,0,......,ni,......,0),待识别色相直方图为(0,0,......,nj,......,0),两个直方图各包含360个数据;Set the hue histogram of the template to be (0, 0, ..., n i , ..., 0) in extreme cases, and the hue histogram to be recognized is (0, 0, .... .., n j ,..., 0), each of the two histograms contains 360 data; 其中,ni=nj=num,且i≠j,num表示像素总个数,定义最大距离
Figure FDA0003987447030000021
则计算待识别图与模板距离dist的公式如下:
Among them, n i =n j =num, and i≠j, num represents the total number of pixels, and defines the maximum distance
Figure FDA0003987447030000021
The formula for calculating the distance dist between the image to be recognized and the template is as follows:
Figure FDA0003987447030000022
Figure FDA0003987447030000022
7.根据权利要求1所述的一种基于模板匹配的颜色识别方法,其特征在于,所述步骤(6)中采用曼哈顿距离法计算待识别和模板图像的距离,包括:7. a kind of color recognition method based on template matching according to claim 1, is characterized in that, adopts Manhattan distance method to calculate the distance to be identified and template image in the described step (6), comprising: 定义最大距离maxDist=2×num,则计算待识别图与模板距离dist的公式如下:Define the maximum distance maxDist=2×num, then the formula for calculating the distance dist between the image to be recognized and the template is as follows:
Figure FDA0003987447030000023
Figure FDA0003987447030000023
8.根据权利要求6或7所述的任一一种基于模板匹配的颜色识别方法,其特征在于,所述步骤(7)中最终得分score的公式如下:8. according to claim 6 or 7 described arbitrary a kind of color recognition method based on template matching, it is characterized in that, the formula of final score score in described step (7) is as follows:
Figure FDA0003987447030000024
Figure FDA0003987447030000024
CN202211575996.XA 2022-12-08 2022-12-08 A Color Recognition Method Based on Template Matching Pending CN116403009A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211575996.XA CN116403009A (en) 2022-12-08 2022-12-08 A Color Recognition Method Based on Template Matching

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211575996.XA CN116403009A (en) 2022-12-08 2022-12-08 A Color Recognition Method Based on Template Matching

Publications (1)

Publication Number Publication Date
CN116403009A true CN116403009A (en) 2023-07-07

Family

ID=87016612

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211575996.XA Pending CN116403009A (en) 2022-12-08 2022-12-08 A Color Recognition Method Based on Template Matching

Country Status (1)

Country Link
CN (1) CN116403009A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119169106A (en) * 2024-08-01 2024-12-20 北京金控数据技术股份有限公司 Activated sludge color detection method and related device based on image recognition

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102034080A (en) * 2009-09-24 2011-04-27 北京汉王智通科技有限公司 Vehicle color identification method and device
CN102663391A (en) * 2012-02-27 2012-09-12 安科智慧城市技术(中国)有限公司 Image multifeature extraction and fusion method and system
JP2017118363A (en) * 2015-12-24 2017-06-29 Necソリューションイノベータ株式会社 Color recognition device, color recognition method and program
CN109584317A (en) * 2018-12-24 2019-04-05 天津天地伟业机器人技术有限公司 Body color recognition methods based on HSV color space histogram
CN114913346A (en) * 2022-03-09 2022-08-16 沈阳工学院 An intelligent sorting system and method based on product color and shape recognition

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102034080A (en) * 2009-09-24 2011-04-27 北京汉王智通科技有限公司 Vehicle color identification method and device
CN102663391A (en) * 2012-02-27 2012-09-12 安科智慧城市技术(中国)有限公司 Image multifeature extraction and fusion method and system
JP2017118363A (en) * 2015-12-24 2017-06-29 Necソリューションイノベータ株式会社 Color recognition device, color recognition method and program
CN109584317A (en) * 2018-12-24 2019-04-05 天津天地伟业机器人技术有限公司 Body color recognition methods based on HSV color space histogram
CN114913346A (en) * 2022-03-09 2022-08-16 沈阳工学院 An intelligent sorting system and method based on product color and shape recognition

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119169106A (en) * 2024-08-01 2024-12-20 北京金控数据技术股份有限公司 Activated sludge color detection method and related device based on image recognition
CN119169106B (en) * 2024-08-01 2025-06-10 北京金控数据技术股份有限公司 Activated sludge color detection method and related device based on image recognition

Similar Documents

Publication Publication Date Title
Aquino et al. vitisBerry: An Android-smartphone application to early evaluate the number of grapevine berries by means of image analysis
CN105069466B (en) Pedestrian's dress ornament color identification method based on Digital Image Processing
WO2020221177A1 (en) Method and device for recognizing image, storage medium and electronic device
KR100422709B1 (en) Face detecting method depend on image
Qiao et al. Bird species recognition based on SVM classifier and decision tree
CN114511567B (en) Tongue body and tongue coating image identification and separation method
CN107292307B (en) A method and system for automatic identification of inverted Chinese character verification codes
CN105740774A (en) Text region positioning method and apparatus for image
CN101882223A (en) Evaluation method of human skin color
CN108345867A (en) Gesture identification method towards Intelligent household scene
CN104537756A (en) Banknote classification and identification method and device based on Lab color space
WO2018010386A1 (en) Method and system for component inversion testing
CN107886110A (en) Method for detecting human face, device and electronic equipment
CN112164057A (en) Qualified label detection method, storage medium and electronic equipment
CN109829354B (en) A Face Recognition Method Based on Deep Learning
CN113052194A (en) Garment color cognition system based on deep learning and cognition method thereof
CN116403009A (en) A Color Recognition Method Based on Template Matching
CN110458200A (en) A method for identifying flower species based on machine learning
CN110648336B (en) Method and device for dividing tongue texture and tongue coating
CN106485266A (en) A kind of ancient wall classifying identification method based on extraction color characteristic
Mukhopadhyay et al. Comparing shape descriptor methods for different color space and lighting conditions
CN110348530B (en) Method for identifying lipstick number
CN111340897B (en) Color Recognition Method Based on Fuzzy Mathematics Similarity
JPH11306325A (en) Object detection apparatus and object detection method
CN105335980B (en) A kind of coloured image of suitable image SIFT feature matching turns luminance picture method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination