A method, apparatus, device, and storage medium for template matching of visual features.

CN119625357BActive Publication Date: 2026-08-14WUHAN FUGUANG TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

[0005]针对现有技术的至少一个缺陷或改进需求,本发明提供了一种视觉特征的模板匹配方法、装置、设备及存储介质,用于解决现有技术中传统算法在遭遇图像变形、遮挡时,需要进行大量的像素级灰度比较和相关性分析,这不仅增加了计算的复杂度,还降低了处理的速度,在实际应用中,往往只能计算一个角度,从而限制了其应用的广度和深度的问题

Benefits of technology

[0042]本发明提供的一种视觉特征的模板匹配方法,通过利用公共图像数据集对深层分类神经网络模型进行训练,改进神经网络结构以建立目标模板匹配模型,能捕捉图像中的细微差别和关键信息,从而提高模板匹配的精度,通过从目标模板图像数据集和待匹配图像中提取特征,能够处理多样化的图像输入,增强在实际应用中的泛化能力,能够学习到图像中更为泛化的特征,以模板图像特征为卷积核计算模板图像特征和待匹配图像特征的近似余弦相似度,能够显著提高匹配的计算效率,通过设置相似度阈值,该方法能够在匹配过程中自动筛选出与模板图像特征相似度较高的候选图像,最大池化操作能够保留局部区域中的最大相似度值,有助于抑制噪声和干扰信息对匹配结果的影响,从而降低了匹配错误率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119625357B_ABST
    Figure CN119625357B_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, device, and storage medium for template matching of visual features, relating to the field of template matching technology. The method includes: training a deep classification neural network model using a public image dataset and improving the neural network structure to build a target template matching model; extracting template image features and image features to be matched from a target template image dataset and an image to be matched using the target template matching model; calculating the approximate cosine similarity between the template image features and the image features to be matched using a simulated sliding window as a convolution kernel; and determining the template matching result from the approximate cosine similarity based on a max pooling operation and a similarity threshold method. This invention improves matching accuracy and computational efficiency, enhances generalization ability, and reduces the matching error rate by utilizing a deep classification neural network model for feature extraction and matching.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of template matching technology, and more specifically, to a method, apparatus, device, and storage medium for template matching of visual features. Background Technology

[0002] Template matching technology, as one of the cornerstones of image processing and computer vision, has a wide range of applications, covering key areas from target detection to face recognition, motion tracking, and remote sensing image analysis. The core of this technology lies in its ability to accurately locate the region most similar to a preset template within complex image data, thereby achieving precise capture of specific targets. In these diverse application scenarios, template matching technology demonstrates its irreplaceable value.

[0003] The Normalized Cross-Correlation (NCC) algorithm is a method for measuring the similarity between two sequences, widely used in image processing, pattern recognition, and signal processing. Images are acquired using a calibrated stereo camera, or by combining two monocular cameras into a stereo camera. The calibration aims to align the epipolar lines of the two frames horizontally, facilitating subsequent NCC operations. This includes removing image distortion and correcting the optical center position. The NCC algorithm is used for matching; the best match is the one with the highest correlation on the same horizontal line between the pixel being tested in the right view and the pixel being tested in the left view. The disparity 'd' is recorded, which is the difference between the horizontal direction of the pixel being tested and the horizontal direction of the matched pixel. Using the disparity map obtained from the matching results, a depth map with the left view as the reference frame is derived using similar triangles.

[0004] However, while traditional NCC algorithms demonstrate excellent stability and reliability in many scenarios, their performance is significantly limited when faced with complex challenges such as image deformation and occlusion. These algorithms often require extensive pixel-level grayscale comparisons and correlation analyses, which not only increases computational complexity but also reduces processing speed, making it difficult to meet the stringent real-time and efficiency requirements of industrial applications. Achieving rotation invariance typically requires multiple matching operations, which not only increases the computational burden but also fails to meet real-time requirements. In practical applications, traditional algorithms often only calculate one angle, thus limiting the breadth and depth of their applications. Summary of the Invention

[0005] To address at least one deficiency or improvement need in the prior art, the present invention provides a template matching method, apparatus, device, and storage medium for visual features. This addresses the problem that traditional algorithms in the prior art require a large number of pixel-level grayscale comparisons and correlation analyses when encountering image deformation or occlusion. This not only increases computational complexity but also reduces processing speed. In practical applications, it often only calculates one angle, thus limiting the breadth and depth of its application.

[0006] To achieve the above objectives, according to a first aspect of the present invention, a template matching method for visual features is provided, comprising:

[0007] We trained a deep classification neural network model using a public image dataset and improved the neural network structure to build a target template matching model.

[0008] The template image features and the image to be matched are extracted from the target template image dataset and the image to be matched using a target template matching model.

[0009] The simulated sliding window uses template image features as convolution kernels to calculate the approximate cosine similarity between template image features and features of the image to be matched;

