Template matching method and device, electronic equipment and computer readable medium
By performing downsampling and feature pyramid matching on the input image, the problem of poor performance of existing template matching methods in complex scenes is solved, and efficient and accurate target detection is achieved.
Patent Information
- Application Number
- CN202411263026.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2025-01-21
AI Technical Summary
The existing template matching methods are not effective in complex scenarios such as lighting changes, viewing angle changes, and non-rigid deformations, making it difficult to take into account real-time and detection accuracy.
By downsampling the input image, the input feature pyramid is generated and matched with the template feature pyramid of the template image to obtain a similar feature set, thereby locating the target area in the input image.
It achieves rapid and accurate detection of target objects in complex scenarios such as illumination changes, viewing angle changes, and non-rigid deformation, meeting real-time requirements.
Smart Images

Figure CN119339115A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field, and in particular to a template matching method, device, electronic device and computer-readable medium. Background Art
[0002] Template matching is a common computer vision task, which generally detects areas in the input image that are similar to the template image based on a given template image. Currently, template matching methods are currently based on grayscale value template matching or feature-based template matching.
[0003] The template matching method based on grayscale value directly compares the "similarity" of a certain area in the input image with the template image in grayscale. The similarity is usually evaluated using "Normalized Cross Correlation" (NCC for short). The higher the similarity, the more similar the image area is to the template. This method can effectively find the target when the target to be found has a certain texture. By providing templates of different angles and sizes, this solution can also match targets of different angles and sizes. However, this method does not work well for smooth targets (without obvious textures), and the matching effect of this method is not good in scenes where the lighting changes significantly, the viewing angle changes, the object undergoes a certain degree of non-rigid deformation, and the object is blocked. When the lighting changes (especially nonlinear lighting changes), or the viewing angle changes, or non-rigid deformation occurs, the template matching method based on grayscale value will greatly increase the failure rate or even fail directly due to the large changes in the image pixel values.
[0004] In feature-based template matching methods, "feature" is a very broad concept, which describes some features of the target in the image, such as using the corner points and edge points of the image to replace the original complete image, or using the gradient image to replace the original image, or projecting the original image and replacing the original image with the projected image for matching, etc. Generally speaking, feature-based template matching methods can obtain a more essential description of the target and have stronger adaptability to environmental changes. Among them, some features also have the characteristics of "rotation invariance" or "scale invariance", making it easier to match targets with changing angles or scales. However, the current feature-based template matching schemes, such as SIFT, SURF, ORB, DOT, BBS, and DDIS, cannot always achieve both speed and matching effect, and most types of features still do not have good effects on scenes such as non-rigid deformation and occlusion. Most feature-based template matching methods have good resistance to illumination changes, but except for BBS and DDIS, most of them cannot handle perspective changes and non-rigid deformations well. In scenarios with high speed requirements, methods such as SIFT, BBS, and DDIS cannot meet real-time requirements.
[0005] Therefore, the existing template matching methods do not take into account both the real-time requirements and the detection in complex scenes (illumination changes, perspective changes, or non-rigid deformations). Summary of the invention
[0006] The content of this application is used to introduce concepts in a brief form, which will be described in detail in the detailed implementation section below. The content of this application is not intended to identify the key features or essential features of the technical solution claimed for protection, nor is it intended to limit the scope of the technical solution claimed for protection.
[0007] Some embodiments of the present application propose template matching methods, devices, electronic devices and computer-readable media to solve the technical problems mentioned in the above background technology section.
[0008] As a first aspect of the present application, some embodiments of the present application provide a template matching method, including:
[0009] In response to the acquired input image, downsampling the input image at least once to obtain an input layer feature matrix;
[0010] Generate input feature pyramids from all input layer feature matrices in the order of downsampling;
[0011] Matching the input feature pyramid with the template feature pyramid of the template image to obtain a similar feature set; the template feature pyramid is composed of a plurality of template layer feature matrices;
[0012] A target area of the similar feature set in the input image is obtained according to the corresponding relationship of the input feature pyramid.
[0013] Optionally, in response to the acquired input image, performing at least one downsampling process on the input image to obtain an input layer feature matrix comprises:
[0014] Dividing the input image into a plurality of image blocks of preset sizes;
[0015] Projecting each image block into a rotation-invariant and / or scale-invariant low-dimensional space to generate an input block feature matrix corresponding to each image block;
[0016] The input block feature matrices corresponding to each image block are combined into the input layer feature matrix.
[0017] Optionally, after combining the block feature matrices corresponding to the image blocks into an input layer feature matrix, the method further comprises:
[0018] Determine whether the size of the input image in the low-dimensional space is less than the size threshold;
[0019] If not, continue to divide the input image in the low-dimensional space into a number of image blocks of preset sizes, continue to project each image block into a rotationally invariant and / or scale-invariant low-dimensional space, and generate a block feature matrix corresponding to each image block.
[0020] Optionally, the size of the image block obtained by segmenting the input image is equal to the size of the image block obtained by segmenting the template image.
[0021] Optionally, the number of input-layer feature matrices in the input feature pyramid is equal to the number of template-layer feature matrices in the template feature pyramid.
[0022] Optionally, matching the input feature pyramid with a template feature pyramid of the template image to obtain a similar feature set includes:
[0023] Select a template block feature matrix from the template layer feature matrix at the top layer of the template feature pyramid;
[0024] Traverse the input layer feature matrix at the top of the input feature pyramid and select the input block feature matrix whose similarity exceeds the similarity threshold;
[0025] The input block feature matrices that meet the preset positional relationship and whose similarities exceed the similarity threshold constitute a similar feature set.
[0026] Optionally, obtaining a target area of the similar feature set in the input image according to the corresponding relationship of the input feature pyramid includes:
[0027] According to the corresponding relationship of the input feature pyramid, a matching area of the similar feature set in the next input layer feature matrix is obtained;
[0028] Determine whether the layer where the matching area is located is the original input image;
[0029] If not, continuing to perform the step of obtaining the matching region of the similar feature set in the feature matrix of the next input layer according to the matching region as the similar feature set;
[0030] If so, the matching area is used as the target area in the input image.
[0031] As a second aspect of the present application, some embodiments of the present application provide a template matching device, including:
[0032] A processing module, configured to, in response to the acquired input image, perform at least one downsampling process on the input image to obtain an input layer feature matrix;
[0033] The generation module is used to generate input feature pyramids from all input layer feature matrices in the order of downsampling;
[0034] A matching module, used for matching the input feature pyramid with the template feature pyramid of the template image to obtain a similar feature set; the template feature pyramid is composed of a plurality of template layer feature matrices;
[0035] The corresponding module is used to obtain the target area of the similar feature set in the input image according to the corresponding relationship of the input feature pyramid.
[0036] As the third aspect of the present application, some embodiments of the present application provide an electronic device, comprising: one or more processors; a storage device on which one or more programs are stored, and when the one or more programs are executed by one or more processors, the one or more processors implement the method described in any implementation manner of the above-mentioned first aspect.
[0037] As a fourth aspect of the present application, some embodiments of the present application provide a computer-readable medium on which a computer program is stored, wherein when the program is executed by a processor, the method described in any implementation of the above-mentioned first aspect is implemented.
[0038] The beneficial effects of the present application are: providing a template matching method, device, electronic device and computer-readable medium for obtaining a target area by downsampling and upsampling an input image and performing coarse-to-fine matching with a template image to take into account both real-time and complex environment detection.
[0039] More specifically, some embodiments of the present application may produce the following specific beneficial effects:
[0040] An input feature pyramid is obtained by downsampling the input image at least once, and the input feature pyramid and the template feature pyramid of the template image are matched to obtain a similar feature set, and then the target area of the similar feature set in the input image is obtained according to the corresponding relationship of the input feature pyramid, so as to achieve coarse-to-fine matching, reduce the amount of calculation required for template matching, and realize target detection in complex scenes such as illumination changes, viewing angle changes, or non-rigid deformations while meeting real-time requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The drawings constituting a part of this application are used to provide a further understanding of this application, so that other features, purposes and advantages of this application become more obvious. The illustrative embodiment drawings and their descriptions of this application are used to explain this application and do not constitute an improper limitation on this application.
[0042] In addition, throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the components and elements are not necessarily drawn to scale.
[0043] In the attached picture:
[0044] Figure 1 is a flow chart of the main steps of a template matching method according to an embodiment of the present application;
[0045] Figure 2 It is a schematic diagram of solving the layer feature matrix in the template matching method according to an embodiment of the present application;
[0046] Figure 3 is a schematic diagram of a downsampling process in a template matching method according to an embodiment of the present application;
[0047] Figure 4 is a schematic diagram of a template layer feature matrix of a template image in a template matching method according to an embodiment of the present application;
[0048] Figure 5 is a schematic diagram of an input layer feature matrix of an input image in a template matching method according to an embodiment of the present application;
[0049] Figure 6 is a schematic diagram of a similar feature set in an input layer feature matrix of an input image in a template matching method according to an embodiment of the present application;
[0050] Figure 7 is a schematic diagram of an upsampling process in a template matching method according to an embodiment of the present application;
[0051] Figure 8 is a structural block diagram of a template matching device according to an embodiment of the present application;
[0052] Fig. 9 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0053] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0054] It should also be noted that, for ease of description, only the parts related to the invention are shown in the drawings. In the absence of conflict, the embodiments and features in the embodiments of the present disclosure can be combined with each other.
[0055] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0056] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0057] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0058] The present disclosure will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.
[0059] like Figure 1 As shown, the present application discloses a template matching method, comprising the following main steps:
[0060] S110: In response to the acquired input image, downsampling the input image at least once to obtain an input layer feature matrix;
[0061] S120: Generate an input feature pyramid by downsampling all input layer feature matrices;
[0062] S130: Matching the input feature pyramid with the template feature pyramid of the template image to obtain a similar feature set; the template feature pyramid is composed of a plurality of template layer feature matrices;
[0063] S140: Obtaining a target region of the similar feature set in the input image according to the corresponding relationship of the input feature pyramid.
[0064] By adopting the above scheme, an input feature pyramid is obtained by downsampling the input image at least once, and the input feature pyramid and the template feature pyramid of the template image are matched to obtain a similar feature set, and then the target area of the similar feature set in the input image is obtained according to the correspondence of the input feature pyramid, so as to achieve coarse-to-fine matching, reduce the amount of calculation required for template matching, and realize target detection in complex scenes such as illumination changes, viewing angle changes, or non-rigid deformations while meeting real-time requirements.
[0065] It can be understood that the input image is subjected to the same downsampling operation as the template image, and the number of downsampling is also the same as the template image. For example, if the template image is downsampled twice, then the input image is also downsampled twice. To avoid repeated description, only the downsampling of the input image is described below.
[0066] In some embodiments, step S110 includes the following specific steps:
[0067] S111: dividing the input image into a number of image blocks of preset sizes;
[0068] For example, the input image may be equally divided into a number of 16*16 small blocks.
[0069] S112: Projecting each image block into a rotation-invariant and / or scale-invariant low-dimensional space to generate an input block feature matrix corresponding to each image block;
[0070] For example, Figure 2 As shown, first find the minimum circumscribed circle of each image block, then divide the circle into several circular rings of equal area, find the average value of the pixel values on each circular ring, and these average values are arranged in sequence to form the input block feature matrix corresponding to the image block. The input block feature matrix obtained in this way has rotation invariance.
[0071] S113: Combining the input block feature matrices corresponding to each image block into an input layer feature matrix.
[0072] It can be understood that the input layer feature matrix is composed of the input block feature matrices according to the arrangement of the image blocks.
[0073] In some embodiments, after step S113, the method further includes:
[0074] S114: Determine whether the size of the input image in the low-dimensional space is less than a size threshold;
[0075] S115: If not, continue to divide the input image in the low-dimensional space into a number of image blocks of preset sizes, continue to project each image block into a rotationally invariant and / or scale-invariant low-dimensional space, and generate a block feature matrix corresponding to each image block.
[0076] For example, Figure 3 As shown, when the template image is large, it can be downsampled, that is, the length and width are reduced by half (the area is reduced to 1 / 4);
[0077] Repeat the above steps until the input image reaches the specified size threshold (for example, 50*50 can be defined as the minimum allowed size, and no further downsampling is allowed after reaching this size); after multiple downsampling, an input feature pyramid consisting of input layer feature matrices at different scales can be formed.
[0078] In some embodiments, the size of the image block obtained by segmenting the input image is equal to the size of the image block obtained by segmenting the template image.
[0079] In some embodiments, the number of input-level feature matrices in the input feature pyramid is equal to the number of template-level feature matrices in the template feature pyramid.
[0080] In some embodiments, step S130 includes the following specific steps:
[0081] S131: Selecting a template block feature matrix from the template layer feature matrix at the top layer of the template feature pyramid;
[0082] S132: traverse the input layer feature matrix at the top layer of the input feature pyramid, and select the input block feature matrix whose similarity exceeds the similarity threshold;
[0083] S133: The input block feature matrices that meet the preset position relationship and whose similarity exceeds the similarity threshold constitute a similar feature set.
[0084] Exemplarily, for each template block feature matrix in the top layer of the template feature pyramid (i.e., the set of feature vectors corresponding to the template image with the smallest scale), find the position (possibly more than one position) where the similarity exceeds the similarity threshold in the top layer of the input feature pyramid; the similarity can be calculated using cosine similarity; the higher the similarity, the closer the two matrices are.
[0085] like Figure 4As shown, Figure 4 is the template layer feature matrix at the top of the template feature pyramid. Each grid represents a template block feature matrix, and each color represents a different vector value. Figure 5 As shown, Figure 5 For each template block feature matrix, the position that can be matched in the input layer feature matrix at the top layer of the input feature pyramid (that is, the position where the similarity exceeds the threshold); it should be noted that for a feature vector in the template, multiple positions where the similarity exceeds the threshold may be found in the input image.
[0086] In some embodiments, step S133 includes the following specific steps:
[0087] S133a: Acquire input block feature matrices that are located in a preset area and match the relative positions of the template block feature matrices in the template layer feature matrix at the top layer of the template feature pyramid, and define these input block feature matrices as pre-selected block feature matrices;
[0088] S133b: adding the similarities of all pre-selected block feature matrices and dividing the sum by the number of template block feature matrices in the template layer feature matrix at the top layer of the template feature pyramid to obtain a similarity position parameter;
[0089] S133c: Determine whether the similarity position parameter is greater than a preset similarity position threshold;
[0090] S133d: If so, the input block feature matrices whose similarity in the preset area exceeds the similarity threshold constitute a similar feature set.
[0091] If not, reselect the preset area and return to step S133a.
[0092] Specifically, the value range of the preset similarity position threshold may be 0 to 1. The preset area may be a framed area that matches the template layer feature matrix at the top layer of the template feature pyramid of the target object.
[0093] By adopting such a scheme, on the basis that the similarity of the input block feature matrices meets the conditions, the input block feature matrices are further screened based on their relative positions to ensure that the selected input block feature matrix matches the input layer feature matrix in the template, thereby improving the accuracy of the similar feature set.
[0094] like Figure 6As shown in the figure, in the area circled by the dotted box, the relative position relationship between the feature matrices of each input block is closest to the feature matrix of the template layer; in other words, in the area circled by the dotted box, the neighbor relationship between the feature matrices of the input blocks is most consistent with the feature matrix of the template layer; therefore, this area can be regarded as an area that can match the entire template image; the area found in this way is the area where the target object is located.
[0095] In some embodiments, step S140 includes the following specific steps:
[0096] S141: Obtaining a matching region of the similar feature set in a next-layer input layer feature matrix according to the corresponding relationship of the input feature pyramid;
[0097] S142: Determine whether the layer where the matching area is located is the original input image;
[0098] S143: If not, continue to perform the step of obtaining the matching region of the similar feature set in the feature matrix of the next input layer according to the matching region as the similar feature set;
[0099] S144: If yes, use the matching area as the target area in the input image.
[0100] For example, Figure 7 As shown, according to the matching results of the previous layer, the search range of the target object in the current layer can be limited, so there is no need to search in the entire upsampled image, but only to search near the area found in the previous layer, which can greatly reduce the amount of calculation required for template matching.
[0101] like Figure 8 As shown, the present application also discloses a template matching device, comprising:
[0102] A processing module, configured to, in response to the acquired input image, perform at least one downsampling process on the input image to obtain an input layer feature matrix;
[0103] The generation module is used to generate input feature pyramids from all input layer feature matrices in the order of downsampling;
[0104] A matching module, used for matching the input feature pyramid with the template feature pyramid of the template image to obtain a similar feature set; the template feature pyramid is composed of a plurality of template layer feature matrices;
[0105] The corresponding module is used to obtain the target area of the similar feature set in the input image according to the corresponding relationship of the input feature pyramid.
[0106] like Fig. 9As shown, the electronic device 800 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage device 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 800 are also stored. The processing device 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0107] Typically, the following devices may be connected to the I / O interface 805: input devices 806 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 807 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 808 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 809. The communication device 809 may allow the electronic device 800 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 8 The electronic device 800 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Figure 8 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0108] In particular, according to some embodiments of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, some embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In some such embodiments, the computer program can be downloaded and installed from the network through the communication device 809, or installed from the storage device 808, or installed from the ROM 802. When the computer program is executed by the processing device 801, the above-mentioned functions defined in the method of some embodiments of the present disclosure are executed.
[0109] It should be noted that the computer-readable medium described above in some embodiments of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0110] In some embodiments of the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device, or device. In some embodiments of the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction execution system, device, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0111] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperTextTransferProtocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an adhoc peer-to-peer network), as well as any currently known or future developed network.
[0112] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device. The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: in response to the acquired input image, downsamples the input image at least once to obtain an input layer feature matrix; generates an input feature pyramid from all input layer feature matrices in the order of downsampling; matches the input feature pyramid with the template feature pyramid of the template image to obtain a similar feature set; the template feature pyramid is composed of several template layer feature matrices; and obtains the target area of the similar feature set in the input image according to the corresponding relationship of the input feature pyramid.
[0113] Computer program code for performing the operations of some embodiments of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0114] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a part of a code, which contains one or more executable instructions for implementing a specified logical function.
[0115] It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures.
[0116] For example, two boxes shown in succession may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of boxes in the block diagram and / or flow chart, can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0117] The units described in some embodiments of the present disclosure may be implemented by software or by hardware. The described units may also be arranged in a processor, for example, may be described as: a processor includes a processing module, a generation module, a matching module and a corresponding module. Among them, the names of these units do not constitute a limitation on the units themselves under certain circumstances. For example, the processing module may also be described as "a unit for performing at least one downsampling process on the input image in response to the acquired input image to obtain an input layer feature matrix".
[0118] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0119] The above descriptions are only some preferred embodiments of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the embodiments of the present disclosure (but not limited to) and the technical solutions formed.
Claims
1. A template matching method, comprising: In response to the acquired input image, downsampling the input image at least once to obtain an input layer feature matrix; Generate input feature pyramids from all input layer feature matrices in the order of downsampling; Matching the input feature pyramid with the template feature pyramid of the template image to obtain a similar feature set; the template feature pyramid is composed of a plurality of template layer feature matrices; A target area of the similar feature set in the input image is obtained according to the corresponding relationship of the input feature pyramid.
2. The template matching method according to claim 1, characterized in that: In response to the acquired input image, performing at least one downsampling process on the input image to obtain an input layer feature matrix, comprising: Dividing the input image into a plurality of image blocks of preset sizes; Projecting each image block into a rotation-invariant and / or scale-invariant low-dimensional space to generate an input block feature matrix corresponding to each image block; The input block feature matrices corresponding to each image block are combined into the input layer feature matrix.
3. The template matching method according to claim 2, characterized in that: After combining the block feature matrices corresponding to the image blocks into an input layer feature matrix, the method further includes: Determine whether the size of the input image in the low-dimensional space is less than the size threshold; If not, continue to divide the input image in the low-dimensional space into several image blocks of preset sizes, continue to project each image block into the rotation-invariant and / or scale-invariant low-dimensional space, and generate a block feature matrix corresponding to each image block.
4. The template matching method according to claim 2, characterized in that: The size of the image block obtained by segmenting the input image is equal to the size of the image block obtained by segmenting the template image.
5. The template matching method according to claim 1, characterized in that: The number of input-layer feature matrices in the input feature pyramid is equal to the number of template-layer feature matrices in the template feature pyramid.
6. The template matching method according to claim 2, characterized in that: The step of matching the input feature pyramid with the template feature pyramid of the template image to obtain a similar feature set includes: Select a template block feature matrix from the template layer feature matrix at the top layer of the template feature pyramid; Traverse the input layer feature matrix at the top of the input feature pyramid and select the input block feature matrix whose similarity exceeds the similarity threshold; The input block feature matrices that meet the preset positional relationship and whose similarities exceed the similarity threshold constitute a similar feature set.
7. The template matching method according to claim 1, characterized in that: The step of obtaining a target area of the similar feature set in the input image according to the corresponding relationship of the input feature pyramid includes: According to the corresponding relationship of the input feature pyramid, a matching area of the similar feature set in the next input layer feature matrix is obtained; Determine whether the layer where the matching area is located is the original input image; If not, continuing to perform the step of obtaining the matching region of the similar feature set in the feature matrix of the next input layer according to the matching region as the similar feature set; If so, the matching area is used as the target area in the input image.
8. A template matching device, comprising: A processing module, configured to, in response to the acquired input image, perform at least one downsampling process on the input image to obtain an input layer feature matrix; The generation module is used to generate input feature pyramids from all input layer feature matrices in the order of downsampling; A matching module, used for matching the input feature pyramid with the template feature pyramid of the template image to obtain a similar feature set; the template feature pyramid is composed of a plurality of template layer feature matrices; The corresponding module is used to obtain the target area of the similar feature set in the input image according to the corresponding relationship of the input feature pyramid.
9. An electronic device, comprising: one or more processors; a storage device having one or more programs stored thereon; When the one or more programs are executed by the one or more processors, the processors implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, wherein: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.