Single-target single-scale multi-angle rapid template matching algorithm

By using image pyramid downsampling and a two-step rotating template matching algorithm, single-target, single-scale, multi-angle template matching is optimized, solving the problems of time consumption and insufficient accuracy in existing technologies. This achieves efficient and accurate template matching, making it suitable for applications requiring high real-time performance and high precision.

CN121883884APending Publication Date: 2026-04-17HUAYI INTELLIGENT EQUIP (HANGZHOU) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUAYI INTELLIGENT EQUIP (HANGZHOU) CO LTD
Filing Date
2024-10-17
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Existing template matching technologies are mostly designed for multi-target, multi-scale, and multi-angle application scenarios. They fail to effectively optimize single-target, single-scale, and multi-angle scenarios, resulting in high time consumption and insufficient matching accuracy in complex multi-angle situations.

Method used

A fast template matching algorithm with single target, single scale, and multiple angles is adopted, including image pyramid downsampling and two-step rotation template matching. The optimal matching angle is initially located by a large step size, and then the step size is gradually reduced for fine search. Combined with image pyramid and sub-pixel interpolation techniques, the computational load and accuracy are optimized.

Benefits of technology

In single-target, single-scale, multi-angle scenarios, it significantly shortens the matching time and improves matching accuracy and efficiency. It is suitable for template matching scenarios with high real-time requirements and high accuracy, and has adaptability and high robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121883884A_ABST
    Figure CN121883884A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of template matching in the field of computer vision, and discloses a single-target single-scale multi-angle rapid template matching algorithm, which comprises the following steps: S1, acquiring a test image and a template image; s2, reducing the resolution and the size by using an image pyramid; s3, a two-step method is used for rotating the template for matching; s4, calculating similarity, and returning a matching result of an optimal score; according to the method, under the condition of a single target, a single scale and multiple angles, the time consumed by template matching is optimized, and according to the actual condition of a user, the user can adjust the threshold parameters of template matching by himself or herself, such as the range control of the rotation angle, the selection of the step length of the rotation angle and the layer number of the image pyramid, so that the template matching efficiency is improved. The method has high adaptability, optimization of algorithm time is the most key, and the method is applied to a template matching scene with high real-time performance and high precision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of template matching technology in computer vision, specifically a fast template matching algorithm for single target, single scale, and multiple angles. Background Technology

[0002] Image matching algorithms are classified into three categories: gray-level-based matching algorithms, feature-based matching algorithms, and relation-based matching algorithms. Gray-level-based matching algorithms, also known as template matching (blocking matching), search for sub-images similar to a given template image within another image. Gray-level-based matching algorithms are also called correlation matching algorithms, using a two-dimensional sliding template for matching. The main difference between matching algorithms lies in the choice of correlation criteria, that is, the choice of formula for calculating similarity.

[0003] The open-source computer vision library OpenCV provides the template matching function `matchTemplate`, which can use normalized cross-correlation coefficients to calculate similarity. However, this method is translation matching and does not support rotation. In other words, when there is an angular difference between the target and the template, matching often fails. Even a slight rotation of the target can significantly reduce the matching score, leading to decreased matching accuracy or even failure to match.

[0004] Existing template matching techniques are mostly designed for multi-target, multi-scale, and multi-angle applications, lacking optimization for single-target, single-scale, and multi-angle scenarios, resulting in significant time consumption. Especially when facing complex multi-angle situations, most methods involve rotating templates or their features to match the test image. This involves performing a 360-degree traversal with a fixed step size to create multiple templates for brute-force matching. This method is heavily influenced by the step size selection; too small a step size leads to high time consumption, while too large a step size results in inaccurate results. Therefore, this paper proposes a fast template matching algorithm for single-target, single-scale, and multi-angle applications. Summary of the Invention

[0005] The purpose of this invention is to provide a fast template matching algorithm for single-target, single-scale, multi-angle applications, addressing the problem that most existing template matching techniques mentioned in the background are designed for multi-target, multi-scale, and multi-angle applications, without optimization for single-target, single-scale, multi-angle applications, resulting in significant time consumption. Especially when facing complex multi-angle situations, methods typically involve rotating templates or their features to match the test image. This method involves traversing 360 degrees with a fixed step size to create templates for force matching at multiple angles. However, this method is heavily influenced by the step size selection; too small a step size results in high time consumption, while too large a step size leads to inaccurate results.