[0010] Template matching results are determined from approximate cosine similarity using max pooling and a similarity thresholding method.

[0011] In one possible implementation, template image features and image features to be matched are extracted from the target template image dataset and the image to be matched using a target template matching model, including:

[0012] An initial template image dataset is created, and the initial template image dataset is preprocessed to obtain the target template image dataset;

[0013] The target template image dataset is input into the target template matching model to extract multiple template image features;

[0014] The image to be matched is input into the target template matching model to extract the features of the image to be matched.

[0015] In one possible implementation, an initial template image dataset is created, and the initial template image dataset is preprocessed to obtain the target template image dataset, including:

[0016] Multiple basic template images are cropped to obtain an initial template image dataset with preset shapes and sizes;

[0017] The initial template image dataset is rotated to obtain a multi-angle template image dataset;

[0018] The target template image dataset is obtained by performing various affine transformations on the multi-angle template image dataset.

[0019] In one possible implementation, a simulated sliding window uses template image features as a convolution kernel to calculate the approximate cosine similarity between the template image features and the features of the image to be matched, including:

[0020] An initial approximate cosine similarity calculation formula is established using template image features as convolution kernels and features of the image to be matched as local vectors.

[0021] The initial approximate cosine similarity calculation formula is approximated based on the features of the template image and the features of the image to be matched to obtain the target approximate cosine similarity calculation formula;

[0022] Based on the target approximate cosine similarity calculation formula, the approximate cosine similarity between the features of the image to be matched and the features of each template image is calculated respectively.

[0023] In one possible implementation, the initial approximate cosine similarity calculation formula is approximated based on the template image features and the features of the image to be matched to obtain the target approximate cosine similarity calculation formula, including:

[0024] The L2 norm of the features of the image to be matched in the initial approximate cosine similarity calculation formula is approximated to the L2 norm of the features of the template image to obtain the transitional approximate cosine similarity calculation formula.

[0025] The inner product of the unit vector of the template image features and the features of the image to be matched is used as the formula for calculating the approximate cosine similarity of the target.

[0026] In one possible implementation, the template matching result is determined from approximate cosine similarity based on max pooling and a similarity thresholding method, including:

[0027] Generate random numbers and then sum them up to approximate cosine similarity.

[0028] Local maxima are extracted from the superimposed approximate cosine similarity using max pooling operations;

[0029] The target template image that matches the image to be matched is determined based on the similarity threshold method and local maxima.

[0030] In one possible implementation, a target template image matching the image to be matched is determined based on a similarity thresholding method and local maxima, including:

[0031] Set a similarity matching threshold based on historical template matching data;

[0032] Iterate through all local maxima and identify the local maxima that exceed the similarity matching threshold;

[0033] The template image corresponding to the maximum value among the local maxima that exceed the similarity matching threshold is used as the target template image.

[0034] According to a second aspect of the present invention, a template matching device for visual features is also provided, comprising:

[0035] The model building module is configured to train a deep classification neural network model using a public image dataset and improve the neural network structure to build a target template matching model.

[0036] The feature extraction module is configured to extract template image features and matching image features from the target template image dataset and the image to be matched using a target template matching model.

[0037] The similarity calculation module is configured to simulate a sliding window to use template image features as convolution kernels to calculate the approximate cosine similarity between the template image features and the features of the image to be matched;

[0038] The template matching module is configured to determine the template matching result from approximate cosine similarity based on max pooling and a similarity thresholding method.

[0039] According to a third aspect of the present invention, a template matching device for visual features is also provided, comprising at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program that, when executed by the processing unit, causes the processing unit to perform the steps of the template matching method for visual features described above.

[0040] According to a fourth aspect of the invention, a storage medium is also provided, which stores a computer program executable by an access authentication device, which, when run on the access authentication device, causes the access authentication device to perform the steps of the template matching method for visual features described in any of the preceding claims.

[0041] In summary, compared with the prior art, the above-described technical solutions conceived by this invention can achieve the following beneficial effects:

[0042] This invention provides a template matching method for visual features. By training a deep classification neural network model using a public image dataset, the neural network structure is improved to establish a target template matching model. This method can capture subtle differences and key information in images, thereby improving the accuracy of template matching. By extracting features from the target template image dataset and the image to be matched, it can handle diverse image inputs, enhance the generalization ability in practical applications, and learn more generalized features in images. By using the template image features as the convolution kernel to calculate the approximate cosine similarity between the template image features and the features of the image to be matched, the computational efficiency of matching can be significantly improved. By setting a similarity threshold, this method can automatically filter out candidate images with high similarity to the template image features during the matching process. Max pooling operation can retain the maximum similarity value in local regions, which helps to suppress the influence of noise and interference information on the matching results, thereby reducing the matching error rate. Attached Figure Description

[0043] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments 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.

[0044] Figure 1 A flowchart illustrating an embodiment of the template matching method for visual features provided by the present invention;

