[go: up one dir, main page]

CN108256566A - A kind of adaptive masterplate matching process and device based on cosine similarity - Google Patents

A kind of adaptive masterplate matching process and device based on cosine similarity Download PDF

Info

Publication number
CN108256566A
CN108256566A CN201810022319.2A CN201810022319A CN108256566A CN 108256566 A CN108256566 A CN 108256566A CN 201810022319 A CN201810022319 A CN 201810022319A CN 108256566 A CN108256566 A CN 108256566A
Authority
CN
China
Prior art keywords
matching
starting point
recognized
similarity
value
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
CN201810022319.2A
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.)
Guangdong University of Technology
Original Assignee
Guangdong University of Technology
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 Guangdong University of Technology filed Critical Guangdong University of Technology
Priority to CN201810022319.2A priority Critical patent/CN108256566A/en
Publication of CN108256566A publication Critical patent/CN108256566A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/22Matching criteria, e.g. proximity measures

Landscapes

  • Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Artificial Intelligence (AREA)
  • Evolutionary Biology (AREA)
  • Evolutionary Computation (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Image Analysis (AREA)

Abstract

本申请公开了一种基于余弦相似度的自适应模版匹配方法,包括:根据计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储;根据相似度值的增减趋势以反向趋势更新平移距离;根据平移距离和预设平移方向更新匹配起始点;判断更新后的匹配起始点的坐标是否满足预设终止条件;若否,则继续计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储;若是,则确定所有相似度值中的极大值,进而确定待识别图像中的匹配目标。本申请根据余弦相似度来自适应调整平移距离,可同时提高匹配精度和速度。本申请还公开了一种基于余弦相似度的自适应模版匹配装置、设备及计算机可读存储介质,也具有上述有益效果。

The present application discloses an adaptive template matching method based on cosine similarity, which includes: matching and storing the similarity value of the image to be recognized from the matching starting point and the template image of the matching target according to the calculation; according to the increase of the similarity value Decrease the trend to update the translation distance with the reverse trend; update the matching starting point according to the translation distance and preset translation direction; judge whether the coordinates of the updated matching starting point meet the preset termination conditions; if not, continue to calculate the image to be recognized from the matching The similarity value matched with the template image of the matching target at the starting point is stored; if so, the maximum value of all similarity values is determined, and then the matching target in the image to be recognized is determined. The present application adaptively adjusts the translation distance according to the cosine similarity, which can improve matching accuracy and speed at the same time. The present application also discloses an adaptive template matching device, equipment and computer-readable storage medium based on cosine similarity, which also have the above beneficial effects.

Description

一种基于余弦相似度的自适应模版匹配方法及装置A method and device for adaptive template matching based on cosine similarity

技术领域technical field

本申请涉及图像识别技术领域,特别涉及一种基于余弦相似度的自适应模版匹配方法、装置、设备及计算机可读存储设备。The present application relates to the technical field of image recognition, in particular to an adaptive template matching method, device, device and computer-readable storage device based on cosine similarity.

背景技术Background technique

在图像识别技术领域,模板匹配是一种最基础、最原始的模式识别方法。它通过在待识别图像中选取与模板图像形状、大小一致的局部区域与模板图像进行匹配比较,再通过评判计算得到的相异度或者相似度,来确定待识别图像中的匹配目标。In the field of image recognition technology, template matching is the most basic and primitive pattern recognition method. It determines the matching target in the image to be recognized by selecting a local area in the image to be recognized that has the same shape and size as the template image for matching and comparison with the template image, and then judging the calculated dissimilarity or similarity.

在模板匹配的过程中,匹配速度和匹配精度是衡量该算法优良性的两个重要指标。然而,现有技术中的模板匹配方法要么匹配速度不高,要么匹配精度不高。这是因为,现有技术中并没有一种科学合理的控制策略来调节局部区域在待识别图像中的平移速度。这里所说的平移速度实际上是指每次平移的平移距离,平移距离过小,会降低匹配速度,平移距离过大,在一些靠近匹配目标的区域内,会造成对匹配目标的漏检。In the process of template matching, matching speed and matching accuracy are two important indicators to measure the superiority of the algorithm. However, the template matching methods in the prior art either have low matching speed or low matching accuracy. This is because, in the prior art, there is no scientific and reasonable control strategy to adjust the translation speed of the local area in the image to be recognized. The translation speed mentioned here actually refers to the translation distance of each translation. If the translation distance is too small, the matching speed will be reduced. If the translation distance is too large, in some areas close to the matching target, the matching target will be missed.

由此可见,采用何种模板匹配方法,以便有效地同时提高匹配精度和匹配速度,是本领域技术人员所需要解决的重要技术问题。It can be seen that which template matching method to use to effectively improve both matching accuracy and matching speed is an important technical problem to be solved by those skilled in the art.

发明内容Contents of the invention

本申请的目的在于提供一种基于余弦相似度的自适应模版匹配方法、装置、设备及计算机可读存储介质,以便有效地同时提高匹配精度和匹配速度。The purpose of the present application is to provide an adaptive template matching method, device, equipment and computer-readable storage medium based on cosine similarity, so as to effectively improve matching accuracy and matching speed at the same time.

为解决上述技术问题,本申请提供一种基于余弦相似度的自适应模版匹配方法,包括:In order to solve the above technical problems, the present application provides an adaptive template matching method based on cosine similarity, including:

根据预设的余弦相似度函数,计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储;所述余弦相似度函数为:According to the preset cosine similarity function, calculate the similarity value of matching the template image of the image to be recognized from the matching starting point and the matching target and store it; the cosine similarity function is:

或者 or

其中,所述模板图像的像素大小为a×b;p(i,j)为所述模板图像在点坐标(i,j)处的灰度值;a、b、i和j均为正整数,且1≤i≤a,1≤j≤b;(x,y)为所述待识别图像的所述匹配起始点的坐标;q(x+i,y+j)为所述待识别图像在点坐标(x+i,y+j)处的灰度值;f(x,y)为与所述匹配起始点(x,y)对应的所述相似度值;Wherein, the pixel size of the template image is a×b; p(i, j) is the gray value of the template image at point coordinates (i, j); a, b, i and j are all positive integers , and 1≤i≤a, 1≤j≤b; (x, y) is the coordinate of the matching starting point of the image to be recognized; q(x+i, y+j) is the image to be recognized Gray value at point coordinates (x+i, y+j); f(x, y) is the similarity value corresponding to the matching starting point (x, y);

根据与所述匹配起始点对应的所述相似度值的增减趋势以反向趋势更新平移距离;Updating the translation distance in a reverse trend according to the increase or decrease trend of the similarity value corresponding to the matching starting point;

根据更新后的所述平移距离和预设平移方向对所述匹配起始点的坐标进行更新;updating the coordinates of the matching starting point according to the updated translation distance and preset translation direction;

判断更新后的所述匹配起始点的坐标是否满足预设终止条件;judging whether the updated coordinates of the matching start point satisfy a preset termination condition;

若否,则继续执行所述计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储的后续步骤;If not, then continue to perform the subsequent steps of calculating the similarity value of the image to be recognized from the matching starting point and matching the template image of the matching target and storing;

若是,则确定所有所述相似度值中的极大值,并根据预设识别依据确定待识别图像中的所述匹配目标。If yes, determine the maximum value among all the similarity values, and determine the matching target in the image to be recognized according to a preset recognition basis.

可选地,所述根据与所述匹配起始点对应的所述相似度值的增减趋势以反向趋势更新平移距离包括:Optionally, the updating the translation distance in a reverse trend according to the increase or decrease trend of the similarity value corresponding to the matching starting point includes:

根据公式对所述平移距离进行更新;其中,h为更新后的所述平移距离,h′为更新前的所述平移距离,h和h′均为正整数;c1为增速调节参数,1<c1;c2为减速调节参数,0<c2<1;预设阈值;[]表示取整数部分。According to the formula Update the translation distance; where, h is the updated translation distance, h' is the translation distance before update, h and h' are both positive integers; c1 is the speed-up adjustment parameter, 1<c1 ;c2 is the deceleration adjustment parameter, 0<c2<1; Preset threshold; [] indicates the integer part.

可选地,所述预设阈值为:Optionally, the preset threshold for:

其中,β为含有所述匹配目标的样本图像与所述模板图像进行匹配所得到的相似度值的均值;l为阈值系数。Wherein, β is the mean value of similarity values obtained by matching the sample image containing the matching target with the template image; l is a threshold coefficient.

可选地,所述预设平移方向为列向平移。Optionally, the preset translation direction is column translation.

可选地,所述平移距离满足条件:Optionally, the translation distance satisfies the condition:

1≤h≤a。1≤h≤a.

可选地,所述根据预设识别依据确定待识别图像中的所述匹配目标包括:Optionally, the determining the matching target in the image to be recognized according to the preset recognition basis includes:

判断相邻两个所述极大值所对应的匹配起始点之间的距离是否低于预设距离阈值;judging whether the distance between the matching start points corresponding to two adjacent maximum values is lower than a preset distance threshold;

若是,则判定所述待识别图像在所述相邻两个极大值中的较大值所对应的匹配起始点处存在一个所述匹配目标;If so, it is determined that there is one matching target in the image to be recognized at the matching starting point corresponding to the larger value among the two adjacent maximum values;

若否,则判定所述待识别图像在所述相邻两个极大值各自对应的匹配起始点处分别存在一个所述匹配目标。If not, it is determined that there is one matching target in the image to be recognized at the matching starting points respectively corresponding to the two adjacent maximum values.

可选地,所述预设距离阈值包括预设横向距离阈值和预设纵向距离阈值;Optionally, the preset distance threshold includes a preset lateral distance threshold and a preset longitudinal distance threshold;

所述判断相邻两个极大值所对应的匹配起始点之间的距离是否低于预设距离阈值包括:The judging whether the distance between the matching starting points corresponding to two adjacent maximum values is lower than the preset distance threshold includes:

判断是否所述相邻两个极大值所对应的匹配起始点之间的横向距离低于所述预设横向距离阈值,或者所述相邻两个极大值所对应的匹配起始点之间的纵向距离低于所述预设纵向距离阈值。Judging whether the lateral distance between the matching starting points corresponding to the two adjacent maximum values is lower than the preset lateral distance threshold, or the distance between the matching starting points corresponding to the two adjacent maximum values The longitudinal distance is lower than the preset longitudinal distance threshold.

本申请还提供了一种基于余弦相似度的自适应模版匹配装置,包括:The present application also provides an adaptive template matching device based on cosine similarity, including:

计算模块:用于根据预设的余弦相似度函数,计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储;所述余弦相似度函数为:Calculation module: used to calculate and store the similarity value of the image to be recognized from the matching starting point and the template image of the matching target according to the preset cosine similarity function; the cosine similarity function is:

或者 or

其中,所述模板图像的像素大小为a×b;p(i,j)为所述模板图像在点坐标(i,j)处的灰度值;a、b、i和j均为正整数,且1≤i≤a,1≤j≤b;(x,y)为所述待识别图像的所述匹配起始点的坐标;q(x+i,y+j)为所述待识别图像在点坐标(x+i,y+j)处的灰度值;f(x,y)为与所述匹配起始点(x,y)对应的所述相似度值;Wherein, the pixel size of the template image is a×b; p(i, j) is the gray value of the template image at point coordinates (i, j); a, b, i and j are all positive integers , and 1≤i≤a, 1≤j≤b; (x, y) is the coordinate of the matching starting point of the image to be recognized; q(x+i, y+j) is the image to be recognized Gray value at point coordinates (x+i, y+j); f(x, y) is the similarity value corresponding to the matching starting point (x, y);

更新模块:用于根据与所述匹配起始点对应的所述相似度值的增减趋势以反向趋势更新平移距离;并根据更新后的所述平移距离和预设平移方向对所述匹配起始点的坐标进行更新;An update module: used to update the translation distance in a reverse trend according to the increase and decrease trend of the similarity value corresponding to the matching starting point; and start the matching according to the updated translation distance and preset translation direction The coordinates of the starting point are updated;

判断模块:用于判断更新后的所述匹配起始点的坐标是否满足预设终止条件;以便所述计算模块在更新后的所述匹配起始点的坐标不满足所述预设终止条件时,继续用于计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储;Judging module: used to judge whether the updated coordinates of the matching starting point meet the preset termination conditions; so that the calculation module continues when the updated coordinates of the matching starting point do not meet the preset termination conditions It is used to calculate and store the similarity value of matching the image to be recognized with the template image of the matching target from the matching starting point;

识别模块:用于在所述匹配起始点的坐标满足所述预设终止条件时,确定所有所述相似度值中的极大值,并根据预设识别依据确定待识别图像中的所述匹配目标。Identification module: used to determine the maximum value of all the similarity values when the coordinates of the matching starting point satisfy the preset termination condition, and determine the matching in the image to be identified according to a preset identification basis Target.

本申请还提供了一种基于余弦相似度的自适应模版匹配设备,包括:The present application also provides an adaptive template matching device based on cosine similarity, including:

存储器:用于存储计算机指令;memory: used to store computer instructions;

处理器:用于执行所述计算机指令以实现如上所述的任一种基于余弦相似度的自适应模版匹配方法的步骤。Processor: used to execute the computer instructions to implement the steps of any cosine similarity-based adaptive template matching method as described above.

本申请还提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,所述计算机程序被处理器执行时实现如上所述的任一种基于余弦相似度的自适应模版匹配方法的步骤。The present application also provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any one of the above-mentioned cosine similarity-based adaptive The steps of the template matching method.

本申请所提供的基于余弦相似度的自适应模版匹配方法包括:The adaptive template matching method based on cosine similarity provided by this application includes:

根据预设的余弦相似度函数,计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储;所述余弦相似度函数为:According to the preset cosine similarity function, calculate the similarity value of matching the template image of the image to be recognized from the matching starting point and the matching target and store it; the cosine similarity function is:

或者 or

其中,所述模板图像的像素大小为a×b;p(i,j)为所述模板图像在点坐标(i,j)处的灰度值;a、b、i和j均为正整数,且1≤i≤a,1≤j≤b;(x,y)为所述待识别图像的所述匹配起始点的坐标;q(x+i,y+j)为所述待识别图像在点坐标(x+i,y+j)处的灰度值;f(x,y)为与所述匹配起始点(x,y)对应的所述相似度值;Wherein, the pixel size of the template image is a×b; p(i, j) is the gray value of the template image at point coordinates (i, j); a, b, i and j are all positive integers , and 1≤i≤a, 1≤j≤b; (x, y) is the coordinate of the matching starting point of the image to be recognized; q(x+i, y+j) is the image to be recognized Gray value at point coordinates (x+i, y+j); f(x, y) is the similarity value corresponding to the matching starting point (x, y);

根据与所述匹配起始点对应的所述相似度值的增减趋势以反向趋势更新平移距离的大小;根据更新后的所述平移距离和预设平移方向对所述匹配起始点的坐标进行更新;判断更新后的所述匹配起始点的坐标是否满足预设终止条件;若否,则继续执行所述计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储的后续步骤;若是,则确定所有所述相似度值中的极大值,并根据预设识别依据确定待识别图像中的所述匹配目标。Update the size of the translation distance with a reverse trend according to the increase or decrease trend of the similarity value corresponding to the matching starting point; perform the coordinates of the matching starting point according to the updated translation distance and preset translation direction Update; judging whether the updated coordinates of the matching starting point meet the preset termination condition; if not, continue to perform the calculation of the similarity value of the image to be recognized from the matching starting point and the template image of the matching target and The subsequent step of storing; if yes, determining the maximum value among all the similarity values, and determining the matching target in the image to be recognized according to a preset recognition basis.

可见,相比于现有技术,本申请所提供的基于余弦相似度的自适应模版匹配方法中,采用了统计学中常使用的余弦相似度来评判待识别图像的局部区域与模板图像的匹配相似度,进而根据该匹配程度即相似度值的大小来自适应反趋势调整对局部区域的匹配起始点进行平移时的平移距离,以便在相似度值高的区域减小平移距离,而在相似度值低的区域增大平移距离。由此可见,本申请可以有效地同时提高匹配精度和匹配速度。本申请所提供的基于余弦相似度的自适应模版匹配装置、设备及计算机可读存储介质可以实现上述基于余弦相似度的自适应模版匹配方法,同样具有上述有益效果。It can be seen that compared with the prior art, in the adaptive template matching method based on cosine similarity provided by the present application, the cosine similarity commonly used in statistics is used to judge the matching similarity between the local area of the image to be recognized and the template image. degree, and then according to the matching degree, that is, the size of the similarity value, the translation distance is adjusted against the trend when the matching starting point of the local area is translated, so that the translation distance can be reduced in the area with a high similarity value, while in the similarity value Low areas increase the translation distance. It can be seen that the present application can effectively improve matching accuracy and matching speed at the same time. The cosine similarity-based adaptive template matching device, equipment, and computer-readable storage medium provided in the present application can realize the above-mentioned cosine similarity-based adaptive template matching method, and also have the above-mentioned beneficial effects.

附图说明Description of drawings

为了更清楚地说明现有技术和本申请实施例中的技术方案,下面将对现有技术和本申请实施例描述中需要使用的附图作简要的介绍。当然,下面有关本申请实施例的附图描述的仅仅是本申请中的一部分实施例,对于本领域普通技术人员来说,在不付出创造性劳动的前提下,还可以根据提供的附图获得其他的附图,所获得的其他附图也属于本申请的保护范围。In order to illustrate the prior art and the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the drawings that need to be used in the description of the prior art and the embodiments of the present application. Of course, the following drawings related to the embodiments of the application describe only a part of the embodiments of the application, and those of ordinary skill in the art can obtain other The accompanying drawings, and other obtained drawings also belong to the protection scope of the present application.

图1为本申请实施例所提供的一种基于余弦相似度的自适应模版匹配方法的流程图;Fig. 1 is a flow chart of an adaptive template matching method based on cosine similarity provided by the embodiment of the present application;

图2为本申请实施例所提供的列向移动方向的示意图;Fig. 2 is a schematic diagram of the row direction moving direction provided by the embodiment of the present application;

图3为本申请实施例所提供的行向移动方向的示意图;FIG. 3 is a schematic diagram of a row moving direction provided by an embodiment of the present application;

图4为本申请实施例所提供的另一种基于余弦相似度的自适应模版匹配方法的流程图;FIG. 4 is a flow chart of another cosine similarity-based adaptive template matching method provided by an embodiment of the present application;

图5为本申请实施例所提供的一种基于余弦相似度的自适应模版匹配装置的结构框图。Fig. 5 is a structural block diagram of an adaptive template matching device based on cosine similarity provided by an embodiment of the present application.

具体实施方式Detailed ways

本申请的核心在于提供一种基于余弦相似度的自适应模版匹配方法、装置、设备及计算机可读存储设备,以便有效地同时提高匹配精度和匹配速度。The core of the present application is to provide an adaptive template matching method, device, device and computer-readable storage device based on cosine similarity, so as to effectively improve matching accuracy and matching speed at the same time.

为了对本申请实施例中的技术方案进行更加清楚、完整地描述,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行介绍。显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to describe the technical solutions in the embodiments of the present application more clearly and completely, the technical solutions in the embodiments of the present application will be introduced below in conjunction with the drawings in the embodiments of the present application. Apparently, the described embodiments are only some of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the scope of protection of this application.

请参考图1,图1为本申请实施例所提供的一种基于余弦相似度的自适应模版匹配方法的流程图,主要包括以下步骤:Please refer to FIG. 1. FIG. 1 is a flow chart of an adaptive template matching method based on cosine similarity provided by the embodiment of the present application, which mainly includes the following steps:

步骤11:根据预设的余弦相似度函数,计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储;余弦相似度函数为:Step 11: According to the preset cosine similarity function, calculate and store the similarity value of matching the image to be recognized with the template image of the matching target from the matching starting point; the cosine similarity function is:

或者 or

其中,模板图像的像素大小为a×b;p(i,j)为模板图像在点坐标(i,j)处的灰度值;a、b、i和j均为正整数,且1≤i≤a,1≤j≤b;(x,y)为待识别图像的匹配起始点的坐标;q(x+i,y+j)为待识别图像在点坐标(x+i,y+j)处的灰度值;f(x,y)为与匹配起始点(x,y)对应的相似度值。Among them, the pixel size of the template image is a×b; p(i, j) is the gray value of the template image at point coordinates (i, j); a, b, i and j are all positive integers, and 1≤ i≤a, 1≤j≤b; (x, y) is the coordinate of the matching starting point of the image to be recognized; q(x+i, y+j) is the point coordinate of the image to be recognized at (x+i, y+ The gray value at j); f(x, y) is the similarity value corresponding to the matching starting point (x, y).

具体地,本申请所提供的模板匹配方法在进行待识别图像与模板图像的匹配比较过程中时,所采用的相似度具体是采用基于余弦来计算的相似度,尤其适用于灰度值夹角特性显著的图像识别场合。当从待识别图像中所选取的局部区域中各个像素点的灰度值与模板图像相应像素点的灰度值经计算得到的相似度越大,该局部区域存在匹配目标的可能性就越高。Specifically, when the template matching method provided by this application is in the process of matching and comparing the image to be recognized and the template image, the similarity used is specifically the similarity calculated based on cosine, which is especially suitable for gray value angles Image recognition occasions with significant characteristics. When the similarity between the gray value of each pixel in the local area selected from the image to be recognized and the gray value of the corresponding pixel in the template image is calculated, the higher the possibility of matching the target in the local area .

从余弦相似度函数的计算表达式也可以看出,在进行相似度计算时,具体是从匹配起始点处开始,在选取的局部区域内以1个像素为单位进行遍历,将局部区域内的所有像素点的灰度值与模板图像的像素点的灰度值进行余弦相似度计算。在进行模板匹配时,为了依次将从待识别图像中选取的局部区域与模板图像的各个像素点依次进行比较,需要分别为待识别图像和模板图像设定原点和统一的坐标轴方向。一般地,可将待识别图像和模板图像的左上顶点分别设为各自的原点,继而将水平向右和竖直向下分别设为横坐标方向和纵坐标方向。由于局部区域涵盖了多个像素点,所以一般可以用匹配起始点来衡量局部区域的位置。类似地,一般会将该局部区域的左上顶点的像素点作为其匹配起始点。It can also be seen from the calculation expression of the cosine similarity function that when calculating the similarity, it starts from the matching starting point and traverses the selected local area in units of 1 pixel. Cosine similarity calculation is performed between the gray values of all pixels and the gray values of the pixels of the template image. When performing template matching, in order to sequentially compare the local area selected from the image to be recognized with each pixel of the template image, it is necessary to set the origin and a unified coordinate axis direction for the image to be recognized and the template image respectively. Generally, the upper left vertices of the image to be recognized and the template image can be set as their respective origins, and then the horizontal to the right and vertical downward can be set to the abscissa direction and the ordinate direction respectively. Since the local area covers multiple pixel points, the matching starting point can generally be used to measure the position of the local area. Similarly, generally, the pixel point of the upper left vertex of the local area is used as the matching start point.

步骤12:根据与匹配起始点对应的相似度值的增减趋势以反向趋势更新平移距离。Step 12: Update the translation distance in a reverse trend according to the increase and decrease trend of the similarity value corresponding to the matching starting point.

具体地,本申请所提供的模板匹配方法在进行对匹配起始点即局部区域的平移时,是根据当前匹配起始点所对应的匹配结果即相似度值来自适应反趋势调整的。在当前匹配起始点所对应的相似度值较大时,说明此时选取的局部区域与模板图像较为接近,存在匹配目标的可能性较高,因此,可以适当地减小每次进行平移时的平移距离,以便防止错过相似度更高的局部区域,进而可有效提高匹配精度。而在当前匹配起始点所对应的相似度值较小时,说明此时选取的局部区域与模板图像相差很大,存起匹配目标的可能性较低,因此,可以适当地增大每次进行平移时的平移距离,以便提高匹配速度。Specifically, when the template matching method provided in the present application translates the matching starting point, that is, the local area, it adapts the anti-trend adjustment according to the matching result corresponding to the current matching starting point, that is, the similarity value. When the similarity value corresponding to the current matching starting point is large, it means that the selected local area is relatively close to the template image, and there is a high possibility of matching targets. The translation distance is used to prevent missing local areas with higher similarity, which can effectively improve the matching accuracy. When the similarity value corresponding to the current matching starting point is small, it means that the local area selected at this time is very different from the template image, and the possibility of saving the matching target is low. The translation distance in order to improve the matching speed.

步骤13:根据更新后的平移距离和预设平移方向对匹配起始点的坐标进行更新。Step 13: Update the coordinates of the matching starting point according to the updated translation distance and preset translation direction.

具体地,匹配起始点是按照平移距离和预设平移方向来进行平移变换的。当选定原点为左上顶点时,预设平移方向既可以为逐行向右平移,也可以逐列向下平移,而具体平移多少个像素点,取决于更新后的平移距离。Specifically, the matching starting point is translated according to the translation distance and the preset translation direction. When the origin is selected as the upper left vertex, the preset translation direction can be either row-by-row right translation or column-by-column translation down, and the exact number of pixels to be translated depends on the updated translation distance.

步骤14:判断更新后的匹配起始点的坐标是否满足预设终止条件:若否,进入步骤11;若是,进入步骤15。Step 14: Determine whether the updated coordinates of the matching starting point meet the preset termination condition: if not, go to step 11; if yes, go to step 15.

具体地,如前所述,模板匹配算法在执行过程中,对匹配起始点即对局部区域的平移是按照预设平移方向进行的、有计划、有序的平移,平移的目的是令所有出现过的局部区域叠加起来能尽量覆盖待识别图像。当预设平移方向确定之后,平移的终止条件也就确定了,该终止条件具体可与匹配起始点的坐标有关,因为匹配起始点的坐标就代表了相应局部区域的范围。例如,即当模板图像的像素大小为a×b、待识别图像的匹配起始点的坐标为(x,y)时,该匹配起始点对应的局部区域即为以像素点(x,y)为左上顶点、纵长为a而横长为b的区域。Specifically, as mentioned above, during the execution of the template matching algorithm, the translation of the matching starting point, that is, the local area, is carried out in a planned and orderly manner according to the preset translation direction. The purpose of the translation is to make all occurrences The overlaid local areas can be superimposed to cover the image to be recognized as much as possible. After the preset translation direction is determined, the termination condition of the translation is also determined. The termination condition may be specifically related to the coordinates of the matching starting point, because the coordinates of the matching starting point represent the range of the corresponding local area. For example, when the pixel size of the template image is a×b, and the coordinates of the matching starting point of the image to be recognized are (x, y), the local area corresponding to the matching starting point is the pixel point (x, y) as The upper left vertex, the area whose vertical length is a and horizontal length is b.

例如,若待识别图像的像素大小为A×B,则为避免局部区域超出待识别图像的范围,可令匹配起始点在待识别图像中(A-a)×(B-b)的有效范围内按照预设平移方向进行平移。具体地,可令匹配起始点从原点处逐列地列向平移,也可以逐行地行向平移。列向平移是指将匹配起始点在列内从上向下(以左上顶点为原点时)进行平移,当平移到该列的底部时再换到下一列的顶部继续向下平移,如图2所示;行向平移是指将匹配起始点在行内从左向右(以左上顶点为原点时)进行平移,当平移到该列的右端时再换到下一行继续向右平移,如图3所示。当匹配起始点在(A-a)×(B-b)的有效范围内平移结束之后,再次对其进行平移后的坐标必然会落在该有效范围之外,因此,具体可将匹配起始点的坐标不在该有效范围之内作为预设终止条件。For example, if the pixel size of the image to be recognized is A×B, in order to prevent the local area from exceeding the range of the image to be recognized, the matching starting point can be set within the valid range of (A-a)×(B-b) in the image to be recognized according to the preset Pan direction to pan. Specifically, the matching start point can be shifted column by column from the origin, or shifted row by row. Column-to-column translation means to translate the matching starting point in the column from top to bottom (with the upper left vertex as the origin), and when it reaches the bottom of the column, switch to the top of the next column and continue to translate downward, as shown in Figure 2 Shown; Row-to-row translation means that the matching starting point is translated from left to right (with the upper left vertex as the origin) in the row, and when it is translated to the right end of the column, it is switched to the next row and continues to translate to the right, as shown in Figure 3 shown. When the matching start point is translated within the valid range of (A-a)×(B-b), the coordinates after it is translated again must fall outside the valid range. within the effective range as the default termination condition.

步骤15:确定所有相似度值中的极大值,并根据预设识别依据确定待识别图像中的匹配目标。Step 15: Determine the maximum value among all similarity values, and determine the matching target in the image to be recognized according to the preset recognition basis.

具体地,当结束了匹配起始点在有效范围内的平移之后,即可根据平移过程中所得到的所有相似度值来确定其中的极大值,以便根据极大值和预设识别依据来确定待识别图像中的匹配目标。Specifically, after the translation of the matching starting point within the effective range is completed, the maximum value can be determined according to all the similarity values obtained during the translation process, so as to determine Matching objects in the image to be recognized.

可见,本申请实施例所提供的基于余弦相似度的自适应模版匹配方法中,采用了统计学中常使用的余弦相似度来评判待识别图像的局部区域与模板图像的匹配相似度,进而根据该匹配程度即相似度值的大小来自适应反趋势调整对局部区域的匹配起始点进行平移时的平移距离,以便在相似度值高的区域减小平移距离,而在相似度值低的区域增大平移距离。由此可见,本申请可以有效地同时提高匹配精度和匹配速度。It can be seen that in the adaptive template matching method based on cosine similarity provided in the embodiment of the present application, the cosine similarity commonly used in statistics is used to judge the matching similarity between the local area of the image to be recognized and the template image, and then according to the The degree of matching, that is, the size of the similarity value, comes from the anti-trend adjustment to adjust the translation distance when the matching starting point of the local area is translated, so that the translation distance can be reduced in areas with high similarity values and increased in areas with low similarity values. translation distance. It can be seen that the present application can effectively improve matching accuracy and matching speed at the same time.

本申请所提供的基于余弦相似度的自适应模版匹配方法,在上述实施例的基础上:The adaptive template matching method based on cosine similarity provided by this application, on the basis of the above-mentioned embodiments:

作为一种优选实施例,根据与匹配起始点对应的相似度值更新平移距离包括:As a preferred embodiment, updating the translation distance according to the similarity value corresponding to the matching starting point includes:

根据公式对平移距离进行更新。According to the formula Update the translation distance.

其中,h为更新后的平移距离,h′为更新前的平移距离,h和h′均为正整数;c1为增速调节参数,1<c1;c2为减速调节参数,0<c2<1;预设阈值;[]表示取整数部分。Among them, h is the updated translation distance, h' is the translation distance before update, both h and h' are positive integers; c1 is the acceleration adjustment parameter, 1<c1; c2 is the deceleration adjustment parameter, 0<c2<1 ; Preset threshold; [] indicates the integer part.

具体地,在依据相似度值对平移距离进行自适应反趋势调整时,具体可分别利用增速调节参数c1和减速调节参数c2来对平移距离进行调整。至于具体的参数取值,可由本领域技术人员自行选择并设置。Specifically, when the translation distance is adaptively adjusted against the trend according to the similarity value, the translation distance can be adjusted by using the acceleration adjustment parameter c1 and the deceleration adjustment parameter c2 respectively. As for the specific parameter values, those skilled in the art can choose and set them by themselves.

此外,本申请实施例在对平移距离进行更新时,相似度值f(x,y)是否较大的评判结合采用了两种评判标准:即与预设阈值比较和变化率的正负比较。当相似度值大于预设阈值或处于增大状态时,说明此时与模板图像匹配的可能性很高,或者相对于上一次的匹配结果的可能性更高,因此可以对平移距离进行减小调节以提高匹配精度;而当相似度值小于预设阈值或处于减小状态时,说明此时与模板图像匹配的可能性很低,或者相对于上一次的匹配结果的可能性更低,因此可以对平移距离进行增大调节以提高匹配速度。In addition, in the embodiment of the present application, when updating the translation distance, the judgment of whether the similarity value f(x, y) is large or not adopts two kinds of judgment criteria in combination: namely, with the preset threshold value Positive and negative comparisons for comparison and rate of change. When the similarity value is greater than the preset threshold Or when it is in the increasing state, it means that the possibility of matching the template image is very high at this time, or the possibility of matching the previous matching result is higher, so the translation distance can be reduced to improve the matching accuracy; and when The similarity value is less than the preset threshold Or when it is in a decreasing state, it means that the possibility of matching with the template image at this time is very low, or the possibility is lower compared with the last matching result, so the translation distance can be adjusted to increase to improve the matching speed.

作为一种优选实施例,预设阈值为:As a preferred embodiment, the preset threshold for:

其中,β为含有匹配目标的样本图像与模板图像进行匹配所得到的相似度值的均值;l为阈值系数。Among them, β is the mean value of the similarity value obtained by matching the sample image containing the matching target with the template image; l is the threshold coefficient.

具体地,该预设阈值可结合样本图像与模板图像的匹配结果的一般平均水平来选取。当然,所说的样本图像为含有该匹配目标的样本图像,并且一般应为随机选取的。Specifically, the preset threshold It can be selected in combination with the general average level of the matching results between the sample image and the template image. Of course, the said sample image is a sample image containing the matching target, and generally should be randomly selected.

作为一种优选实施例,预设平移方向为列向平移。As a preferred embodiment, the preset translation direction is column translation.

如前所述,可按照计算机逐列处理数据的习惯,将匹配起始点在有效范围内列向平移,以使对应的各个局部区域覆盖待识别图像。当然,本领域内技术人员也可以采用其他方式,本申请实施例对此并不进行限定。As mentioned above, according to the computer's habit of processing data column by column, the matching starting point can be shifted column-wise within the effective range, so that each corresponding local area covers the image to be recognized. Certainly, those skilled in the art may also adopt other manners, which are not limited in this embodiment of the present application.

作为一种优选实施例,平移距离满足条件:As a preferred embodiment, the translation distance satisfies the condition:

1≤h≤a。1≤h≤a.

当采用列向平移方式时,可以对每次更新后的平移距离h进行大小限定,以防止该平移距离h过大而跳过部分含有匹配目标的区域,影响匹配精度。具体地,可将平移距离h设置为不大于模板图像的纵长a,即1≤h≤a。在确保平移距离h大小时,具体可采用饱和函数,即:When the column-wise translation method is used, the translation distance h after each update can be limited in size, so as to prevent the translation distance h from being too large and skipping some regions containing the matching target, which affects the matching accuracy. Specifically, the translation distance h can be set to be not greater than the vertical length a of the template image, that is, 1≤h≤a. When ensuring the size of the translation distance h, a saturation function can be used specifically, that is:

其中,hbef为饱和处理前的平移距离h,haft为饱和处理后的平移距离h。Wherein, h bef is the translation distance h before saturation processing, and h aft is the translation distance h after saturation processing.

作为一种优选实施例,根据预设识别依据确定待识别图像中的匹配目标包括:As a preferred embodiment, determining the matching target in the image to be recognized according to the preset recognition basis includes:

判断相邻两个极大值所对应的匹配起始点之间的距离是否低于预设距离阈值;Judging whether the distance between matching starting points corresponding to two adjacent maximum values is lower than a preset distance threshold;

若是,则判定待识别图像在相邻两个极大值中的较大值所对应的匹配起始点处存在一个匹配目标;If so, it is determined that there is a matching target at the matching starting point corresponding to the larger value of the adjacent two maximum values in the image to be recognized;

若否,则判定待识别图像在相邻两个极大值各自对应的匹配起始点处分别存在一个匹配目标。If not, it is determined that there is a matching target in the image to be recognized at the matching start points corresponding to the two adjacent maximum values respectively.

具体地,本申请实施例所提供的基于余弦相似度的自适应模版匹配方法在根据各个相似度值进行匹配目标的确定时,具体是基于极大值来判定的。根据极大值的物理含义可知,待识别图像可能在某个极大值所对应的匹配起始点处(局部区域处)存在着一个匹配目标;也有可能是在多个极大值所对应的匹配起始点之间的区域处存在着一个匹配目标。Specifically, in the adaptive template matching method based on cosine similarity provided in the embodiment of the present application, when determining the matching target according to each similarity value, the determination is specifically based on the maximum value. According to the physical meaning of the maximum value, the image to be recognized may have a matching target at the matching starting point (local area) corresponding to a certain maximum value; it may also be a matching target corresponding to multiple maximum values. There is a matching target in the area between the starting points.

为了对此进行区分,本申请实施例对相邻两个极大值所对应的匹配起始点之间的距离进行了判断,若该距离小于预设距离阈值,则说明这两个匹配起始点相距很近,应当是属于上述第二种情况。而这两个极大值所共同描述的这个匹配目标的具体位置,可由这两个相邻极大值中的较大值来确定,即该较大值对应的匹配起始点处存在着匹配目标。假设该较大值对应的匹配起始点坐标为(x1,y1),则匹配目标的中心的位置坐标即可被认为是(x1+a/2,y1+b/2)。In order to distinguish this, the embodiment of the present application judges the distance between the matching starting points corresponding to two adjacent maximum values. If the distance is less than the preset distance threshold, it means that the two matching starting points are far apart. Very close, it should belong to the second situation above. The specific position of the matching target described by these two maximum values can be determined by the larger value of the two adjacent maximum values, that is, there is a matching target at the matching starting point corresponding to the larger value . Assuming that the coordinates of the matching starting point corresponding to the larger value are (x1, y1), the position coordinates of the center of the matching target can be regarded as (x1+a/2, y1+b/2).

若该相邻两个极大值所对应的匹配起始点之间的距离不小于预设距离阈值,则说明这两个匹配起始点相距较远,应当是属于上述第一种情况。因此可判定待识别图像在两个极大值所对应的匹配起始点处分别存在一个匹配目标。If the distance between the matching starting points corresponding to the two adjacent maximum values is not less than the preset distance threshold, it means that the two matching starting points are far apart, which should belong to the first case above. Therefore, it can be determined that there is a matching target at the matching start points corresponding to the two maximum values in the image to be recognized.

此外,这里所说的预设距离阈值的具体取值,可由本领域技术人员自行选择并设置,本申请实施例对此均不进行限定。In addition, the specific value of the preset distance threshold mentioned here can be selected and set by those skilled in the art, which is not limited in the embodiments of the present application.

作为一种优选实施例,预设距离阈值包括预设横向距离阈值和预设纵向距离阈值;As a preferred embodiment, the preset distance threshold includes a preset horizontal distance threshold and a preset longitudinal distance threshold;

判断相邻两个极大值所对应的匹配起始点之间的距离是否低于预设距离阈值包括:Judging whether the distance between the matching start points corresponding to two adjacent maximum values is lower than the preset distance threshold includes:

判断是否相邻两个极大值所对应的匹配起始点之间的横向距离低于预设横向距离阈值,或者相邻两个极大值所对应的匹配起始点之间的纵向距离低于预设纵向距离阈值。Judging whether the horizontal distance between the matching start points corresponding to two adjacent maximum values is lower than the preset horizontal distance threshold, or whether the vertical distance between the matching starting points corresponding to two adjacent maximum values is lower than the preset Set the vertical distance threshold.

具体地,本申请实施例所采用的预设距离阈值包括两个:预设横向距离阈值和预设纵向距离阈值,分别用于评判两个极大值对应匹配起始点的横向距离和纵向距离。并且,具体地,该预设横向距离阈值和预设纵向距离阈值可分别设置为模板图像的纵长a和横长b。当然,本领域技术人员还可以自行选择并设置其他阈值,本申请实施例对此均不进行限定。Specifically, the preset distance thresholds adopted in the embodiment of the present application include two preset horizontal distance thresholds and preset vertical distance thresholds, which are respectively used to judge the horizontal distance and vertical distance corresponding to the matching starting point of two maximum values. And, specifically, the preset horizontal distance threshold and the preset vertical distance threshold may be respectively set as the vertical length a and the horizontal length b of the template image. Certainly, those skilled in the art may also select and set other thresholds by themselves, which is not limited in the embodiments of the present application.

请参阅图4,图4为本申请实施例所提供的另一种基于余弦相似度的自适应模版匹配方法的流程图;包括:Please refer to FIG. 4. FIG. 4 is a flow chart of another cosine similarity-based adaptive template matching method provided by the embodiment of the present application; including:

步骤21:根据公式计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储。Step 21: According to the formula Calculate and store the similarity value of matching the image to be recognized with the template image of the matching target from the matching starting point.

其中,模板图像的像素大小为a×b;p(i,j)为模板图像在点坐标(i,j)处的灰度值;a、b、i和j均为正整数,且1≤i≤a,1≤j≤b;(x,y)为待识别图像的匹配起始点的坐标;q(x+i,y+j)为待识别图像在点坐标(x+i,y+j)处的灰度值;f(x,y)为与匹配起始点(x,y)对应的相似度值。Among them, the pixel size of the template image is a×b; p(i, j) is the gray value of the template image at point coordinates (i, j); a, b, i and j are all positive integers, and 1≤ i≤a, 1≤j≤b; (x, y) is the coordinate of the matching starting point of the image to be recognized; q(x+i, y+j) is the point coordinate of the image to be recognized at (x+i, y+ The gray value at j); f(x, y) is the similarity value corresponding to the matching starting point (x, y).

具体地,本申请实施例所提供的自适应模板匹配方法根据公式来计算相似度。并且,匹配起始点(x,y)的初始值为(1,1)。Specifically, the adaptive template matching method provided by the embodiment of the present application is based on the formula to calculate the similarity. And, the initial value of the matching starting point (x,y) is (1,1).

步骤22:根据公式更新平移距离。Step 22: According to the formula Update the translation distance.

其中,h为更新后的平移距离,h′为更新前的平移距离,h和h′均为正整数;c1为增速调节参数,1<c1;c2为减速调节参数,0<c2<1;预设阈值,[]表示取整数部分。Among them, h is the updated translation distance, h' is the translation distance before update, both h and h' are positive integers; c1 is the acceleration adjustment parameter, 1<c1; c2 is the deceleration adjustment parameter, 0<c2<1 ; Preset threshold, [] indicates the integer part.

步骤23:将x+h重新赋值给x,y保持不变。Step 23: Reassign x+h to x, and keep y unchanged.

具体地,本申请实施例所提供的自适应模板匹配方法采用列向平移匹配起始点的平移方式,每次向右平移的平移距离h根据相似度值f(x,y)和增速调节参数c1或者减速调节参数c2确定。Specifically, the adaptive template matching method provided by the embodiment of the present application adopts the translation method of the starting point of the column-wise translation matching, and the translation distance h of each translation to the right is adjusted according to the similarity value f(x, y) and the speed-up parameter c1 or deceleration adjustment parameter c2 is determined.

步骤24:判断x>A-a是否成立:若是,进入步骤25;若否,进入步骤26。Step 24: Determine whether x>A-a holds: if yes, go to step 25; if not, go to step 26.

具体地,在将匹配起始点的坐标列向向下平移之后,可以先判断下平移后的匹配起始点的纵坐标是否超出了有效范围,即是否需要换列。当x>A-a成立时,则需要进行换列处理。当x>A-a不成立时,则不需要进行换列处理,直接进行是否满足预设终止条件的判断。Specifically, after the coordinate column of the matching starting point is shifted downward, it may first be judged whether the vertical coordinate of the matching starting point after the downward translation is beyond the valid range, that is, whether the column needs to be changed. When x>A-a is established, it is necessary to change columns. When x>A-a does not hold, there is no need to change columns, and it is directly judged whether the preset termination condition is satisfied.

步骤25:令y+1重新赋值给y,x取为1;进入步骤26。Step 25: Reassign y+1 to y, and take x as 1; go to step 26.

具体地,在进行换列处理时,即将匹配起始点的横坐标加1,而纵坐标取为初始值1。换列之后,即可进行是否满足预设终止条件的判断。Specifically, when changing columns, add 1 to the abscissa of the matching starting point, and take the ordinate as an initial value of 1. After changing columns, it can be judged whether the preset termination condition is satisfied.

步骤26:判断y>B-b是否成立:若否,进入步骤21;若是,进入步骤27。Step 26: Determine whether y>B-b holds: if not, go to step 21; if yes, go to step 27.

当y>B-b成立时,说明匹配起始点的横坐标超出了有效范围,则说明此时已经完成了在有效范围内的平移过程,可以进入步骤27进行匹配目标的确定。否则,则继续返回步骤21计算新匹配起始点的相似度。When y>B-b holds true, it means that the abscissa of the matching starting point is beyond the valid range, and it means that the translation process within the valid range has been completed at this time, and step 27 can be entered to determine the matching target. Otherwise, continue to return to step 21 to calculate the similarity of the new matching starting point.

步骤27:确定所有相似度值中的极大值;进入步骤28。Step 27: Determine the maximum value among all similarity values; go to step 28.

步骤28:判断相邻两个极大值所对应的匹配起始点之间的距离是否低于预设距离阈值:若是,则判定待识别图像在相邻两个极大值中的较大值所对应的匹配起始点处存在一个匹配目标;若否,则判定待识别图像在相邻两个极大值各自对应的匹配起始点处分别存在一个匹配目标。Step 28: Determine whether the distance between the matching starting points corresponding to two adjacent maximum values is lower than the preset distance threshold: if so, determine the distance between the larger value of the two adjacent maximum values of the image to be recognized There is a matching target at the corresponding matching starting point; if not, it is determined that there is a matching target at the corresponding matching starting points of the two adjacent maximum values in the image to be recognized.

下面对本申请实施例所提供的基于余弦相似度的自适应模版匹配装置进行介绍。The cosine similarity-based adaptive template matching device provided by the embodiment of the present application is introduced below.

请参阅图5,图5为本申请所提供的一种基于余弦相似度的自适应模版匹配装置的结构框图;包括计算模块1、更新模块2、判断模块3和识别模块4;Please refer to FIG. 5, which is a structural block diagram of an adaptive template matching device based on cosine similarity provided by the present application; including a calculation module 1, an update module 2, a judgment module 3 and an identification module 4;

计算模块1用于根据预设的余弦相似度函数,计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储;余弦相似度函数为:Calculation module 1 is used for calculating the similarity value of matching the template image of the image to be recognized from the matching starting point and matching target according to the preset cosine similarity function and storing; the cosine similarity function is:

或者 or

其中,模板图像的像素大小为a×b;p(i,j)为模板图像在点坐标(i,j)处的灰度值;a、b、i和j均为正整数,且1≤i≤a,1≤j≤b;(x,y)为待识别图像的匹配起始点的坐标;q(x+i,y+j)为待识别图像在点坐标(x+i,y+j)处的灰度值;f(x,y)为与匹配起始点(x,y)对应的相似度值;Among them, the pixel size of the template image is a×b; p(i, j) is the gray value of the template image at point coordinates (i, j); a, b, i and j are all positive integers, and 1≤ i≤a, 1≤j≤b; (x, y) is the coordinate of the matching starting point of the image to be recognized; q(x+i, y+j) is the point coordinate of the image to be recognized at (x+i, y+ j) at the gray value; f(x, y) is the similarity value corresponding to the matching starting point (x, y);

更新模块2用于根据与匹配起始点对应的相似度值的增减趋势以反向趋势更新平移距离;并根据更新后的平移距离和预设平移方向对匹配起始点的坐标进行更新;The update module 2 is used to update the translation distance with a reverse trend according to the increase and decrease trend of the similarity value corresponding to the matching starting point; and update the coordinates of the matching starting point according to the updated translation distance and preset translation direction;

判断模块3用于判断更新后的匹配起始点的坐标是否满足预设终止条件;以便计算模块在更新后的匹配起始点的坐标不满足预设终止条件时,继续用于计算待识别图像从匹配起始点处与匹配目标的模板图像进行匹配的相似度值并存储;Judgment module 3 is used for judging whether the coordinates of the matching starting point after updating meet the preset termination condition; so that the calculation module continues to be used to calculate the image to be recognized from the matching when the coordinates of the updated matching starting point do not meet the preset termination condition The similarity value of the matching target template image at the starting point is stored;

识别模块4用于在匹配起始点的坐标满足预设终止条件时,确定所有相似度值中的极大值,并根据预设识别依据确定待识别图像中的匹配目标。The recognition module 4 is used to determine the maximum value among all similarity values when the coordinates of the matching starting point satisfy the preset termination condition, and determine the matching target in the image to be recognized according to the preset recognition basis.

可见,本申请所提供的基于余弦相似度的自适应模版匹配装置,采用了统计学中常使用的余弦相似度来评判待识别图像的局部区域与模板图像的匹配相似度,进而根据该匹配程度即相似度值的大小来自适应反趋势调整对局部区域的匹配起始点进行平移时的平移距离,以便在相似度值高的区域减小平移距离,而在相似度值低的区域增大平移距离。由此可见,本申请可以有效地同时提高匹配精度和匹配速度。It can be seen that the adaptive template matching device based on cosine similarity provided by the present application adopts the cosine similarity commonly used in statistics to judge the matching similarity between the local area of the image to be recognized and the template image, and then according to the matching degree that is The size of the similarity value comes from the anti-trend adjustment to adjust the translation distance when the matching starting point of the local area is translated, so that the translation distance is reduced in the area with high similarity value, and the translation distance is increased in the area with low similarity value. It can be seen that the present application can effectively improve matching accuracy and matching speed at the same time.

本申请还提供了一种基于余弦相似度的自适应模版匹配设备,包括:The present application also provides an adaptive template matching device based on cosine similarity, including:

存储器:用于存储计算机指令;memory: used to store computer instructions;

处理器:用于执行该计算机指令以实现以上所介绍的任一种基于余弦相似度的自适应模版匹配方法的步骤。Processor: for executing the computer instructions to implement the steps of any one of the cosine similarity-based adaptive template matching methods described above.

本申请还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有计算机程序,该计算机程序被处理器执行时实现以上所介绍的任一种基于余弦相似度的自适应模版匹配方法的步骤。The present application also provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any one of the above-mentioned adaptive template matching based on cosine similarity can be realized method steps.

本申请所提供的基于余弦相似度的自适应模版匹配装置、设备及计算机可读存储介质的具体实施方式与上文所描述的基于余弦相似度的自适应模版匹配方法可相互对应参照,这里就不再赘述。The specific implementations of the cosine similarity-based adaptive template matching device, equipment, and computer-readable storage medium provided in this application and the cosine similarity-based adaptive template matching method described above can be referred to each other. No longer.

本申请中各个实施例采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似部分互相参见即可。对于实施例公开的装置而言,由于其与实施例公开的方法相对应,所以描述的比较简单,相关之处参见方法部分说明即可。Each embodiment in the present application is described in a progressive manner, each embodiment focuses on the differences from other embodiments, and the same and similar parts of the various embodiments can be referred to each other. As for the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and for the related information, please refer to the description of the method part.

还需说明的是,在本申请文件中,诸如“第一”和“第二”之类的关系术语,仅仅用来将一个实体或者操作与另一个实体或者操作区分开来,而不一定要求或者暗示这些实体或者操作之间存在任何这种实际的关系或者顺序。此外,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。It should also be noted that in this application, relative terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between such entities or operations. Furthermore, the term "comprises", "comprises" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article or apparatus comprising a set of elements includes not only those elements, but also includes elements not expressly listed. other elements of or also include elements inherent in such a process, method, article, or device. Without further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article or apparatus comprising said element.

以上对本申请所提供的技术方案进行了详细介绍。本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想。应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请原理的前提下,还可以对本申请进行若干改进和修饰,这些改进和修饰也落入本申请权利要求的保护范围内。The technical solution provided by the present application has been introduced in detail above. In this paper, specific examples are used to illustrate the principles and implementation methods of the present application, and the descriptions of the above embodiments are only used to help understand the methods and core ideas of the present application. It should be pointed out that those skilled in the art can make some improvements and modifications to the application without departing from the principles of the application, and these improvements and modifications also fall within the protection scope of the claims of the application.

Claims (10)

1. a kind of adaptive masterplate matching process based on cosine similarity, which is characterized in that including:
According to preset cosine similarity function, template image of the images to be recognized from matching starting point with matching target is calculated It carries out matched similarity value and stores;The cosine similarity function is:
Or
Wherein, the pixel size of the template image is a × b;P (i, j) is ash of the template image at point coordinates (i, j) Angle value;A, b, i and j are positive integer, and 1≤i≤a, 1≤j≤b;(x, y) is that the matching of the images to be recognized originates The coordinate of point;Q (x+i, y+j) is gray value of the images to be recognized at point coordinates (x+i, y+j);F (x, y) be with it is described Match the corresponding similarity value of starting point (x, y);
According to the growth trend with the corresponding similarity value of the matching starting point with reversed trend update adjustment translation away from From;
The coordinate of the matching starting point is updated according to the updated translation distance and default translation direction;
Judge whether the coordinate of the updated matching starting point meets preset termination condition;
If it is not, the calculating images to be recognized is then continued to execute from matching starting point and the template image progress for matching target The similarity value matched and the subsequent step stored;
If so, determining the maximum in all similarity values, and determined in images to be recognized according to default basis of characterization The matching target.
2. adaptive masterplate matching process according to claim 1, which is characterized in that the basis matches starting with described The growth trend of the corresponding similarity value of point is included with reversed trend update translation distance:
According to formulaThe translation distance is updated;Wherein, h is The updated translation distance, h ' are the translation distance before update, and h and h ' are positive integer;C1 adjusts ginseng for speedup Number, 1<c1;C2 be deceleration adjustment parameter, 0<c2<1;Predetermined threshold value;[] represents round numbers part.
3. adaptive masterplate matching process according to claim 2, which is characterized in that the predetermined threshold valueFor:
Wherein, β is that the sample image containing the matching target carries out matching obtained similarity value with the template image Mean value;L is threshold coefficient.
4. adaptive masterplate matching process according to claim 2, which is characterized in that the default translation direction for row to Translation.
5. adaptive masterplate matching process according to claim 4, which is characterized in that the translation distance meets condition:
1≤h≤a。
6. adaptive masterplate matching process according to any one of claims 1 to 5, which is characterized in that the basis is preset Basis of characterization determines that the matching target in images to be recognized includes:
Judge the distance between matching starting point corresponding to the two neighboring maximum whether less than pre-determined distance threshold value;
If so, judge the matching starting point corresponding to higher value of the images to be recognized in the two neighboring maximum There are a matching targets at place;
If it is not, then judge that the images to be recognized is deposited respectively in the two neighboring corresponding matching starting point of maximum In a matching target.
7. adaptive template matching process according to claim 6, which is characterized in that the pre-determined distance threshold value includes pre- If lateral distance threshold value and default fore-and-aft distance threshold value;
Whether the distance between described matching starting point judged corresponding to two neighboring maximum is less than pre-determined distance threshold value packet It includes:
Judge whether that the lateral distance between the matching starting point corresponding to the two neighboring maximum is less than the default horizontal stroke It is default less than described to the fore-and-aft distance between the matching starting point corresponding to distance threshold or the two neighboring maximum Fore-and-aft distance threshold value.
8. a kind of adaptive masterplate coalignment based on cosine similarity, which is characterized in that including:
Computing module:For according to preset cosine similarity function, calculating images to be recognized from matching starting point with matching The template image of target carries out matched similarity value and stores;The cosine similarity function is:
Or
Wherein, the pixel size of the template image is a × b;P (i, j) is ash of the template image at point coordinates (i, j) Angle value;A, b, i and j are positive integer, and 1≤i≤a, 1≤j≤b;(x, y) is that the matching of the images to be recognized originates The coordinate of point;Q (x+i, y+j) is gray value of the images to be recognized at point coordinates (x+i, y+j);F (x, y) be with it is described Match the corresponding similarity value of starting point (x, y);
Update module:For according to the growth trend with the corresponding similarity value of the matching starting point with reversed trend more New translation distance;And the coordinate of the matching starting point is carried out according to the updated translation distance and default translation direction Update;
Judgment module:Whether the coordinate for judging the updated matching starting point meets preset termination condition;With toilet When stating the coordinate of the matching starting point of computing module in the updated and being unsatisfactory for the preset termination condition, continue on for calculating Images to be recognized is from matching starting point with matching the matched similarity value of template image progress of target and storing;
Identification module:For when the coordinate of the matching starting point meets the preset termination condition, determining all phases Like the maximum in angle value, and determine according to default basis of characterization the matching target in images to be recognized.
9. a kind of adaptive masterplate matching unit based on cosine similarity, which is characterized in that including:
Memory:For storing computer instruction;
Processor:It is as described in any one of claim 1 to 7 similar based on cosine to realize for performing the computer instruction The step of adaptive masterplate matching process of degree.
10. a kind of computer readable storage medium, which is characterized in that be stored with computer in the computer readable storage medium Program, the computer program are realized as described in any one of claim 1 to 7 based on cosine similarity when being executed by processor Adaptive masterplate matching process the step of.
CN201810022319.2A 2018-01-10 2018-01-10 A kind of adaptive masterplate matching process and device based on cosine similarity Pending CN108256566A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810022319.2A CN108256566A (en) 2018-01-10 2018-01-10 A kind of adaptive masterplate matching process and device based on cosine similarity

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810022319.2A CN108256566A (en) 2018-01-10 2018-01-10 A kind of adaptive masterplate matching process and device based on cosine similarity

Publications (1)

Publication Number Publication Date
CN108256566A true CN108256566A (en) 2018-07-06

Family

ID=62724925

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810022319.2A Pending CN108256566A (en) 2018-01-10 2018-01-10 A kind of adaptive masterplate matching process and device based on cosine similarity

Country Status (1)

Country Link
CN (1) CN108256566A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109410255A (en) * 2018-10-17 2019-03-01 中国矿业大学 A kind of method for registering images and device based on improved SIFT and hash algorithm
CN109815869A (en) * 2019-01-16 2019-05-28 浙江理工大学 A Finger Vein Recognition Method Based on FCN Fully Convolutional Network
CN110688926A (en) * 2019-09-19 2020-01-14 Oppo广东移动通信有限公司 Subject detection method and apparatus, electronic device, and computer-readable storage medium
CN113127670A (en) * 2019-12-31 2021-07-16 飞书数字科技(上海)有限公司 Method, device, storage medium and processor for searching target color

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101901334A (en) * 2009-05-31 2010-12-01 汉王科技股份有限公司 Static object detection method
CN103617625A (en) * 2013-12-13 2014-03-05 中国气象局北京城市气象研究所 Image matching method and image matching device
CN103886760A (en) * 2014-04-02 2014-06-25 李涛 Real-time vehicle type detection system based on traffic video
US8855373B2 (en) * 2010-01-08 2014-10-07 Nec Corporation Similarity calculation device, similarity calculation method, and program
CN104484868A (en) * 2014-10-08 2015-04-01 浙江工业大学 Moving object aerial photograph tracking method with template matching and picture contour being combined
CN106600600A (en) * 2016-12-26 2017-04-26 华南理工大学 Wafer defect detection method based on characteristic matching
CN107194341A (en) * 2017-05-16 2017-09-22 西安电子科技大学 The many convolution neural network fusion face identification methods of Maxout and system

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101901334A (en) * 2009-05-31 2010-12-01 汉王科技股份有限公司 Static object detection method
US8855373B2 (en) * 2010-01-08 2014-10-07 Nec Corporation Similarity calculation device, similarity calculation method, and program
CN103617625A (en) * 2013-12-13 2014-03-05 中国气象局北京城市气象研究所 Image matching method and image matching device
CN103886760A (en) * 2014-04-02 2014-06-25 李涛 Real-time vehicle type detection system based on traffic video
CN104484868A (en) * 2014-10-08 2015-04-01 浙江工业大学 Moving object aerial photograph tracking method with template matching and picture contour being combined
CN106600600A (en) * 2016-12-26 2017-04-26 华南理工大学 Wafer defect detection method based on characteristic matching
CN107194341A (en) * 2017-05-16 2017-09-22 西安电子科技大学 The many convolution neural network fusion face identification methods of Maxout and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
刘冰等: "基于余弦相似度的指纹匹配算法的室内定位方法", 《科技通报》 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109410255A (en) * 2018-10-17 2019-03-01 中国矿业大学 A kind of method for registering images and device based on improved SIFT and hash algorithm
CN109815869A (en) * 2019-01-16 2019-05-28 浙江理工大学 A Finger Vein Recognition Method Based on FCN Fully Convolutional Network
CN110688926A (en) * 2019-09-19 2020-01-14 Oppo广东移动通信有限公司 Subject detection method and apparatus, electronic device, and computer-readable storage medium
CN110688926B (en) * 2019-09-19 2022-12-13 Oppo广东移动通信有限公司 Subject detection method and apparatus, electronic device, and computer-readable storage medium
CN113127670A (en) * 2019-12-31 2021-07-16 飞书数字科技(上海)有限公司 Method, device, storage medium and processor for searching target color

Similar Documents

Publication Publication Date Title
CN108256566A (en) A kind of adaptive masterplate matching process and device based on cosine similarity
CN109409366B (en) Distorted image correction method and device based on angular point detection
CN109308478B (en) Character recognition method and device
CN113808193B (en) Light spot centroid positioning method based on blocking threshold
CN104143186B (en) A kind of SLIC super-pixel piecemeal optimization method
CN107452028B (en) Method and device for determining position information of target image
CN110705544A (en) Self-adaptive rapid target detection method based on fast-RCNN
JP2007026106A (en) Vehicle, image processing program, image processing method, and image processing program
CN108256564B (en) Self-adaptive template matching method and device based on distance measurement dissimilarity
CN112884864A (en) Drawing method based on automatic correction rectangle of electronic whiteboard and application thereof
CN112381844B (en) Adaptive ORB Feature Extraction Method Based on Image Blocking
CN112037272B (en) Target tracking method for rapid regional search based on correlation filtering
CN111814784B (en) Liquid level identification method and related device based on image processing
CN111462232B (en) Object grabbing method, device and storage medium
CN119068215A (en) A method for ORB feature extraction and matching based on adaptive threshold and geometric constraints
CN112434640A (en) Method and device for determining rotation angle of document image and storage medium
CN108257174A (en) Image block matching method and soldered ball position-recognizing system based on sub-pixel level image
CN108121541B (en) Method for generating suggested position when adding two-dimensional interface component to canvas
CN108256565A (en) A kind of adaptive masterplate matching process and device based on cross entropy distinctiveness ratio
KR20160126596A (en) Moving object segmentation method by the pixel-based background estimation
CN108122230B (en) Image block identification method, device, and flip chip solder ball position identification system
CN115661464A (en) Image segmentation method, device, equipment and computer storage medium
CN114663308A (en) Method for realizing flat field correction and multi-angle rapid template matching based on CUDA (compute unified device architecture) and storage medium
CN111383183B (en) Image edge enhancement method and device and computer storage medium
CN113947686A (en) An image feature point extraction threshold dynamic adjustment method and system

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20180706