[0006] To achieve the above objectives, the present invention provides the following technical solution: a fast template matching algorithm for single target, single scale, and multiple angles, comprising the following steps:

[0007] S1. Obtain the test image and template image;

[0008] S2. Use image pyramids to reduce resolution and size;

[0009] S3. Use a two-step method to rotate the template for matching;

[0010] S4. Calculate the similarity and return the best matching result;

[0011] S5, Display Output.

[0012] As a preferred embodiment, in S2, an image pyramid is constructed, and the template image and test image are downsampled step by step to reduce the amount of computation in the subsequent matching process.

[0013] Preferably, the image pyramid described above is constructed using a Gaussian pyramid or a Laplacian pyramid to progressively reduce the resolution and size of the image.

[0014] Preferably, the above-mentioned step S3 includes the following sub-steps;

[0015] S301. First step: Set a large angle step size, rotate the template image with this step size in the range of 0 degrees to 360 degrees, traverse all angles and record the best matching score and corresponding angle.

[0016] S302, Second step: Based on the best matching angle obtained in S301, set an initial large angle step size, search around this angle and record the matching score, gradually reduce the angle step size, and after each reduction, search again with the current best matching angle as the center, until the angle step size is reduced to the preset small angle step size, and continuously record and update the best matching angle and score.

[0017] Preferably, the large-angle step size and small-angle step size mentioned above can be adjusted according to actual needs to balance matching speed and accuracy.

[0018] As a preferred embodiment, in S4, the matching position is first adjusted according to the number of pyramid scaling operations, then the position of the rotated template vertex is calculated and converted to the coordinate system of the original image for output.

[0019] Preferably, in S5, the output is a matching rectangle, tilt angle, and direction.

[0020] Compared with the prior art, the present invention, employing the above technical solution, has the following technical effects:

[0021] I. This invention optimizes the template matching time in the case of single target, single scale, and multiple angles. It can also adjust the threshold parameters of template matching according to the actual situation of the user, such as the range control of the rotation angle, the selection of the rotation angle step size, and the number of layers of the image pyramid. It has high adaptability. In this invention, the optimization of algorithm time is the most critical and it is applied to template matching scenarios with high real-time performance and high precision.

[0022] Second, this invention demonstrates how to quickly rotate the angle of the test image and the template image at the same scale to accurately identify a single target in the test image. It features high real-time performance, high precision, and ease of operation. It is suitable for template images with single targets, single scale, and multiple angles, and is applicable to template matching scenarios with high time requirements.

[0023] Third, this invention uses an image pyramid to downsample the template image and the test image step by step, which effectively reduces the amount of computation in the subsequent matching process, thereby greatly improving the matching efficiency. It is especially suitable for high-resolution images and can significantly shorten the matching time.

[0024] Fourth, this invention uses a two-step rotating template for matching. First, it quickly locates the approximate range of the optimal matching angle by using a large angle step size. Then, it gradually reduces the angle step size for fine searching. While ensuring matching speed, it improves matching accuracy by refining the search range and gradually reducing the step size, making the matching result closer to the true value. Attached Figure Description

[0025] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0026] Figure 1 This is a flowchart of the algorithm of the present invention. Detailed Implementation

[0027] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0028] It should be noted that the structures, proportions, sizes, etc., shown in the accompanying drawings of this specification are only for the purpose of assisting those skilled in the art in understanding and reading the content disclosed in the specification, and are not intended to limit the conditions under which this application can be implemented. Therefore, they have no substantial technical significance. Any modifications to the structure, changes in the proportions, or adjustments to the size should still fall within the scope of the technical content disclosed in this application, provided that they do not affect the effects and purposes that this application can produce.

[0029] Example

[0030] In existing technologies, most template matching solutions are designed for multi-target, multi-scale, and multi-angle applications, without optimization for single-target, single-scale, and multi-angle applications, resulting in significant time consumption. Especially when facing complex multi-angle situations, methods typically involve rotating templates or their features to match the test image. This method involves traversing 360 degrees with a fixed step size to create templates for multiple angles for brute-force matching. However, this method is heavily influenced by the step size selection; too small a step size leads to high time consumption, while too large a step size results in inaccurate results.

[0031] Please see Figure 1 This invention provides a technical solution: a fast template matching algorithm for single target, single scale, and multiple angles, comprising the following steps:

[0032] S1. Obtain the test image and template image. After obtaining the images, perform basic input validation to ensure that the image files are valid, correctly formatted, and not empty. This includes checking whether the file exists, whether the file size is reasonable, and whether the image data is complete. Preprocess the obtained images, such as grayscale conversion (if the original image is color), noise reduction (e.g., using Gaussian filtering or median filtering), and edge detection (optional, depending on the application scenario requirements) to improve the matching effect.

[0033] S2. Use image pyramids to reduce resolution and size;

[0034] By constructing an image pyramid and downsampling the template and test images step by step, the computational load in the subsequent matching process is reduced. This not only preserves the main features of the images but also significantly improves the processing speed, making it particularly suitable for processing high-resolution images.

[0035] Image pyramids are constructed using either Gaussian or Laplacian pyramids to progressively reduce the resolution and size of the image.

[0036] The number of layers in the image pyramid is dynamically selected based on the actual size and resolution of the image. For high-resolution images, the number of layers can be increased to more effectively reduce computation; for low-resolution images, fewer layers may be needed. Gaussian blur is used to smooth the image during pyramid construction to reduce jagged edges introduced by downsampling. Simultaneously, the main features of the image are preserved as much as possible during downsampling. Parallel processing or GPU acceleration is considered to speed up the image pyramid construction process, especially when dealing with large-scale datasets. Using the image pyramid to progressively downsample the template and test images effectively reduces the computational load in subsequent matching processes, thus significantly improving matching efficiency, especially for high-resolution images, and can significantly shorten matching time.

[0037] S3. Use a two-step method to rotate the template for matching;

[0038] Includes the following sub-steps;

[0039] S301. First step: Set a large angle step size, such as 30 degrees. Rotate the template image with this step size within the range of 0 degrees to 360 degrees, traverse all angles and record the best matching score and corresponding angle.

[0040] S302, Second step: Based on the best matching angle obtained in S301, set an initial large angle step size, expand the step size by a large angle, refine the angle range, search around the angle and record the matching score, set the large angle to one-fifth of this range, and then continue to use the reduced large angle to traverse within this range until the range is reduced to five times the small angle, then switch to using the small angle step size to traverse, gradually reduce the angle step size, and after each reduction, search again with the current best matching angle as the center until the angle step size is reduced to the preset small angle step size, continuously record and update the best matching angle and score;

[0041] For example, with a value of 0.1 degrees, a matching angle and score are obtained. Simply put, the angle is first roughly obtained as the best score angle, and then the angle is gradually fine-tuned to the optimal value.

[0042] The two-step method of rotating the template is used for matching. First, the approximate range of the best matching angle is quickly located by using a large angle step size. Then, the angle step size is gradually reduced to perform a fine search, thereby reducing unnecessary calculations while ensuring accuracy.

[0043] The large and small angle step sizes can be adjusted according to actual needs to balance matching speed and accuracy. By refining the angle search range and gradually reducing the angle step size during traversal, the matching algorithm can find the optimal value that is closer to the actual matching angle, thereby improving the matching accuracy.

[0044] In the large-angle step-size search phase, in addition to recording the best matching score and angle, some suboptimal solutions can also be recorded as alternative points in subsequent refinement searches, increasing the robustness of the search. In the refinement search phase, besides gradually reducing the angle step-size, nonlinear search strategies, such as binary search or golden section search, can be introduced to approach the best matching angle more quickly. The angle step-size is dynamically adjusted based on the rate of change of matching scores in the current search area. Larger step-sizes are used in areas with large score variations, while smaller step-sizes are used in areas where scores tend to stabilize.

[0045] S4. Calculate the similarity and return the best matching result;

[0046] First, the matching position is adjusted according to the number of pyramid scaling steps. Then, the position of the rotated template vertex is calculated and transformed into the coordinate system of the original image to output the result. When calculating the similarity, the matching position is adjusted to take into account the effect of pyramid scaling, so as to ensure that accurate matching results can be obtained even at different resolutions.

[0047] Users can adjust parameters such as the range of rotation angles, rotation angle step size, and the number of layers in the image pyramid according to actual needs, thereby achieving optimal matching results in different scenarios. Multiple similarity measurement methods (such as normalized cross-correlation and structural similarity index) are compared to select the most suitable method for the current application scenario. When converting the matching results back to the original image coordinate system, the impact of pyramid scaling on position is considered, and precise position adjustments are made. Simultaneously, sub-pixel interpolation techniques (such as bilinear or bicubic interpolation) are used to improve the accuracy of the matching position. Matching is performed at different levels of the pyramid, and the consistency of the matching results at different scales is verified to improve the stability and reliability of the matching.