[0045] Figure 2 This is a schematic diagram of the structure of an embodiment of the Resnet network provided by the present invention;

[0046] Figure 3 Provided by the present invention Figure 1 A schematic flowchart of an embodiment of step S102;

[0047] Figure 4 Provided by the present invention Figure 3 A schematic flowchart of an embodiment of step S301;

[0048] Figure 5 Provided by the present invention Figure 1 A schematic flowchart of an embodiment of step S103;

[0049] Figure 6 Provided by the present invention Figure 1 A flowchart illustrating an embodiment of step S104;

[0050] Figure 7 Provided by the present invention Figure 6 A schematic flowchart of an embodiment of step S603;

[0051] Figure 8 A schematic diagram of the structure of an embodiment of the template matching device for visual features provided by the present invention;

[0052] Figure 9 This is a schematic diagram of the structure of a template matching device for visual features provided in an embodiment of the present invention. Detailed Implementation

[0053] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.

[0054] The terms "first," "second," "third," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.

[0055] This invention provides a template matching method, apparatus, device, and storage medium for visual features, which will be described below.

[0056] Please see Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the template matching method for visual features provided by the present invention. In a specific embodiment of the present invention, a template matching method for visual features is disclosed, comprising:

[0057] S101. Train a deep classification neural network model using a public image dataset, and improve the neural network structure to build a target template matching model;

[0058] S102. Extract template image features and image features to be matched from the target template image dataset and the image to be matched using the target template matching model;

[0059] S103. The simulated sliding window uses the template image features as the convolution kernel to calculate the approximate cosine similarity between the template image features and the features of the image to be matched;

[0060] S104. Determine the template matching result from the approximate cosine similarity based on the max pooling operation and the similarity threshold method.

[0061] In the above embodiments, a deep classification neural network model is first trained using a large-scale public image dataset to ensure that the model can learn rich and discriminative features from the images. These features can include not only low-level information such as the basic shape and color of the image, but also higher-level semantic information, such as object categories and scene attributes. Through training, the model can gradually optimize its weight parameters, thereby extracting image features more accurately.

[0062] After training, the neural network structure is improved to build a model specifically for target template matching. Model improvements may include, but are not limited to, adjusting the number of network layers, changing the convolutional kernel size, and introducing new activation functions to better suit the requirements of the neural network model for template matching tasks. This results in a highly customized target template matching model capable of more effectively extracting and comparing image features.

[0063] Next, a target template matching model is used to extract image features from the target template image dataset and the images to be matched. These image features are represented as high-dimensional vectors, showing key information within the images. Since the target template matching model has been thoroughly trained, it can accurately capture subtle differences and key features in the images, providing strong support for the subsequent matching process.

[0064] After feature extraction, the template image features are used as the convolution kernel to calculate the approximate cosine similarity between the template image features and the features of the image to be matched. Approximate cosine similarity is a commonly used metric that measures the angle between two vectors, thus reflecting their degree of similarity. By calculating the approximate cosine similarity, a similarity matrix can be obtained, which contains the similarity information between various positions in the template image and the image to be matched.

[0065] Finally, template matching results are determined from approximate cosine similarity using max pooling and a similarity thresholding method. Max pooling preserves the maximum similarity value in local regions, thus suppressing the influence of noise and interference on the matching results. The similarity thresholding method filters matching results by setting a threshold; a match is considered successful only when the similarity exceeds the threshold, thereby ensuring the accuracy and reliability of the matching results.

[0066] In a specific embodiment of this invention, three classic classification networks—ResNet, EfficientNet, and RegNet—were compared in detail. Based on the similarities and differences of these networks, the impact of different operations in the network modules on the matching effect was analyzed in detail, and the optimization of the network was discussed. The following principles were followed when selecting the feature network layer: First, spatial semantic information must be preserved, therefore the portion after the average pooling layer in the classification network was excluded; second, the two-dimensional spatial scale should not be reduced too much compared to the original image to ensure sufficient resolution; finally, the feature network layer should avoid fusing channel attention modules and local feature smoothing operations. When the image is reduced by a factor of 32, matching errors are likely due to the low resolution. When the image is reduced by a factor of 16, the matching performance is acceptable, but the performance of each network varies. Specifically, ResNet performs well when reduced by a factor of 16, successfully matching all four similar targets. However, EfficientNet and RegNet both failed to match successfully when selecting the last network layer reduced by a factor of 16. Further comparison of these three networks reveals that ResNet lacks an attention module and local average pooling operation, EfficientNet includes an attention module, and RegNet includes both. Therefore, by removing the integrated attention module and local average pooling module, EfficientNet achieves a significant performance improvement, while RegNet, although showing some improvement, still suffers from matching errors. Thus, compared to the RegNet network structure, ResNet and EfficientNet are more suitable for modification into feature networks.

