CN110210346A - A kind of optimization method that video template matching is handled in real time - Google Patents

A kind of optimization method that video template matching is handled in real time Download PDF

Info

Publication number
CN110210346A
CN110210346A CN201910422598.6A CN201910422598A CN110210346A CN 110210346 A CN110210346 A CN 110210346A CN 201910422598 A CN201910422598 A CN 201910422598A CN 110210346 A CN110210346 A CN 110210346A
Authority
CN
China
Prior art keywords
image
data
pixel value
row
sliding window
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
CN201910422598.6A
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.)
Xidian University
Original Assignee
Xidian University
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 Xidian University filed Critical Xidian University
Priority to CN201910422598.6A priority Critical patent/CN110210346A/en
Publication of CN110210346A publication Critical patent/CN110210346A/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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V20/00Scenes; Scene-specific elements
    • G06V20/40Scenes; Scene-specific elements in video content
    • G06V20/48Matching video sequences

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Data Mining & Analysis (AREA)
  • Multimedia (AREA)
  • Artificial Intelligence (AREA)
  • Evolutionary Computation (AREA)
  • General Engineering & Computer Science (AREA)
  • Evolutionary Biology (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Health & Medical Sciences (AREA)
  • Computing Systems (AREA)
  • Databases & Information Systems (AREA)
  • General Health & Medical Sciences (AREA)
  • Medical Informatics (AREA)
  • Software Systems (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Image Analysis (AREA)

Abstract

本发明公开了提出一种视频模板匹配实时处理的优化方法,该方法包括以下步骤:读取并存储模板图像的像素值数据;构建与模板图像T大小相同的滑动窗口,采用滑动窗口对背景图像进行滑动取样,每次滑动对应得到一副子图像,读取子图像的像素值数据,并对子图像的像素值数据进行实时存储和更新;采用最小误差法,获得每次滑动对应的子图像的像素值数据与模板图像的像素值数据的相似度,进而得到模板图像的匹配位置。本发明采用基于相似度的模板匹配以及滑动窗口遍历背景图像的全局搜索策略,在保证效果的基础上,利用现场可编程门阵列加速计算,最终实现了对视频的实时处理。

The invention discloses an optimization method for real-time processing of video template matching. The method includes the following steps: reading and storing pixel value data of a template image; constructing a sliding window with the same size as the template image T, and using the sliding window to adjust the background image Carry out slide sampling, each slide corresponds to get a sub-image, read the pixel value data of the sub-image, and store and update the pixel value data of the sub-image in real time; use the minimum error method to obtain the sub-image corresponding to each slide The similarity between the pixel value data of the template image and the pixel value data of the template image, and then the matching position of the template image is obtained. The present invention adopts template matching based on similarity and a global search strategy of traversing background images with sliding windows, and on the basis of ensuring the effect, uses a field programmable gate array to accelerate calculation, and finally realizes real-time video processing.

Description

一种视频模板匹配实时处理的优化方法An Optimal Method for Real-time Processing of Video Template Matching

技术领域technical field

本发明属于图像处理技术领域,更进一步涉及一种视频模板匹配实时处理的优化方法,可用于在背景图像中对模板图像进行匹配,并实时地输出匹配位置。The invention belongs to the technical field of image processing, and further relates to an optimization method for real-time processing of video template matching, which can be used to match template images in background images and output matching positions in real time.

背景技术Background technique

模板匹配是在一副图像中寻找到与给定目标模板图像的技术,其广泛应用于图像处理及信号处理领域,例如图像检索、图像配准、图像识别等等。然而随着科学技术的飞速发展,图像模板匹配处理工作的信息处理量越来越大,同时人们对实时图像处理的需求也越来越高。在采用通用处理器来实现实时图像的模板匹配的过程中,图像的处理速度已经成为该技术的瓶颈,对于高清图像很难达到实时处理。一些优秀的匹配算法在台式机或工作站上能够正确地执行,而将它们应用于嵌入式系统后,由于主频、存储资源等限制必须对算法进行简化,而简化后的算法常常执行效果很差,有的甚至不能执行。所以随着硬件的快速发展,使用现场可编程门阵列(FPGA)解决实时图像处理问题已经成为一种趋势。Template matching is a technology to find a given target template image in an image, which is widely used in the fields of image processing and signal processing, such as image retrieval, image registration, image recognition and so on. However, with the rapid development of science and technology, the information processing capacity of image template matching processing is increasing, and people's demand for real-time image processing is also increasing. In the process of using general-purpose processors to realize real-time image template matching, the image processing speed has become the bottleneck of this technology, and it is difficult to achieve real-time processing for high-definition images. Some excellent matching algorithms can be executed correctly on desktops or workstations, but after they are applied to embedded systems, the algorithms must be simplified due to limitations such as main frequency and storage resources, and the simplified algorithms often perform poorly , and some cannot even be executed. So with the rapid development of hardware, it has become a trend to use Field Programmable Gate Array (FPGA) to solve real-time image processing problems.

现有的模板匹配实现方案在实时处理方面不理想,其影响速度的主要因素是搜索计算和匹配的操作。一些方案中,为了进行对图像进行遍历搜索,存储了大量的图像数据,其频繁读取降低了速度;另一些方案中,计算部分设计不合理,限制了系统的时钟频率,影响了整体的处理速度。除此之外大量存储和计算也会占用大量的硬件资源,增加实现的成本。Existing implementations of template matching are not ideal in terms of real-time processing, and the main factors affecting the speed are the operations of search calculation and matching. In some schemes, a large amount of image data is stored in order to traverse and search images, and its frequent reading reduces the speed; in other schemes, the design of the calculation part is unreasonable, which limits the clock frequency of the system and affects the overall processing speed. In addition, a large amount of storage and computing will also occupy a large amount of hardware resources, increasing the cost of implementation.

发明内容Contents of the invention

为了解决上述问题,本发明的目的是提出一种视频模板匹配实时处理的优化方法,本发明综合考虑了匹配效果和现场可编程门阵列的计算速度快但不擅长复杂逻辑的特点,本发明采用基于相似度的模板匹配以及滑动窗口遍历背景图像的全局搜索策略,在保证效果的基础上,利用现场可编程门阵列加速计算,最终实现了对视频的实时处理。In order to solve the above problems, the purpose of the present invention is to propose an optimization method for real-time processing of video template matching. The present invention comprehensively considers the characteristics of the matching effect and field programmable gate array that the calculation speed is fast but not good at complex logic. The present invention adopts The template matching based on similarity and the global search strategy of traversing the background image through the sliding window, on the basis of ensuring the effect, use the field programmable gate array to accelerate the calculation, and finally realize the real-time processing of the video.

为了达到上述目的,本发明采用以下技术方案予以解决。In order to achieve the above object, the present invention adopts the following technical solutions.

一种视频模板匹配实时处理的优化方法,包括以下步骤:An optimization method for real-time processing of video template matching, comprising the following steps:

步骤1,设定模板图像T的大小为m×n,背景图像G的大小为M×N;读取并存储模板图像的像素值数据ref[m×n]。Step 1. Set the size of the template image T as m×n, and the size of the background image G as M×N; read and store the pixel value data ref[m×n] of the template image.

步骤2,构建与模板图像T大小相同的滑动窗口A,即滑动窗口A的大小为m×n;采用滑动窗口A对背景图像G进行滑动取样,每次滑动对应得到一副大小为m×n的子图像,读取子图像的像素值数据imgp[m×n],并对子图像的像素值数据imgp[m×n]进行实时存储和更新。Step 2, construct a sliding window A with the same size as the template image T, that is, the size of the sliding window A is m×n; the sliding window A is used to perform sliding sampling on the background image G, and each sliding corresponds to a pair of m×n , read the pixel value data img p [m×n] of the sub-image, and store and update the pixel value data img p [m×n] of the sub-image in real time.

其中,imgp[m×n]表示第p次滑动获得的子图像像素值数据。Among them, img p [m×n] represents the sub-image pixel value data obtained by the p-th slide.

步骤3,采用最小误差法,分别获得每次滑动对应的子图像的像素值数据imgp[m×n]与模板图像的像素值数据ref[m×n]的相似度,进而得到模板图像的匹配位置,完成模板图像与背景图像的匹配。Step 3: Use the minimum error method to obtain the similarity between the pixel value data img p [m×n] of the sub-image corresponding to each slide and the pixel value data ref[m×n] of the template image, and then obtain the template image’s Match the position to complete the matching of the template image and the background image.

与现有技术相比,本发明的有益效果为:Compared with prior art, the beneficial effect of the present invention is:

本发明基于可编程逻辑阵列对模板图像和背景图像的处理,并且在实现过程中通过设计合理的数据存储与更新方法提高了整个处理的速度,并且节省了现场可编程门阵列资源。其基本思路为:通过滑动窗口对背景图像进行全局搜索,然后使用相似度计算对模板图像进行匹配;通过采用多个存储器对滑动窗口获得的子图像的数据进行实施存储和更新,加快了数据存储与更新的速度,节省资源,最终输出模板图像的匹配位置。The invention is based on the processing of the template image and the background image by the programmable logic array, and improves the speed of the whole processing by designing a reasonable data storage and update method in the realization process, and saves the resources of the field programmable gate array. The basic idea is: perform a global search on the background image through the sliding window, and then use the similarity calculation to match the template image; by using multiple memories to store and update the data of the sub-image obtained by the sliding window, the data storage is accelerated. With the update speed, resources are saved, and the matching position of the final output template image is achieved.

附图说明Description of drawings

下面结合附图和具体实施例对本发明做进一步详细说明。The present invention will be described in further detail below in conjunction with the accompanying drawings and specific embodiments.

图1为本发明提供的一种模板匹配实时处理的优化方法的流程示意图。FIG. 1 is a schematic flowchart of an optimization method for template matching real-time processing provided by the present invention.

图2为滑动窗口的滑动过程示意图。FIG. 2 is a schematic diagram of a sliding process of a sliding window.

具体实施方式Detailed ways

下面结合附图对本发明的实施例及效果作进一步详细描述。The embodiments and effects of the present invention will be further described in detail below in conjunction with the accompanying drawings.

步骤1,设定模板图像T的大小为m×n,背景图像G的大小为M×N;读取并存储模板图像的像素值数据ref[m×n];Step 1, set the size of the template image T as m×n, and the size of the background image G as M×N; read and store the pixel value data ref[m×n] of the template image;

从外部存储器读取得到m×n的模板图像的像素值数据,由于对一次匹配过程来说,模板图像是确定不变的,且图像相对较小,因此,将模板图像的像素值数据存储至寄存器中,模板图像的像素值数据记为ref[m×n]。The pixel value data of the m×n template image is read from the external memory. Since the template image is fixed and relatively small for a matching process, the pixel value data of the template image is stored in In the register, the pixel value data of the template image is recorded as ref[m×n].

步骤2,构建与模板图像T大小相同的滑动窗口A,即滑动窗口A的大小为m×n;采用滑动窗口A对背景图像G进行滑动取样,每次滑动对应得到一副大小为m×n的子图像,读取子图像的像素值数据imgp[m×n],并对子图像的像素值数据imgp[m×n]进行实时存储和更新;Step 2, construct a sliding window A with the same size as the template image T, that is, the size of the sliding window A is m×n; the sliding window A is used to perform sliding sampling on the background image G, and each sliding corresponds to a pair of m×n sub-image, read the pixel value data img p [m×n] of the sub-image, and store and update the pixel value data img p [m×n] of the sub-image in real time;

所述滑动取样为:滑动窗口A从背景图像G的左上角开始,从左向右、自上而下依次滑动,每个时钟周期滑动一次,每次滑动一个像素。The sliding sampling is as follows: the sliding window A starts from the upper left corner of the background image G, slides from left to right and from top to bottom, and slides once every clock cycle, and slides one pixel each time.

所述读取子图像的像素值数据imgp[m×n]具体为:The pixel value data img p [m×n] of the read sub-image is specifically:

当滑动窗口A滑动至背景图像的每一行的最左边时,即滑动窗口A在背景图像G中的位置的左上角坐标为(0,y)时,经过m个时钟周期,读取到背景图像最左端的m×n个像素值数据;When the sliding window A slides to the leftmost of each line of the background image, that is, when the coordinates of the upper left corner of the sliding window A in the background image G are (0, y), after m clock cycles, the background image is read The leftmost m×n pixel value data;

当滑动窗口A不位于背景图像的每一行的最左边时,读取的数据由上一个滑动位置的(m-1)列像素值数据,加上当前滑动位置的最后一列像素值数据组成,即每次滑动对应一个n行m列像素值数据;When the sliding window A is not located at the leftmost of each row of the background image, the read data consists of (m-1) columns of pixel value data at the previous sliding position, plus the last column of pixel value data at the current sliding position, that is Each slide corresponds to an n-row m-column pixel value data;

所述对子图像的像素值数据imgp[m×n]进行实时存储,其具体步骤为:The pixel value data img p [m × n] of the sub-image is stored in real time, and its specific steps are:

对每次滑动获得的像素值数据,将前(n-1)行对应存储于(n-1)个存储器中,每行使用一个存储器;则每个时钟周期从(n-1)个存储器中读取到上一个滑动位置的(n-1)个像素值数据,作为当前滑动位置的最后一列的前(n-1)个数据;从外部存储器中读取当前滑动位置的一个数据,作为当前滑动位置的最后一列的第n个数据,即得到当前滑动位置的最后一列数据。For the pixel value data obtained by sliding each time, the first (n-1) rows are correspondingly stored in (n-1) memories, and each row uses one memory; then each clock cycle from (n-1) memories Read the (n-1) pixel value data of the previous sliding position as the first (n-1) data of the last column of the current sliding position; read a data of the current sliding position from the external memory as the current The nth data of the last column of the sliding position, that is, the last column of data of the current sliding position.

所述对子图像的像素值数据imgp[m×n]进行实时更新,其具体步骤为:The pixel value data img p [m × n] of the sub-image is updated in real time, and its specific steps are:

存储器中的数据更新:首先,当滑动窗口向右滑动一个像素,将存储器中地址为0的数据进行更新,将第二行地址为0处的数据写入第一行地址为0处,完成对第一行数据的更新,依次类推,将第(n-1)行的数据地址为0处的数据写入第(n-2)行地址为0处,完成(n-2)行数据的更新;其次,将从外部存储器读取的第n行地址为0处的数据写到第(n-1)行地址为0处,完成第(n-1)行数据的更新;最后,当滑动窗口再次向右滑动一个像素,则将存储器中地址为1的数据进行更新,将第二行地址为1处的数据写入第一行地址为1处,完成对第一行数据的更新,依次类推,将第(n-1)行的数据地址为1处的数据写入第(n-2)行地址为1处,完成(n-2)行数据的更新;其次,将从外部存储器读取的第n行地址为1处的数据写到第(n-1)行地址为1处,完成第(n-1)行数据的更新。依次类推,完成每次滑动窗口滑动的存储器内的数据更新。Data update in memory: first, when the sliding window slides one pixel to the right, the data at address 0 in the memory is updated, and the data at address 0 in the second row is written to address 0 in the first row to complete the The update of the first row of data, and so on, write the data at the address 0 of the (n-1) row to the address 0 of the (n-2) row, and complete the update of the (n-2) row data ;Secondly, the data at the nth row address read from the external memory is written to the (n-1) row address at 0, and the update of the (n-1) row data is completed; finally, when the sliding window Slide one pixel to the right again to update the data at the address 1 in the memory, write the data at the address 1 in the second row to the address 1 in the first row, and complete the update of the data in the first row, and so on , write the data at the (n-1) row whose data address is 1 to the (n-2) row whose address is 1, and complete the update of the (n-2) row data; secondly, read from the external memory The data at the address 1 of the nth row is written to the address 1 of the (n-1)th row, and the update of the (n-1)th row data is completed. By analogy, the update of data in the memory is completed each time the sliding window slides.

每次将当前窗口A内的m×n个背景图像的像素值数据,存放在寄存器中;当滑动窗口滑动时,对应的对寄存器内的数据进行更新。Store the pixel value data of m×n background images in the current window A in the register each time; when the sliding window slides, update the data in the register correspondingly.

按照这样的方式,当滑动窗口A下移时,存储器中已经是更新后的数据,只需要按照之前的操作重复进行即可,直至滑动窗口A滑动至背景图像的右下角,即滑动窗口A的右下角坐标与整幅图像的右下角坐标一致,即完成滑动匹配过程。In this way, when the sliding window A moves down, there is already updated data in the memory, and you only need to repeat the previous operation until the sliding window A slides to the lower right corner of the background image, that is, the bottom right corner of the sliding window A. The coordinates of the lower right corner are consistent with the coordinates of the lower right corner of the entire image, that is, the sliding matching process is completed.

步骤3,采用最小误差法,分别获得每次滑动对应的子图像的像素值数据imgp[m×n]与模板图像的像素值数据ref[m×n]的相似度,进而得到模板图像的匹配位置,完成模板图像与背景图像的匹配。Step 3: Use the minimum error method to obtain the similarity between the pixel value data img p [m×n] of the sub-image corresponding to each slide and the pixel value data ref[m×n] of the template image, and then obtain the template image’s Match the position to complete the matching of the template image and the background image.

基于相似度的模板匹配,其主要思想是:根据不同的相似度函数来计算模板图像与待匹配图像中滑动窗口所覆盖区域数据的相似度。综合考虑模板匹配的效果和计算复杂程度,本发明采用最小误差法计算相似度。The main idea of similarity-based template matching is to calculate the similarity between the template image and the area data covered by the sliding window in the image to be matched according to different similarity functions. Comprehensively considering the template matching effect and calculation complexity, the present invention uses the minimum error method to calculate the similarity.

最小误差法的主要思想是:根据模板图像与滑动窗口所覆盖区域图像的差值来表示它们的相关性。当滑动窗口遍历完背景图像中所有像素后,取差值最小的区域即为模板图像在背景图像中的位置。常见的最小误差函数有方差、均方差、平均绝对误差和绝对误差。最小误差法的计算主要涉及到加法与减法,其很少用到乘法和除法。因此,最小误差法具有实现简单、运算量小的特点。The main idea of the minimum error method is to represent their correlation according to the difference between the template image and the area image covered by the sliding window. After the sliding window traverses all the pixels in the background image, the area with the smallest difference is the position of the template image in the background image. Common minimum error functions are variance, mean square error, mean absolute error, and absolute error. The calculation of the minimum error method mainly involves addition and subtraction, and rarely uses multiplication and division. Therefore, the minimum error method has the characteristics of simple implementation and small amount of calculation.

每次滑动滑动窗口,对应得到当前滑动窗口位置处子图像与模板图像的相似度,将当前滑动窗口位置对应的相似度与上一次滑动窗口位置对应的相似度进行比较,相似度较高的位置即为当前匹配的模板图像的位置;当滑动窗口遍历背景图像后,即得到与模板图像相似度最高的滑动窗口的位置,即为模板图像的匹配位置;Each time the sliding window is slid, the similarity between the sub-image and the template image at the current sliding window position is obtained, and the similarity corresponding to the current sliding window position is compared with the similarity corresponding to the previous sliding window position. The position with higher similarity is is the position of the currently matched template image; when the sliding window traverses the background image, the position of the sliding window with the highest similarity to the template image is obtained, which is the matching position of the template image;

其中,相似度采用绝对误差和表征,相似度越高,绝对误差和越小。Among them, the similarity is represented by the sum of absolute errors, and the higher the similarity, the smaller the sum of absolute errors.

本发明中采用最小误差函数为绝对误差和(SAD)。The minimum error function adopted in the present invention is the sum of absolute errors (SAD).

绝对误差和函数的计算公式为:G(i,j)为滑动窗口内的背景图像的像素值,T(i,j)为模板图像的像素值,|·|为取绝对值符号,(i,j)表示图像中的像素坐标,D为背景图像与模板图像的绝对误差和。The formula for calculating the absolute error sum function is: G(i,j) is the pixel value of the background image in the sliding window, T(i,j) is the pixel value of the template image, |·| is the absolute value symbol, (i,j) represents the pixel coordinates in the image , D is the absolute error sum of the background image and the template image.

即将模板图像与背景图像的对应位置处的像素值相减,再对差值取绝对值,最后,将m×n个绝对值相加,得到两幅图像的绝对误差和,绝对误差和越小,表明相似度越大,绝对误差和最小的位置即为匹配的模板图像位置。That is to subtract the pixel values at the corresponding positions of the template image and the background image, and then take the absolute value of the difference, and finally, add the m×n absolute values to obtain the absolute error sum of the two images, the smaller the absolute error sum , indicating that the greater the similarity, the position with the smallest absolute error sum is the matching template image position.

本发明采用DSP48E1计算背景图像与模板图像的绝对误差和,DSP48E1是一种现场可编程门阵列硬件资源,它是数字信号处理单元,可实现乘法、加法、乘加等运算,使用该资源进行计算可节省现场可编程门阵列的其他资源。在计算相似度时有较多的加减法运算,可使用DSP48E1以节省资源。The present invention adopts DSP48E1 to calculate the absolute error sum of background image and template image, DSP48E1 is a kind of field programmable gate array hardware resource, it is a digital signal processing unit, can realize operations such as multiplication, addition, multiplication and addition, uses this resource to carry out calculation Additional resources of the FPGA can be saved. There are more addition and subtraction operations when calculating the similarity, and DSP48E1 can be used to save resources.

采用DSP48E1计算背景图像与模板图像的绝对误差和,其具体的计算过程为:Using DSP48E1 to calculate the absolute error sum of the background image and the template image, the specific calculation process is:

首先,计算对应差值:将模板图像与背景图像的子图像的对应像素值相减;其中,每个像素值为8位数据,而DSP48E1能够进行48位数据的加减法,将四个像素值进行组合计算减法,即每次计算四个像素值差值;再在被减数前添加0用于借位,减数前添加0,使得每个数据变为9位数,组合后为36位数,再调用DSP48E1原语进行减法运算,计算完成后再将差值的对应位数进行分割,恢复为四个像素值;遍历背景图像,得到每个背景图像的子图像与模板图像的对应差值;First, calculate the corresponding difference: Subtract the corresponding pixel values of the template image and the sub-image of the background image; where, each pixel value is 8-bit data, and DSP48E1 can perform addition and subtraction of 48-bit data, four pixels Values are combined and subtracted, that is, the difference between four pixel values is calculated each time; then add 0 before the subtrahend for borrowing, and add 0 before the subtrahend, so that each data becomes 9 digits, and the combination is 36 number of digits, and then call DSP48E1 primitives to perform subtraction, and after the calculation is completed, divide the corresponding digits of the difference and restore them to four pixel values; traverse the background image to obtain the correspondence between the sub-images of each background image and the template image difference;

其次,对每个对应差值取绝对值:所述对应差值的最高位为符号位,低8位为数据;对所述对应差值的最高位是否借位进行判断,若最高位为0,则借位,表明对应差值为负数,则将低8位取反变为正数,即得所述对应差值的绝对值;否则,所述对应差值的低8位数据即为对应差值的绝对值;Secondly, the absolute value is taken for each corresponding difference value: the highest bit of the corresponding difference value is a sign bit, and the lower 8 bits are data; whether the highest bit of the corresponding difference value is borrowed is judged, if the highest bit is 0 , then borrow, indicating that the corresponding difference is a negative number, then invert the lower 8 bits into a positive number to obtain the absolute value of the corresponding difference; otherwise, the lower 8 bits of the corresponding difference are the corresponding the absolute value of the difference;

最后,对所有对应差值的绝对值进行累加求和,得到背景图像与模板图像的绝对误差和;Finally, the absolute values of all corresponding differences are accumulated and summed to obtain the absolute error sum of the background image and the template image;

具体为:先将所有对应差值的绝对值按两两一组进行求和,得到第一级求和结果,再将第一级求和结果按两两一组进行求和,得到第二级求和结果,依次类推,得到所有对应差值的绝对值的和,即为背景图像与模板图像的绝对误差和。上述对所有绝对值进行累加求和,也可以使用DSP48E1进行求和运算。Specifically: first sum the absolute values of all corresponding differences in pairs to obtain the first-level summation result, and then sum the first-level summation results in pairs to obtain the second-level The summation result, and so on, is the sum of the absolute values of all corresponding differences, which is the absolute error sum of the background image and the template image. The above-mentioned accumulation and summation of all absolute values can also be performed by using DSP48E1.

上述匹配过程也可以表述为:每次滑动对应得到当前的SAD值,将当前的SAD值与上一次滑动得到的相似度高的SAD值进行比较,将较小SAD值作为当前次相似度高的SAD值,当滑动结束时,即得到最小的SAD值即为相似度最高的SAD值,该窗口对应的位置即为匹配位置,即完成模板图像与背景图像的匹配。The above matching process can also be expressed as: each slide corresponds to the current SAD value, compare the current SAD value with the SAD value with high similarity obtained in the previous slide, and use the smaller SAD value as the current SAD value with high similarity. SAD value, when the sliding ends, the smallest SAD value is the SAD value with the highest similarity, and the position corresponding to this window is the matching position, that is, the matching between the template image and the background image is completed.

以上步骤通过流水线的方式进行,每个时钟周期可以得到一个SAD值,背景图像输入完毕后已经遍历了所有位置的SAD值,并完成所有SAD值的比较,输出匹配位置。同时最终实现的时钟频率可以达到100MHz,对于每一帧图像都可以快速地得到其匹配位置,即能够对图像进行实时处理。The above steps are performed in a pipelined manner, and a SAD value can be obtained in each clock cycle. After the background image is input, the SAD values of all positions have been traversed, and the comparison of all SAD values is completed, and the matching position is output. At the same time, the final clock frequency can reach 100MHz, and the matching position of each frame of image can be quickly obtained, that is, the image can be processed in real time.

本发明全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。All or part of the steps of the present invention can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. The medium includes: various mediums capable of storing program codes such as ROM, RAM, magnetic disk or optical disk.

以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。The above is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Anyone skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present invention. Should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be determined by the protection scope of the claims.

Claims (8)

1.一种视频模板匹配实时处理的优化方法,其特征在于,包括以下步骤:1. an optimization method for video template matching real-time processing, is characterized in that, comprises the following steps: 步骤1,设定模板图像T的大小为m×n,背景图像G的大小为M×N;读取并存储模板图像的像素值数据ref[m×n];Step 1, set the size of the template image T as m×n, and the size of the background image G as M×N; read and store the pixel value data ref[m×n] of the template image; 从外部存储器中读取模板图像T的像素值数据,并将其存储于寄存器中;Read the pixel value data of the template image T from the external memory, and store it in the register; 步骤2,构建与模板图像T大小相同的滑动窗口A,即滑动窗口A的大小为m×n;采用滑动窗口A对背景图像G进行滑动取样,每次滑动对应得到一副大小为m×n的子图像,读取子图像的像素值数据imgp[m×n],并对子图像的像素值数据imgp[m×n]进行实时存储和更新;Step 2, construct a sliding window A with the same size as the template image T, that is, the size of the sliding window A is m×n; the sliding window A is used to perform sliding sampling on the background image G, and each sliding corresponds to a pair of m×n sub-image, read the pixel value data img p [m×n] of the sub-image, and store and update the pixel value data img p [m×n] of the sub-image in real time; 其中,imgp[m×n]表示第p次滑动获得的子图像像素值数据;Among them, img p [m×n] represents the sub-image pixel value data obtained by the p-th slide; 步骤3,采用最小误差法,分别获得每次滑动对应的子图像的像素值数据imgp[m×n]与模板图像的像素值数据ref[m×n]的相似度,进而得到模板图像的匹配位置,完成模板图像与背景图像的匹配。Step 3: Use the minimum error method to obtain the similarity between the pixel value data img p [m×n] of the sub-image corresponding to each slide and the pixel value data ref[m×n] of the template image, and then obtain the template image’s Match the position to complete the matching of the template image and the background image. 2.根据权利要求1所述的一种视频模板匹配实时处理的优化方法,其特征在于,所述滑动取样为:滑动窗口A从背景图像G的左上角开始,从左向右、自上而下依次滑动,每个时钟周期滑动一次,每次滑动一个像素。2. the optimization method of a kind of video template matching real-time processing according to claim 1, is characterized in that, described sliding sampling is: sliding window A starts from the upper left corner of background image G, from left to right, from top to bottom Slide down and down in turn, slide once per clock cycle, and slide one pixel at a time. 3.根据权利要求1所述的一种视频模板匹配实时处理的优化方法,其特征在于,所述读取子图像的像素值数据imgp[m×n]具体为:3. the optimization method of a kind of video template matching real-time processing according to claim 1, is characterized in that, the pixel value data img p [m × n] of described reading sub-image is specifically: 当滑动窗口A滑动至背景图像的每一行的最左边时,即滑动窗口A在背景图像G中的位置的左上角坐标为(0,y)时,经过m个时钟周期,读取到背景图像最左端的m×n个像素值数据;When the sliding window A slides to the leftmost of each line of the background image, that is, when the coordinates of the upper left corner of the position of the sliding window A in the background image G are (0, y), after m clock cycles, the background image is read The leftmost m×n pixel value data; 当滑动窗口A不位于背景图像的每一行的最左边时,读取的数据由上一个滑动位置的(m-1)列像素值数据,加上当前滑动位置的最后一列像素值数据组成,即每次滑动对应一个n行m列像素值数据。When the sliding window A is not located at the leftmost of each row of the background image, the read data consists of (m-1) columns of pixel value data at the previous sliding position, plus the last column of pixel value data at the current sliding position, that is Each slide corresponds to an n-row m-column pixel value data. 4.根据权利要求3所述的一种视频模板匹配实时处理的优化方法,其特征在于,所述对子图像的像素值数据imgp[m×n]进行实时存储,其具体步骤为:4. the optimization method of a kind of video template matching real-time processing according to claim 3, is characterized in that, described pixel value data img p [m × n] of sub-image is stored in real time, and its specific steps are: 对每次滑动获得的像素值数据,将前(n-1)行对应存储于(n-1)个存储器中,每行使用一个存储器;则每个时钟周期从(n-1)个存储器中读取到上一个滑动位置的(n-1)个像素值数据,作为当前滑动位置的最后一列的前(n-1)个数据;从外部存储器中读取当前滑动位置的一个数据,作为当前滑动位置的最后一列的第n个数据,即得到当前滑动位置的最后一列数据。For the pixel value data obtained by sliding each time, the first (n-1) rows are correspondingly stored in (n-1) memories, and each row uses one memory; then each clock cycle from (n-1) memories Read the (n-1) pixel value data of the previous sliding position as the first (n-1) data of the last column of the current sliding position; read a data of the current sliding position from the external memory as the current The nth data of the last column of the sliding position, that is, the last column of data of the current sliding position. 5.根据权利要求4所述的一种视频模板匹配实时处理的优化方法,其特征在于,所述对子图像的像素值数据imgp[m×n]进行实时更新,其具体步骤为:5. the optimization method of a kind of video template matching real-time processing according to claim 4, is characterized in that, described pixel value data img p [m × n] of sub-image is updated in real time, and its concrete steps are: 存储器中的数据更新:首先,当滑动窗口向右滑动一个像素,将存储器中地址为0的数据进行更新,将第二行地址为0处的数据写入第一行地址为0处,完成对第一行数据的更新,依次类推,将第(n-1)行的数据地址为0处的数据写入第(n-2)行地址为0处,完成(n-2)行数据的更新;其次,将从外部存储器读取的第n行地址为0处的数据写到第(n-1)行地址为0处,完成第(n-1)行数据的更新;最后,当滑动窗口再次向右滑动一个像素,则将存储器中地址为1的数据进行更新,将第二行地址为1处的数据写入第一行地址为1处,完成对第一行数据的更新,依次类推,将第(n-1)行的数据地址为1处的数据写入第(n-2)行地址为1处,完成(n-2)行数据的更新;其次,将从外部存储器读取的第n行地址为1处的数据写到第(n-1)行地址为1处,完成第(n-1)行数据的更新;依次类推,完成每次滑动窗口滑动的存储器内的数据更新;Data update in memory: first, when the sliding window slides one pixel to the right, the data at address 0 in the memory is updated, and the data at address 0 in the second row is written to address 0 in the first row to complete the The update of the first row of data, and so on, write the data at the address 0 of the (n-1) row to the address 0 of the (n-2) row, and complete the update of the (n-2) row data ;Secondly, the data at the address of the nth row read from the external memory is 0 and written to the address of the (n-1) row at 0, and the update of the data in the (n-1) row is completed; finally, when the sliding window Slide one pixel to the right again to update the data at the address 1 in the memory, write the data at the address 1 in the second row to the address 1 in the first row, and complete the update of the data in the first row, and so on , write the data at the address 1 of the (n-1) row to the address 1 of the (n-2) row, and complete the update of the (n-2) row data; secondly, read from the external memory Write the data at the address of the nth row of 1 to the address of the (n-1)th row at 1, and complete the update of the (n-1)th row of data; and so on, complete the data in the memory of each sliding window sliding renew; 每次将当前窗口A内的m×n个背景图像的像素值数据,存放在寄存器中;当滑动窗口滑动时,对应的对寄存器内的数据进行更新。Store the pixel value data of m×n background images in the current window A in the register each time; when the sliding window slides, update the data in the register correspondingly. 6.根据权利要求1所述的一种视频模板匹配实时处理的优化方法,其特征在于,所述最小误差法采用的最小误差函数为绝对误差和,其计算公式为:6. the optimization method of a kind of video template matching real-time processing according to claim 1, is characterized in that, the minimum error function that described minimum error method adopts is absolute error sum, and its computing formula is: 其中,G(i,j)为滑动窗口内的背景图像的像素值,T(i,j)为模板图像的像素值,|·|为取绝对值符号,(i,j)表示图像中的像素坐标,D为背景图像与模板图像的绝对误差和。Among them, G(i, j) is the pixel value of the background image in the sliding window, T(i, j) is the pixel value of the template image, |·| is the absolute value symbol, (i, j) represents the Pixel coordinates, D is the sum of absolute errors between the background image and the template image. 7.根据权利要求1所述的一种视频模板匹配实时处理的优化方法,其特征在于,所述分别获得每次滑动对应的子图像的像素值数据imgp[m×n]与模板图像的像素值数据ref[m×n]的相似度,进而得到模板图像的匹配位置,其具体步骤为:7. the optimization method of a kind of video template matching real-time processing according to claim 1, is characterized in that, described respectively obtains the pixel value data img p [m × n] of the sub-image corresponding to each slide and the template image The similarity of the pixel value data ref[m×n], and then the matching position of the template image is obtained. The specific steps are: 每次滑动滑动窗口,对应得到当前滑动窗口位置处子图像与模板图像的相似度,将当前滑动窗口位置对应的相似度与上一次滑动窗口位置对应的相似度进行比较,相似度较高的位置即为当前匹配的模板图像的位置;当滑动窗口遍历背景图像后,即得到与模板图像相似度最高的滑动窗口的位置,即为模板图像的匹配位置;Each time the sliding window is slid, the similarity between the sub-image and the template image at the current sliding window position is obtained, and the similarity corresponding to the current sliding window position is compared with the similarity corresponding to the previous sliding window position. The position with higher similarity is is the position of the currently matched template image; when the sliding window traverses the background image, the position of the sliding window with the highest similarity to the template image is obtained, which is the matching position of the template image; 其中,相似度采用绝对误差和表征,相似度越高,绝对误差和越小。Among them, the similarity is represented by the sum of absolute errors, and the higher the similarity, the smaller the sum of absolute errors. 8.根据权利要求1所述的一种视频模板匹配实时处理的优化方法,其特征在于,采用DSP48E1计算背景图像与模板图像的绝对误差和,其具体的计算过程为:8. the optimization method of a kind of video template matching real-time processing according to claim 1, is characterized in that, adopts DSP48E1 to calculate the absolute error of background image and template image and, its concrete calculation process is: 首先,计算对应差值:将模板图像与背景图像的子图像的对应像素值相减;其中,每个像素值为8位数据,而DSP48E1能够进行48位数据的加减法,将四个像素值进行组合计算减法,即每次计算四个像素值差值;再在被减数前添加0用于借位,减数前添加0,使得每个数据变为9位数,组合后为36位数,再调用DSP48E1原语进行减法运算,计算完成后再将差值的对应位数进行分割,恢复为四个像素值;遍历背景图像,得到每个背景图像的子图像与模板图像的对应差值;First, calculate the corresponding difference: Subtract the corresponding pixel values of the template image and the sub-image of the background image; where, each pixel value is 8-bit data, and DSP48E1 can perform addition and subtraction of 48-bit data, four pixels Values are combined and subtracted, that is, the difference between four pixel values is calculated each time; then add 0 before the subtrahend for borrowing, and add 0 before the subtrahend, so that each data becomes 9 digits, and the combination is 36 number of digits, and then call DSP48E1 primitives to perform subtraction, and after the calculation is completed, divide the corresponding digits of the difference and restore them to four pixel values; traverse the background image to obtain the correspondence between the sub-images of each background image and the template image difference; 其次,对每个对应差值取绝对值:所述对应差值的最高位为符号位,低8位为数据;对所述对应差值的最高位是否借位进行判断,若最高位为0,则借位,表明对应差值为负数,则将低8位取反变为正数,即得所述对应差值的绝对值;否则,所述对应差值的低8位数据即为对应差值的绝对值;Secondly, the absolute value is taken for each corresponding difference value: the highest bit of the corresponding difference value is a sign bit, and the lower 8 bits are data; whether the highest bit of the corresponding difference value is borrowed is judged, if the highest bit is 0 , then borrow, indicating that the corresponding difference is a negative number, then invert the lower 8 bits into a positive number to obtain the absolute value of the corresponding difference; otherwise, the lower 8 bits of the corresponding difference are the corresponding the absolute value of the difference; 最后,对所有对应差值的绝对值进行累加求和,得到背景图像与模板图像的绝对误差和;Finally, the absolute values of all corresponding differences are accumulated and summed to obtain the absolute error sum of the background image and the template image; 具体为:先将所有对应差值的绝对值按两两一组进行求和,得到第一级求和结果,再将第一级求和结果按两两一组进行求和,得到第二级求和结果,依次类推,得到所有对应差值的绝对值的和,即为背景图像与模板图像的绝对误差和。Specifically: first sum the absolute values of all corresponding differences in pairs to obtain the first-level summation result, and then sum the first-level summation results in pairs to obtain the second-level The summation result, and so on, is the sum of the absolute values of all corresponding differences, which is the absolute error sum of the background image and the template image.
CN201910422598.6A 2019-05-21 2019-05-21 A kind of optimization method that video template matching is handled in real time Pending CN110210346A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910422598.6A CN110210346A (en) 2019-05-21 2019-05-21 A kind of optimization method that video template matching is handled in real time

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910422598.6A CN110210346A (en) 2019-05-21 2019-05-21 A kind of optimization method that video template matching is handled in real time

Publications (1)

Publication Number Publication Date
CN110210346A true CN110210346A (en) 2019-09-06

Family

ID=67787919

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910422598.6A Pending CN110210346A (en) 2019-05-21 2019-05-21 A kind of optimization method that video template matching is handled in real time

Country Status (1)

Country Link
CN (1) CN110210346A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111598177A (en) * 2020-05-19 2020-08-28 中国科学院空天信息创新研究院 An Adaptive Maximum Sliding Window Matching Method for Low Overlap Image Matching
CN111780781A (en) * 2020-06-23 2020-10-16 南京航空航天大学 A combined visual and inertial odometry for template matching based on sliding window optimization
CN112967310A (en) * 2021-02-04 2021-06-15 成都国翼电子技术有限公司 FPGA-based template matching acceleration method
CN113900805A (en) * 2021-10-07 2022-01-07 珠海一微半导体股份有限公司 A kind of image processing method and chip based on fixed orientation
CN114584673A (en) * 2020-12-01 2022-06-03 京东方科技集团股份有限公司 Image processing method and device
CN115082714A (en) * 2021-03-16 2022-09-20 南京理工大学 Adaptive template matching algorithm based on MCD distance

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060002472A1 (en) * 2004-06-30 2006-01-05 Mehta Kalpesh D Various methods and apparatuses for motion estimation
US20060002471A1 (en) * 2004-06-30 2006-01-05 Lippincott Louis A Motion estimation unit
US20090028440A1 (en) * 2007-07-27 2009-01-29 Sportvision, Inc. Detecting an object in an image using multiple templates
US20100020880A1 (en) * 2008-07-22 2010-01-28 Mathstar, Inc. Field programmable object array having image processing circuitry
CN103514293A (en) * 2013-10-09 2014-01-15 北京中科模识科技有限公司 Method for video matching in video template library
CN105761233A (en) * 2014-12-15 2016-07-13 南京理工大学 FPGA-based real-time panoramic image mosaic method
US20170339404A1 (en) * 2016-05-17 2017-11-23 Arris Enterprises Llc Template matching for jvet intra prediction
CN109671042A (en) * 2018-12-19 2019-04-23 西安电子科技大学 Gray-scale image processing system and method based on FPGA morphological operator
CN109743562A (en) * 2019-01-10 2019-05-10 中国科学技术大学 Circuit structure and working method of matching cost calculation based on Census algorithm

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060002472A1 (en) * 2004-06-30 2006-01-05 Mehta Kalpesh D Various methods and apparatuses for motion estimation
US20060002471A1 (en) * 2004-06-30 2006-01-05 Lippincott Louis A Motion estimation unit
US20090028440A1 (en) * 2007-07-27 2009-01-29 Sportvision, Inc. Detecting an object in an image using multiple templates
US20100020880A1 (en) * 2008-07-22 2010-01-28 Mathstar, Inc. Field programmable object array having image processing circuitry
CN103514293A (en) * 2013-10-09 2014-01-15 北京中科模识科技有限公司 Method for video matching in video template library
CN105761233A (en) * 2014-12-15 2016-07-13 南京理工大学 FPGA-based real-time panoramic image mosaic method
US20170339404A1 (en) * 2016-05-17 2017-11-23 Arris Enterprises Llc Template matching for jvet intra prediction
CN109671042A (en) * 2018-12-19 2019-04-23 西安电子科技大学 Gray-scale image processing system and method based on FPGA morphological operator
CN109743562A (en) * 2019-01-10 2019-05-10 中国科学技术大学 Circuit structure and working method of matching cost calculation based on Census algorithm

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
周文晖;杜歆;叶秀清;顾伟康;: "基于FPGA的双目立体视觉系统" *
沙莎;刘锦峰;: "基于差分有序数组的图像匹配快速算法" *

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111598177A (en) * 2020-05-19 2020-08-28 中国科学院空天信息创新研究院 An Adaptive Maximum Sliding Window Matching Method for Low Overlap Image Matching
CN111780781A (en) * 2020-06-23 2020-10-16 南京航空航天大学 A combined visual and inertial odometry for template matching based on sliding window optimization
CN114584673A (en) * 2020-12-01 2022-06-03 京东方科技集团股份有限公司 Image processing method and device
CN114584673B (en) * 2020-12-01 2024-01-09 京东方科技集团股份有限公司 Image processing method and device
CN112967310A (en) * 2021-02-04 2021-06-15 成都国翼电子技术有限公司 FPGA-based template matching acceleration method
CN112967310B (en) * 2021-02-04 2023-07-14 成都国翼电子技术有限公司 Template matching acceleration method based on FPGA
CN115082714A (en) * 2021-03-16 2022-09-20 南京理工大学 Adaptive template matching algorithm based on MCD distance
CN113900805A (en) * 2021-10-07 2022-01-07 珠海一微半导体股份有限公司 A kind of image processing method and chip based on fixed orientation

Similar Documents

Publication Publication Date Title
CN110210346A (en) A kind of optimization method that video template matching is handled in real time
Huang et al. Flowformer: A transformer architecture for optical flow
CN108133270B (en) Convolutional Neural Network Acceleration Method and Device
CN109784372B (en) Target classification method based on convolutional neural network
JP2019504394A (en) Quasi-parametric optical flow estimation
Sun et al. A flexible and efficient real-time orb-based full-hd image feature extraction accelerator
CN111583093B (en) Hardware implementation method for ORB feature point extraction with good real-time performance
CN104751484A (en) Moving target detection method and detection system for achieving same
US20210312215A1 (en) Method for book recognition and book reading device
Wang et al. Rethinking low-level features for interest point detection and description
Shi et al. Focus for free in density-based counting
CN113596576A (en) Video super-resolution method and device
CN117496204A (en) An image feature point matching method, device, equipment and medium
Zhang et al. Tmp: Temporal motion propagation for online video super-resolution
KR102756789B1 (en) Method of matching images for merging the images and data processing device performing the same
CN117726921A (en) FPGA-implemented ORB feature extraction accelerator based on stream processing and non-blocking
CN113630601B (en) An affine motion estimation method, device, equipment and storage medium
CN108629798A (en) Rapid Image Registration method based on GPU
CN116091297A (en) Image connected domain marking hardware implementation algorithm
CN110569684B (en) Image binarization method for small-capacity cache
Shi et al. Large displacement optical flow estimation based on robust interpolation of sparse correspondences
Kupade et al. Fpga implementation of moving object segmentation using abpd and background model
Chen et al. VLSI architecture design of weighted mode filter for Full-HD depth map upsampling at 30fps
Pourganjalikhan et al. Adaptive memory management for video object segmentation
CN113869326A (en) SURF feature point extraction method, system, computer device and storage medium

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
AD01 Patent right deemed abandoned
AD01 Patent right deemed abandoned

Effective date of abandoning: 20231103