[0048] S5, Display Output.

[0049] The output displays the matching rectangle, tilt angle, and direction, presenting the matching results to the user in a visual format. This includes drawing the matching rectangle on the original image and labeling the tilt angle and direction. It also displays a matching score to allow users to evaluate the matching quality and analyze the results, such as calculating the confidence level of the matching region and identifying potential false matches. Based on the analysis results, further optimization suggestions or corrective actions are provided.

[0050] There are many image matching algorithms, including quite a few grayscale matching algorithms. The main difference lies in the different similarity calculation formulas. This invention adopts grayscale template matching based on NCC because this algorithm is the most commonly used and most basic template matching method in the industry. NCC, or Normalized Cross-Correlation Coefficient, is widely used in template matching and is a standout among many template matching methods. This algorithm has better stability under the influence of lighting, noise, etc.

[0051] In the case of single target, single scale, and multiple angles, the time consumed by template matching is optimized, and the threshold parameters of template matching can be adjusted according to the actual situation of the user, such as the range control of the rotation angle, the selection of the rotation angle step size, and the number of layers of the image pyramid. It has high adaptability. In this invention, the optimization of algorithm time is the most critical, and it is applied to template matching scenarios with high real-time performance and high precision.

[0052] This invention is based on a fast template matching algorithm using OpenCV. It can quickly rotate the test image and template image at the same scale to accurately identify a single target in the test image. It features high real-time performance, high accuracy, and ease of operation. It is suitable for template matching scenarios with single target, single scale, and multiple angles, and where time is a critical factor.

[0053] This invention uses an image pyramid to downsample the template image and the test image step by step, which effectively reduces the amount of computation in the subsequent matching process, thereby greatly improving the matching efficiency. It is especially suitable for high-resolution images and can significantly shorten the matching time.

[0054] This invention employs a two-step method of rotating templates for matching. First, it quickly locates the approximate range of the optimal matching angle using a large angle step size. Then, it gradually reduces the angle step size for a fine search. While ensuring matching speed, it improves matching accuracy by refining the search range and gradually reducing the step size, making the matching result closer to the true value.

[0055] Those skilled in the art will understand that the features described in the various embodiments and / or claims of the present invention can be combined or combined in various ways, even if such combinations or combinations are not explicitly described in the present invention. In particular, the features described in the various embodiments and / or claims of the present invention can be combined or combined in various ways without departing from the spirit and teachings of the present invention. All such combinations and / or combinations fall within the scope of the present invention.

Claims

1. A fast template matching algorithm for single-target, single-scale, multi-angle applications, characterized in that: Includes the following steps: S1. Obtain the test image and template image; S2. Use image pyramids to reduce resolution and size; S3. Use a two-step method to rotate the template for matching; S4. Calculate the similarity and return the best matching result; S5, Display Output.

2. The fast template matching algorithm for single target, single scale, and multiple angles according to claim 1, characterized in that: In S2, an image pyramid is constructed, and the template image and test image are downsampled step by step to reduce the amount of computation in the subsequent matching process.

3. The fast template matching algorithm for single target, single scale, and multiple angles according to claim 2, characterized in that: The image pyramid is constructed using a Gaussian pyramid or a Laplacian pyramid to progressively reduce the image resolution and size.

4. The fast template matching algorithm for single target, single scale, and multiple angles according to claim 1, characterized in that: S3 includes the following sub-steps; S301. First step: Set a large angle step size, rotate the template image with this step size in the range of 0 degrees to 360 degrees, traverse all angles and record the best matching score and corresponding angle. S302, Second step: Based on the best matching angle obtained in S301, set an initial large angle step size, search around this angle and record the matching score, gradually reduce the angle step size, and after each reduction, search again with the current best matching angle as the center, until the angle step size is reduced to the preset small angle step size, and continuously record and update the best matching angle and score.

5. The fast template matching algorithm for single target, single scale, and multiple angles according to claim 4, characterized in that: The large-angle step size and small-angle step size can be adjusted according to actual needs to balance matching speed and accuracy.

6. The fast template matching algorithm for single target, single scale, and multiple angles according to claim 5, characterized in that: In S4, the matching position is first adjusted according to the number of pyramid scaling steps, then the position of the rotated template vertex is calculated and transformed into the coordinate system of the original image to output the result.

7. The fast template matching algorithm for single target, single scale, and multiple angles according to claim 1, characterized in that: In S5, the output is the output of the matching rectangle, tilt angle, and direction.