[0067] Please see Figure 2 , Figure 2 This is a schematic diagram of the structure of an embodiment of the ResNet network provided by the present invention. When constructing the feature network, ResNet is preferred, and a network layer size of 1 / 16 is determined as the basis for feature extraction. For example... Figure 2As shown, all layers in the conv4_x region meet the selection criteria. Given that deeper layers in deep neural networks often extract richer and more detailed features, this invention prioritizes the last layer (containing activation operations) in conv4_x to obtain optimal feature representation. Corresponding adjustments were made to various ResNet variants: ResNet-18 retained the first 13 layers to reconstruct an efficient feature extraction network; ResNet-34 retained the first 27 layers; ResNet-50 selected the first 40 layers; ResNet-101 retained the first 91 layers; and ResNet-152 retained the first 142 layers for feature extraction network reconstruction. The selection of EfficientNet and RegNet not only requires consideration of the network layer output scale multiple, but more importantly, careful removal of attention modules from corresponding layers is also necessary. To illustrate this more intuitively, EfficientNet-b2 and RegNet_y_800mf are used as examples for detailed explanation. In the efficientNet-b2 network architecture, the 5th block was chosen as the split point. Using the dashed line as the boundary, layers were split from the first layer to the dashed line, thus reconstructing a feature extraction network. It's worth noting that the attention module (SE module) in efficientNet is cleverly integrated into the network structure as a fully connected layer. To more comprehensively evaluate the impact of the SE module on network performance, removing the SE module significantly improves network performance compared to retaining it.

[0068] Compared with existing technologies, this embodiment provides a visual feature template matching method. By training a deep classification neural network model using a public image dataset and improving the neural network structure to establish a target template matching model, it can capture subtle differences and key information in images, thereby improving the accuracy of template matching. By extracting features from the target template image dataset and the image to be matched, it can handle diverse image inputs, enhance the generalization ability in practical applications, and learn more generalized features in images. By using the template image features as the convolution kernel to calculate the approximate cosine similarity between the template image features and the features of the image to be matched, it can significantly improve the computational efficiency of matching. By setting a similarity threshold, this method can automatically filter out candidate images with high similarity to the template image features during the matching process. Max pooling operation can retain the maximum similarity value in local regions, which helps to suppress the influence of noise and interference information on the matching results, thereby reducing the matching error rate.

[0069] Please see Figure 3 , Figure 3 Provided by the present invention Figure 1A flowchart illustrating an embodiment of step S102. In some embodiments of the present invention, template image features and image features to be matched are extracted from a target template image dataset and an image to be matched using a target template matching model, including:

[0070] S301. Establish an initial template image dataset and preprocess the initial template image dataset to obtain the target template image dataset;

[0071] S302. Input the target template image dataset into the target template matching model to extract multiple template image features;

[0072] S303. Input the image to be matched into the target template matching model to extract the features of the image to be matched.

[0073] In the above embodiments, firstly, a large number of images related to the target application are collected from various sources (such as public databases, on-site photography, etc.) to form an initial template image dataset. Then, the data is cleaned to remove duplicate, blurry, incomplete, or irrelevant images, ensuring data quality. Preprocessing may include, but is not limited to, resizing, color correction, noise removal, and contrast enhancement of the remaining images to standardize the image format and improve the accuracy of subsequent feature extraction. Furthermore, data augmentation techniques, such as rotation, scaling, and flipping, may be included to increase data diversity and improve the model's generalization ability. The preprocessed image set constitutes the target template image dataset.

[0074] Choose an appropriate template matching model based on specific application requirements. This can include ResNet, EfficientNet, and RegNet neural networks, or a combination of two. Input the preprocessed target template image dataset into the selected model. The model automatically learns and extracts multiple discriminative image features by analyzing information such as image texture, shape, and color. The extracted image features will be used in the subsequent matching process.

[0075] Similar preprocessing steps to those described above can be performed on the images to be matched to ensure consistency with the target template image dataset in terms of format and feature space. The preprocessed images to be matched are then input into the pre-trained target template matching model. The model will extract the key features of the images to be matched. These extracted features will be formatted to be suitable for comparison with the template image features, preparing for subsequent feature matching steps.

[0076] Please see Figure 4 , Figure 4 Provided by the present invention Figure 3A flowchart illustrating an embodiment of step S301 is provided. In some embodiments of the present invention, an initial template image dataset is established, and the initial template image dataset is preprocessed to obtain a target template image dataset, including:

[0077] S401. Cropping multiple basic template images yields an initial template image dataset with a preset shape and size;

[0078] S402. Rotate the initial template image dataset to obtain a multi-angle template image dataset;

[0079] S403. Perform various affine transformations on the multi-angle template image dataset to obtain the target template image dataset.

[0080] In the above embodiments, image processing software or programming tools are used to crop each basic template image according to actual application requirements, removing irrelevant background and redundant information, and retaining only the target area of ​​interest. The cropped image should have a uniform preset shape (such as square, circle, etc.) and preset size (such as 256x256 pixels, 128x128 pixels, etc.) to facilitate subsequent processing.

[0081] To enhance the diversity of template images and improve the matching algorithm's ability to recognize targets from different angles, a rotation transformation is applied to the initial template image dataset. The rotation transformation can be performed around the image center or any specified point, and the rotation angle can be set as needed, such as rotating every 15, 30, or 45 degrees, thereby generating template images from multiple angles. Through this rotation transformation, a dataset containing template images from multiple angles is obtained, which can more comprehensively reflect the appearance features of the target from different viewpoints.

[0082] Affine transformation is a two-dimensional coordinate transformation that includes operations such as translation, scaling, rotation (different from rotation transformation, it involves further adjustments based on an existing rotation), and tilting. Various types of affine transformations are applied to a multi-angle template image dataset to simulate the various deformations and viewpoint changes that targets may encounter in real-world applications. The parameters of the affine transformation (such as translation, scaling, and tilt angle) can be flexibly set according to the specific application requirements. By adjusting these parameters, a large number of template images with different deformations and viewpoint changes can be generated. After various affine transformations, a target template image dataset containing rich diversity and deformation information is obtained. This dataset will be used to train a template matching model or as a reference template library in the matching process to improve the matching algorithm's ability and robustness in recognizing targets under different conditions.

[0083] Please see Figure 5 , Figure 5 Provided by the present invention Figure 1A flowchart illustrating one embodiment of step S103. In some embodiments of the present invention, a simulated sliding window uses template image features as a convolution kernel to calculate the approximate cosine similarity between the template image features and the features to be matched, including:

[0084] S501. Establish an initial approximate cosine similarity calculation formula using template image features as convolution kernels and features of the image to be matched as local vectors.

[0085] S502. Based on the features of the template image and the features of the image to be matched, the initial approximate cosine similarity calculation formula is approximated to obtain the target approximate cosine similarity calculation formula.

[0086] S503. Based on the target approximate cosine similarity calculation formula, calculate the approximate cosine similarity between the features of the image to be matched and the features of each template image.

[0087] In the above embodiments, firstly, the template image features are treated as convolution kernels (or filters). These template image features are extracted using a deep learning model (such as a convolutional neural network) and possess high abstraction and representational power. Simultaneously, the features of the image to be matched are divided into multiple local vectors (or local feature blocks). These vectors are also obtained using the same deep learning model or other feature extraction methods. The division of local vectors can be determined based on the image size, feature density, and computational resource limitations. Based on the convolution kernel (template image features) and local vectors (features of the image to be matched), an initial approximate cosine similarity calculation formula is constructed. This formula typically involves dot product operations and magnitude calculations of vectors, used to measure the directional similarity between two vectors.

[0088] Directly applying the initial approximate cosine similarity calculation formula can lead to enormous computational costs, especially when processing high-resolution images or a large number of template images. Therefore, it is necessary to approximate the formula to reduce computational complexity. Approximation methods can include, but are not limited to: using low-rank approximation to reduce the dimensionality of feature vectors; utilizing Fast Fourier Transform (FFT) to accelerate dot product operations; or employing techniques such as random projection to approximate the magnitude and dot product of vectors. After approximation, a target approximate cosine similarity calculation formula is obtained, which significantly reduces computational complexity while maintaining computational accuracy.

[0089] For each feature in the image to be matched, the process iterates through each template image feature (i.e., each convolutional kernel) and calculates the approximate cosine similarity between them using the target approximate cosine similarity formula. During the calculation, the approximate cosine similarity between each template image feature and the feature in the image to be matched can be stored in a similarity matrix. Each row of this matrix represents a template image feature, and each column represents a local feature block or the feature vector of the entire image in the image to be matched (depending on the partitioning of the local vectors). Finally, the values ​​in the similarity matrix are analyzed to find the template image feature most similar to the feature in the image to be matched. This involves finding the maximum value in the matrix or the row / column index of the maximum value, thus determining the best matching result.

[0090] In some embodiments of the present invention, the initial approximate cosine similarity calculation formula is approximated based on the template image features and the features of the image to be matched to obtain the target approximate cosine similarity calculation formula, including:

[0091] The L2 norm of the features of the image to be matched in the initial approximate cosine similarity calculation formula is approximated to the L2 norm of the features of the template image to obtain the transitional approximate cosine similarity calculation formula.

[0092] The inner product of the unit vector of the template image features and the features of the image to be matched is used as the formula for calculating the approximate cosine similarity of the target.

[0093] In the above embodiments, approximate cosine similarity is adopted as the theoretical basis for measuring the similarity between vectors, as clearly shown in formula (1):

[0094]

[0095] Here, A and B both represent vectors. Within this formula framework, vector A corresponds to the convolution kernel (i.e., the template image features), while vector B (i.e., the image features to be matched) represents the local vector of the convolved tensor at the current window position. The symbol ||·|| denotes the L2 norm of the vector.<A,B> This represents the inner product operation of vectors. However, in actual convolution operations, the local calculation at each window position is essentially equivalent to the inner product operation of the corresponding local vectors. Since the L2 norm calculation of local variable B is difficult to process efficiently in batches or in parallel, when vectors A and B are highly similar, their L2 norms tend to be close. Based on this situation, the original formula (1) can be reasonably approximated to simplify the computational complexity:

[0096]

[0097] Specifically, the proposed new formula avoids repeatedly calculating the L2 norm of B each time the window slides by pre-calculating and storing the L2 norm of the convolution kernel A. This improvement gives the new formula (2) a significant advantage in computational efficiency compared to the original formula (1) because it simplifies and accelerates key computational steps. Furthermore, to deepen this optimization strategy, formula (2) is further refined to ensure that the convolution operation can more closely simulate the target approximate cosine similarity calculation process under the sliding window:

[0098]

[0099] These innovative adjustments not only improved the computational efficiency of the algorithm but also enhanced its practicality and scalability when processing large-scale data.

[0100] Please see Figure 6 , Figure 6 Provided by the present invention Figure 1 A flowchart illustrating an embodiment of step S104. In some embodiments of the present invention, the template matching result is determined from approximate cosine similarity based on max pooling and a similarity threshold method, including:

[0101] S601. Generate random numbers and superimpose them onto an approximate cosine similarity.

[0102] S602. Extract local maxima from the superimposed approximate cosine similarity using max pooling operation;

[0103] S603. Determine the target template image that matches the image to be matched based on the similarity threshold method and local maximum value.

[0104] In the above embodiments, to simulate noise and uncertainty that may exist in practical applications, a series of random numbers can be generated and superimposed on the calculated approximate cosine similarity. These random numbers can follow a normal distribution, a uniform distribution, or other suitable probability distribution. The generated random numbers are superimposed element-wise on the corresponding positions of the approximate cosine similarity matrix, thereby introducing small perturbations into the similarity matrix to simulate noise and interference that may be encountered in practical applications. By introducing random numbers, the matching process can be made more robust to small changes in similarity, reducing false matches caused by noise or changes in lighting.

[0105] Max pooling is a downsampling technique commonly used in convolutional neural networks. It reduces data dimensionality and redundancy by selecting the maximum value within a local region. In template matching tasks, max pooling can be applied to the superimposed approximate cosine similarity matrix to extract local maxima. The size of the local region can be determined based on the feature sizes of the template and target images, as well as computational resource constraints. Typically, the size of the local region should be large enough to cover possible matching areas, but not so large as to lose detail. Within the defined local region, the maximum approximate cosine similarity is selected as the representative value for that region. These local maxima will be used for subsequent matching decisions.

[0106] Based on the needs of the practical application and background knowledge, a similarity threshold is set. This threshold is used to distinguish between successful and unsuccessful matches. The similarity threshold should be high enough to exclude irrelevant template images, but not so high that potential matches are missed. The extracted local maxima are compared with the set similarity threshold. If a local maxima is greater than or equal to the threshold, the template image corresponding to that local region is considered to have successfully matched the image to be matched. Otherwise, the match is considered to have failed. In the successfully matched local regions, the template image with the highest similarity value is selected as the final target template image.

[0107] Please see Figure 7 , Figure 7 Provided by the present invention Figure 6 A flowchart illustrating an embodiment of step S603. In some embodiments of the present invention, determining a target template image matching the image to be matched based on a similarity threshold method and local maxima includes:

[0108] S701. Set the similarity matching threshold based on historical template matching data;

[0109] S702. Traverse all local maxima and determine the local maxima that exceed the similarity matching threshold;

[0110] S703. Use the template image corresponding to the maximum value among the local maximum values ​​that exceed the similarity matching threshold as the target template image.

[0111] In the above embodiments, firstly, historical template matching data is collected and analyzed. This data should include multiple pairs of template images and images to be matched that have been known to have matched successfully, as well as their similarity values. Additionally, it may include some known failed matching cases to understand the distribution of similarity under different circumstances. Based on historical data analysis, statistical methods (such as mean, median, standard deviation, etc.) can be used to set a similarity matching threshold. For example, a threshold higher than the similarity value of most failed matching cases but lower than the similarity value of most successful matching cases can be selected. Another approach is to use machine learning algorithms (such as support vector machines, decision trees, etc.) to train a classifier to automatically determine the optimal similarity threshold. In practical applications, the similarity matching threshold may need to be dynamically adjusted based on newly collected matching data. This can be achieved by periodically updating the historical database and recalculating the threshold.

[0112] In the previous steps, local maxima were extracted from the approximate cosine similarity matrix using max pooling. Now, these local maxima need to be iterated through to find those that exceed a similarity matching threshold. For each local maxima, it is compared with the set similarity matching threshold. If the local maxima is greater than or equal to the threshold, it is considered a potential match and retained for subsequent analysis. Otherwise, it is excluded from the matching results. During the filtering process, in addition to recording the local maxima exceeding the threshold, it is also necessary to record their corresponding template image index, location information, etc., to facilitate the subsequent determination of the target template image.

[0113] Among the local maxima exceeding the similarity matching threshold, the local maximum with the highest similarity value is selected. The local maximum represents the highest degree of similarity between the image to be matched and a certain template image. Based on the template image index or location information corresponding to the selected local maximum, the corresponding template image is retrieved from the template image database as the target template image. The target template image is the template image that best matches the image to be matched.

[0114] To better implement the template matching method for visual features in the embodiments of the present invention, based on the template matching method for visual features, please refer to the corresponding... Figure 8 , Figure 8 This is a schematic diagram of a structural embodiment of the template matching device for visual features provided by the present invention. The embodiment of the present invention provides a template matching device 800 for visual features, comprising:

[0115] The model building module 810 is configured to train a deep classification neural network model using a public image dataset and improve the neural network structure to build a target template matching model.

[0116] The feature extraction module 820 is configured to extract template image features and matching image features from the target template image dataset and the image to be matched using a target template matching model.

[0117] The similarity calculation module 830 is configured to simulate a sliding window to use template image features as convolution kernels to calculate the approximate cosine similarity between template image features and features of the image to be matched;

[0118] Template matching module 840 is configured to determine template matching results from approximate cosine similarity based on max pooling operation and similarity thresholding.

[0119] It should be noted that the device 800 provided in the above embodiments can implement the technical solutions described in the above method embodiments. The specific implementation principles of the above modules or units can be found in the corresponding content in the above method embodiments, and will not be repeated here.

[0120] Please see Figure 9 , Figure 9 This is a schematic diagram of the structure of a template matching device for visual features provided in an embodiment of the present invention. Based on the above-described template matching method for visual features, the present invention also provides a template matching device for visual features, which can be a computing device such as a mobile terminal, desktop computer, laptop, handheld computer, or server. The template matching device 900 for visual features includes a processor 910, a memory 920, and a display 930. Figure 9 Only some components of the template matching device for visual features are shown; however, it should be understood that implementation of all shown components is not required, and more or fewer components may be implemented instead.

[0121] In some embodiments, the memory 920 may be an internal storage unit of the visual feature template matching device 900, such as a hard disk or memory of the visual feature template matching device 900. In other embodiments, the memory 920 may be an external storage device of the visual feature template matching device 900, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the visual feature template matching device 900. Furthermore, the memory 920 may include both internal and external storage units of the visual feature template matching device 900. The memory 920 is used to store application software and various types of data installed on the visual feature template matching device 900, such as program code installed on the visual feature template matching device 900. The memory 920 may also be used to temporarily store data that has been output or will be output. In one embodiment, a template matching program 940 for visual features is stored in the memory 920. The template matching program 940 for visual features can be executed by the processor 910 to implement the template matching method for visual features in the embodiments of this application.

[0122] In some embodiments, processor 910 may be a central processing unit (CPU), a microprocessor, or other data processing chip, used to run program code stored in memory 920 or process data, such as performing template matching methods for visual features.

[0123] In some embodiments, display 930 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen. Display 930 is used to display information from the template matching device 900 for visual features and to display a visual user interface. Components 910-930 of the template matching device 900 for visual features communicate with each other via a system bus.

[0124] In one embodiment, the steps in the visual feature template matching method described above are implemented when the processor 910 executes the template matching program 940 for visual features in the memory 920.

[0125] This embodiment also provides a computer-readable storage medium storing a template matching program for visual features, which, when executed by a processor, performs the following steps:

[0126] We trained a deep classification neural network model using a public image dataset and improved the neural network structure to build a target template matching model.

[0127] The template image features and the image to be matched are extracted from the target template image dataset and the image to be matched using a target template matching model.

[0128] The simulated sliding window uses template image features as convolution kernels to calculate the approximate cosine similarity between template image features and features of the image to be matched;

[0129] Template matching results are determined from approximate cosine similarity using max pooling and a similarity thresholding method.

[0130] In summary, the visual feature template matching method provided by this invention trains a deep classification neural network model using a public image dataset, improves the neural network structure to establish a target template matching model, and can capture subtle differences and key information in images, thereby improving the accuracy of template matching. By extracting features from the target template image dataset and the image to be matched, it can handle diverse image inputs, enhance the generalization ability in practical applications, and learn more generalized features in images. By using the template image features as the convolution kernel to calculate the approximate cosine similarity between the template image features and the features of the image to be matched, it can significantly improve the computational efficiency of matching. By setting a similarity threshold, this method can automatically filter out candidate images with high similarity to the template image features during the matching process. Max pooling operation can retain the maximum similarity value in local regions, which helps to suppress the influence of noise and interference information on the matching results, thereby reducing the matching error rate.

[0131] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method. The computer-readable storage medium may include, but is not limited to, any type of disk, including floppy disks, optical disks, DVDs, CD-ROMs, microdrives, as well as magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic cards or optical cards, nanosystems (including molecular memory ICs), or any type of medium or device suitable for storing instructions and / or data.

[0132] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0133] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0134] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between devices or units may be electrical or other forms.

[0135] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0136] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0137] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0138] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.

[0139] The foregoing description is merely an exemplary embodiment of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Those skilled in the art will readily conceive of embodiments of this disclosure upon considering the specification and practicing the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described herein. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.

[0140] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0141] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A template matching method for visual features, characterized in that, include: We trained a deep classification neural network model using a public image dataset and improved the neural network structure to build a target template matching model. The target template matching model extracts template image features and image features to be matched from the target template image dataset and the image to be matched. The simulated sliding window uses the template image features as a convolution kernel to calculate the approximate cosine similarity between the template image features and the features of the image to be matched; including: An initial approximate cosine similarity calculation formula is established using the template image features as the convolution kernel and the image features to be matched as the local vector. The initial approximate cosine similarity calculation formula is approximated based on the template image features and the image features to be matched to obtain the target approximate cosine similarity calculation formula; including: By approximating the L2 norm of the features of the image to be matched in the initial approximate cosine similarity calculation formula to the L2 norm of the features of the template image, a transitional approximate cosine similarity calculation formula is obtained. Where A and B both represent vectors; Further refinement yields the formula for calculating the approximate cosine similarity of the target. Based on the target approximate cosine similarity calculation formula, the approximate cosine similarity between the feature of the image to be matched and each of the template image features is calculated respectively; Template matching results are determined from the approximate cosine similarity based on max pooling and a similarity thresholding method.

2. The template matching method for visual features as described in claim 1, characterized in that, The step of extracting template image features and matching image features from the target template image dataset and the image to be matched using the target template matching model includes: An initial template image dataset is established, and the target template image dataset is obtained by preprocessing the initial template image dataset. The target template image dataset is input into the target template matching model to extract multiple template image features; The image to be matched is input into the target template matching model to extract the features of the image to be matched.

3. The template matching method for visual features as described in claim 2, characterized in that, The process of establishing an initial template image dataset and preprocessing the initial template image dataset to obtain the target template image dataset includes: Multiple basic template images are cropped to obtain the initial template image dataset with a preset shape and preset size; The initial template image dataset is rotated and transformed to obtain a multi-angle template image dataset. The target template image dataset is obtained by performing various affine transformations on the multi-angle template image dataset.

4. The template matching method for visual features as described in claim 1, characterized in that, The step of determining the template matching result from the approximate cosine similarity based on the max pooling operation and the similarity threshold method includes: Generate random numbers and then superimpose these random numbers onto the approximate cosine similarity. The maximum value is extracted from the superimposed approximate cosine similarity using the max pooling operation; The target template image that matches the image to be matched is determined based on the similarity threshold method and the local maximum value.

5. The template matching method for visual features as described in claim 4, characterized in that, The step of determining the target template image that matches the image to be matched based on the similarity threshold method and the local maximum value includes: Set a similarity matching threshold based on historical template matching data; Iterate through all local maxima and determine the local maxima that exceed the similarity matching threshold; The template image corresponding to the maximum value among the local maximum values ​​that exceed the similarity matching threshold is used as the target template image.

6. A template matching device for visual features, characterized in that, include: The model building module is configured to train a deep classification neural network model using a public image dataset and improve the neural network structure to build a target template matching model. The feature extraction module is configured to extract template image features and image features to be matched from the target template image dataset and the image to be matched through the target template matching model. The similarity calculation module is configured to simulate a sliding window, using the template image features as a convolution kernel to calculate the approximate cosine similarity between the template image features and the features of the image to be matched; including: An initial approximate cosine similarity calculation formula is established using the template image features as the convolution kernel and the image features to be matched as the local vector. The initial approximate cosine similarity calculation formula is approximated based on the template image features and the image features to be matched to obtain the target approximate cosine similarity calculation formula; including: By approximating the L2 norm of the features of the image to be matched in the initial approximate cosine similarity calculation formula to the L2 norm of the features of the template image, a transitional approximate cosine similarity calculation formula is obtained. Where A and B both represent vectors; Further refinement yields the formula for calculating the approximate cosine similarity of the target. Based on the target approximate cosine similarity calculation formula, the approximate cosine similarity between the feature of the image to be matched and each of the template image features is calculated respectively; The template matching module is configured to determine the template matching result from the approximate cosine similarity based on the max pooling operation and the similarity threshold method.

7. A template matching device for visual features, characterized in that, It includes at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program that, when executed by the processing unit, causes the processing unit to perform the steps of the template matching method for visual features according to any one of claims 1 to 5.

8. A storage medium, characterized in that, It stores a computer program executable by an access authentication device, which, when run on the access authentication device, causes the access authentication device to perform the steps of the template matching method for the visual features according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Image retrieval method, device and equipment based on local matching and computer medium

    CN117874267A