Image matching method and device, electronic equipment and storage medium
By using adaptive windows in the image matching algorithm and gradually increasing the image resolution, the problem of mismatching in the image matching algorithm when the target object is partially occluded is solved, and the matching accuracy and real-time performance are improved.
Patent Information
- Application Number
- CN202410771103.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-09-03
AI Technical Summary
The grayscale-based image matching algorithm searches the entire area of the image to be searched, which may cause matching errors when the target object is partially obscured, and the tracking target is lost. How to improve the accuracy of image matching is an urgent problem that needs to be solved.
By obtaining the initial template image and the initial image to be searched, preprocessing is performed to form the template image set and the image set to be searched, and the adaptive window is used for search, which gradually improves the resolution and search accuracy of the image, reduces interference factors, and avoids mismatching.
It effectively improves the accuracy of image matching, avoids mismatching when the target object is partially blocked, and improves the matching accuracy and real-time performance.
Smart Images

Figure CN118587459A
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image matching method, device, electronic device and storage medium. Background Art
[0002] With the continuous development of computer vision, image matching algorithms are applied to more and more image matching scenarios. Among them, the grayscale-based image matching algorithm is a commonly used image matching algorithm. It searches for a sub-image that is identical or close to the template image in the image to be searched based on a known image template, and calculates the mutual correlation coefficient between the template image and the searched sub-image, and determines the position of the sub-image with the largest mutual correlation value as the position of the best matching point.
[0003] However, image matching based on the above method requires searching within the entire area of the image to be searched and calculating the correlation coefficient. However, if the target object in the image to be searched is partially occluded, matching errors may occur, resulting in the loss of the tracking target. Therefore, how to improve the accuracy of image matching is an urgent problem to be solved. Summary of the invention
[0004] In view of this, the present application provides an image matching method, device, electronic device and storage medium to improve the accuracy of image matching.
[0005] In order to achieve the above purpose, the embodiments of the present application provide the following technical solutions:
[0006] In a first aspect, an embodiment of the present application provides an image matching method, the method comprising:
[0007] Acquire an initial template image and an initial image to be searched, wherein the initial template image is an image window of a target object, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image;
[0008] Preprocessing the initial template image and the initial image to be searched respectively to obtain a template image set and a set of images to be searched, wherein the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image; wherein the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and among the K images to be searched, the Nth image to be searched is an image obtained by averaging a preset number of pixels in the N-1th image to be searched, and both K and N are integers greater than or equal to 1, and N≤K;
[0009] Using the Kth template image to search in the Kth image to be searched, obtaining the target image region in the Kth image to be searched that has the greatest similarity with the Kth template image, using the image region corresponding to the target image region in the K-1th image to be searched as the candidate image region of the K-1th image to be searched, using the K-1th template image to search in the candidate image region of the K-1th image to be searched, obtaining the target image region in the K-1th image to be searched that has the greatest similarity with the K-1th template image, and gradually obtaining the target image region of the first image to be searched;
[0010] The target image region of the first image to be searched is determined as a matching position of the target object in the initial image to be searched.
[0011] As an optional implementation of the embodiment of the present application, the obtaining of the initial template image and the initial image to be searched includes:
[0012] Determine a current frame image, and determine an image window corresponding to the target object in a frame image before the current frame image as an initial template image;
[0013] Predicting a target position where the target object appears in the current frame image;
[0014] An adaptive window is determined with the target position as the center, and the adaptive window is used as the initial image to be searched. The size of the adaptive window is smaller than the size of the current frame image.
[0015] As an optional implementation of the embodiment of the present application, the initial template image and the initial image to be searched are preprocessed respectively to obtain a template image set and a set of images to be searched, including:
[0016] For the initial template image, average every m*m pixels as one pixel to obtain a second template image. In the second template image, average every m*m pixels as one pixel to obtain a third template image. Perform pixel averaging processing step by step until the Kth template image is obtained. The K template images constitute a template image set.
[0017] For the initial image to be searched, every m*m pixels are averaged as one pixel to obtain the second image to be searched. In the second image to be searched, every m*m pixels are averaged as one pixel to obtain the third image to be searched. Pixel averaging processing is performed step by step until the Kth image to be searched is obtained. The K images to be searched constitute the template image set.
[0018] As an optional implementation of the embodiment of the present application, the step of searching in the Kth image to be searched using the Kth template image to obtain a target image region in the Kth image to be searched having the greatest similarity to the Kth template image includes:
[0019] Using the K-th template image to traverse and search in the K-th image to be searched, to obtain a plurality of image windows matching the K-th template image;
[0020] The similarity between each image window and the K-th template image is calculated, and the image window with the greatest similarity is determined as the target image region of the K-th image to be searched.
[0021] As an optional implementation of the embodiment of the present application, determining an adaptive window with the target position as the center and using the adaptive window as the initial image to be searched includes:
[0022] Taking the image window corresponding to the target position as the center window, determining eight neighborhood windows of the center window;
[0023] The central window and eight neighboring windows of the central window are used as adaptive windows.
[0024] As an optional implementation of the embodiment of the present application, the value of m is 2;
[0025] The method of averaging each m*m pixels into one pixel for the initial template image to obtain a second template image includes:
[0026] For the initial template image, average every 2*2 pixels into one pixel to obtain the second template image;
[0027] The method of averaging each m*m pixels into one pixel for the initial image to be searched to obtain a second image to be searched includes:
[0028] For the initial image to be searched, every 2*2 pixels are averaged into one pixel to obtain the second image to be searched.
[0029] As an optional implementation of the embodiment of the present application, predicting a target position where the target object appears in the current frame image includes:
[0030] A Kalman filter algorithm is used to predict the target position where the target object appears in the current frame image.
[0031] In a second aspect, an embodiment of the present application provides an image matching device, including:
[0032] An acquisition module, used for acquiring an initial template image and an initial image to be searched, wherein the initial template image is an image window of a target object, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image;
[0033] A processing module, used for preprocessing the initial template image and the initial image to be searched respectively to obtain a template image set and a set of images to be searched, wherein the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image; wherein the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and among the K images to be searched, the Nth image to be searched is an image obtained by averaging a preset number of pixels in the N-1th image to be searched, and both K and N are integers greater than or equal to 1, and N≤K;
[0034] a matching module, configured to use the Kth template image to search in the Kth image to be searched, obtain a target image region in the Kth image to be searched that has the greatest similarity with the Kth template image, use an image region corresponding to the target image region in the K-1th image to be searched as a candidate image region of the K-1th image to be searched, use the K-1th template image to search in the candidate image region of the K-1th image to be searched, obtain a target image region in the K-1th image to be searched that has the greatest similarity with the K-1th template image, and gradually obtain the target image region of the first image to be searched;
[0035] A determination module is used to determine that the target image area of the first image to be searched is the matching position of the target object in the initial image to be searched.
[0036] As an optional implementation of the embodiment of the present application, the acquisition module is specifically used to determine the current frame image, and determine the image window corresponding to the target object in the frame image before the current frame image as the initial template image;
[0037] Predicting a target position where the target object appears in the current frame image;
[0038] An adaptive window is determined with the target position as the center, and the adaptive window is used as the initial image to be searched. The size of the adaptive window is smaller than the size of the current frame image.
[0039] As an optional implementation of the embodiment of the present application, the processing module is specifically used to average every m*m pixels into one pixel for the initial template image to obtain a second template image, and in the second template image, average every m*m pixels into one pixel to obtain a third template image, and gradually perform pixel averaging processing until the Kth template image is obtained, and the K template images constitute a template image set;
[0040] For the initial image to be searched, every m*m pixels are averaged as one pixel to obtain the second image to be searched. In the second image to be searched, every m*m pixels are averaged as one pixel to obtain the third image to be searched. Pixel averaging processing is performed step by step until the Kth image to be searched is obtained. The K images to be searched constitute the template image set.
[0041] As an optional implementation of the embodiment of the present application, the matching module is specifically used to use the K-th template image to traverse and search in the K-th image to be searched, and obtain multiple image windows that match the K-th template image;
[0042] The similarity between each image window and the K-th template image is calculated, and the image window with the greatest similarity is determined as the target image region of the K-th image to be searched.
[0043] As an optional implementation of the embodiment of the present application, the acquisition module is specifically used to determine eight neighborhood windows of the center window with the image window corresponding to the target position as the center window;
[0044] The central window and eight neighboring windows of the central window are used as adaptive windows.
[0045] As an optional implementation of the embodiment of the present application, m is set to 2; the processing module is specifically used to average every 2*2 pixels into one pixel for the initial template image to obtain a second template image;
[0046] For the initial image to be searched, every 2*2 pixels are averaged into one pixel to obtain the second image to be searched.
[0047] As an optional implementation of the embodiment of the present application, the acquisition module is specifically used to predict the target position of the target object in the current frame image by using a Kalman filter algorithm.
[0048] In a third aspect, an embodiment of the present application provides an electronic device comprising: a memory and a processor, the memory being used to store a computer program; the processor being used to execute the steps of the image matching method described in the first aspect or any optional implementation of the first aspect when calling the computer program.
[0049] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the image matching method described in the first aspect or any optional implementation manner of the first aspect.
[0050] The image matching method, device, electronic device and storage medium provided by the embodiments of the present application include: obtaining an initial template image and an initial image to be searched, wherein the initial template image is an image window of a target object, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image; preprocessing the initial template image and the initial image to be searched respectively to obtain a template image set and a set of images to be searched, wherein the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image; wherein the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and among the K images to be searched, the Nth image to be searched The method comprises the following steps: obtaining an image by averaging a preset number of pixels in the N-1th image to be searched, wherein K and N are integers greater than or equal to 1, and N≤K; searching in the Kth image to be searched using the Kth template image to obtain a target image region in the Kth image to be searched having the greatest similarity with the Kth template image, taking an image region corresponding to the target image region in the K-1th image to be searched as a candidate image region of the K-1th image to be searched, searching in the candidate image region of the K-1th image to be searched using the K-1th template image to obtain a target image region in the K-1th image to be searched having the greatest similarity with the K-1th template image, and gradually obtaining a target image region of the first image to be searched; and determining the target image region of the first image to be searched as a matching position of the target object in the initial image to be searched. In the embodiment of the present application, since the initial image to be searched is an adaptive window centered on the image window of the target object, the size of the adaptive window is larger than the size of the initial template image, that is, the matching in the embodiment of the present application is performed in the adaptive window rather than the entire image area. Therefore, not only the amount of data to be processed is reduced, but also other interference factors outside the adaptive window are reduced, which can effectively avoid mismatching of the target object when it is partially obscured, thereby improving the matching accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0052] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0053] Figure 1 A flowchart of the steps of an image matching method provided in one embodiment of the present application;
[0054] Figure 2 A schematic diagram of an adaptive window provided for one embodiment of the present application;
[0055] Figure 3 This is a structural block diagram of an image matching device in one embodiment of the present application;
[0056] Figure 4 This is a diagram of the internal structure of an electronic device in one embodiment of the present application. DETAILED DESCRIPTION
[0057] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0058] In the following description, many specific details are set forth to facilitate a full understanding of the present application, but the present application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only part of the embodiments of the present application, rather than all of the embodiments.
[0059] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way. In addition, in the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" refers to two or more.
[0060] The execution subject of the image matching method provided in the embodiment of the present application may be a terminal device. The terminal device may be a computer device, a mobile phone, a tablet computer, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a smart watch, a smart bracelet, or other terminal devices, or the terminal device may also be other types of terminal devices, and the embodiment of the present application does not limit the type of the terminal device.
[0061] The image matching method provided in the embodiment of the present application can be applied to the scenario of tracking the target object in a video. In this scenario, the normalized cross-correlation template matching algorithm is often used. The algorithm has the characteristics of strong anti-noise ability and high matching accuracy. It is a process of searching for a sub-image that is the same or close to the template image in the image to be searched based on a known image template. The template image can be regarded as a known small image. Template matching is to search for targets of the same size in one or more images. The template image is used as the source input, and the next frame image is traversed and searched from left to right and from top to bottom. The cross-correlation coefficient between the template image and the searched sub-image is calculated, and the position of the sub-image with the largest cross-correlation value is determined as the position of the best matching point.
[0062] However, in the process of template matching, it is necessary to search within the entire area of the image to be searched based on the template image and calculate the correlation coefficient. The operation of its search strategy is highly complex, so it has certain limitations for matching problems with high real-time requirements. In addition, during the tracking process, if the target object is partially obscured, matching errors may occur and the tracking target may be lost.
[0063] Based on this, the present application proposes an image matching method for improving the accuracy of image matching and avoiding the problem of matching errors and thus losing the tracking target when the target object is partially occluded.
[0064] The image matching method provided in this application is exemplified below through several specific embodiments.
[0065] Figure 1 A flowchart of an image matching method provided in one embodiment of the present application, referring to Figure 1 As shown, the following steps S11-S14 are included.
[0066] S11, obtaining an initial template image and an initial image to be searched.
[0067] The initial template image is an image window of the target object, the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image. The initial image to be searched is an image processed from the original image to be searched.
[0068] Exemplarily, if person A in an image is to be tracked, person A is determined as the target object. If the original image to be searched is the current frame image, the image window corresponding to person A in the previous frame image of the current frame image is the initial template image. The current frame image is processed, and the adaptive window including the target object is selected as the initial image to be searched.
[0069] In some embodiments, a current frame image is determined, and an image window corresponding to a target object is determined in a frame image previous to the current frame image as an initial template image; a target position where the target object appears in the current frame image is predicted; an adaptive window is determined with the target position as the center, and the adaptive window is used as the initial image to be searched.
[0070] Among them, when predicting the target position where the target object appears in the current frame image, a Kalman filter algorithm can be used to predict the target position where the target object appears in the current frame image, which will not be described in detail here.
[0071] In some embodiments, an adaptive window in the original image to be searched may be determined as the initial image to be searched based on the following method: taking the image window corresponding to the target position as the center window, determining the eight-neighborhood window of the center window; and taking the center window and the eight-neighborhood window of the center window as adaptive windows.
[0072] For example, refer to Figure 2 As shown, 21 is the center window corresponding to the target object, and eight neighborhood windows of the center window 21 are determined. The size of each neighborhood window is the same as that of the center window. The center window 21 and the eight neighborhood windows constitute an adaptive window 22, and the size of the adaptive window 22 is smaller than the size of the original image 20 to be searched.
[0073] In the embodiment of the present application, the position of the target object in the current frame image is predicted to determine the adaptive window so that the target object is included in the adaptive window. In this way, when the target object is partially obscured, mismatching can be effectively avoided.
[0074] S12. Preprocess the initial template image and the initial image to be searched respectively to obtain a template image set and a set of images to be searched, so that the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image.
[0075] Among them, the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and among the K images to be searched, the Nth image to be searched is an image obtained by averaging a preset number of pixels in the N-1th image to be searched, K and N are both integers greater than or equal to 1, and N≤K.
[0076] The first template image to the Kth template image described in the embodiments of the present application are used to refer to the order of template images, and the first image to be searched to the Kth image to be searched are used to refer to the order of images to be searched. From the first template image to the Kth template image, the resolution of the template image decreases successively, and from the first image to be searched to the Kth image to be searched, the resolution of the images to be searched decreases successively. The Nth template image can refer to any template image among the K template images, and the Nth image to be searched can refer to any image to be searched among the K images to be searched.
[0077] Exemplarily, for the initial template image, the initial template image is used as the first template image, and every m*m pixels are averaged as one pixel to obtain a second template image. In the second template image, every m*m pixels are averaged as one pixel to obtain a third template image, and pixel averaging processing is gradually performed until the Kth template image is obtained, and the K template images constitute a template image set.
[0078] Exemplarily, the value of m can be 2, then the initial template image is used as the first template image, and every 2*2=4 pixels are averaged as one pixel to obtain the second template image. In the second template image, every 2*2=4 pixels are averaged as one pixel to obtain the third template image. The third template image is processed in the same way to obtain the fourth template image... That is, the template image obtained last time is processed in the same way until the Kth template image is obtained, and the K template images constitute a template image set.
[0079] For the initial image to be searched, every m*m pixels are averaged as one pixel to obtain the second image to be searched. In the second image to be searched, every m*m pixels are averaged as one pixel to obtain the third image to be searched. Pixel averaging processing is performed step by step until the Kth image to be searched is obtained. The K images to be searched constitute the template image set.
[0080] When the value of m is 2, for the initial image to be searched, the initial image to be searched is taken as the first image to be searched, and every 2*2=4 pixels are averaged as one pixel to obtain the second image to be searched. In the second image to be searched, every 2*2=4 pixels are averaged as one pixel to obtain the third image to be searched. The third image to be searched is processed in the same way to obtain the fourth image to be searched… That is, the image to be searched obtained last time is processed in the same way until the Kth image to be searched is obtained, and the K images to be searched constitute the image set to be searched.
[0081] That is, the initial template image is processed K-1 times to obtain K template images, and the initial image to be searched is processed K-1 times to obtain K images to be searched.
[0082] Among them, m can also be other values, which will not be given as examples in the embodiments of the present application.
[0083] S13, using the Kth template image to search in the Kth image to be searched, obtaining the target image region in the Kth image to be searched that has the greatest similarity with the Kth template image, using the image region corresponding to the target image region in the K-1th image to be searched as the candidate image region of the K-1th image to be searched, using the K-1th template image to search in the candidate image region of the K-1th image to be searched, obtaining the target image region in the K-1th image to be searched that has the greatest similarity with the K-1th template image, and gradually obtaining the target image region of the first image to be searched;
[0084] Exemplarily, the K-th template image is used to traverse and search in the K-th image to be searched, and multiple image windows matching the K-th template image are obtained; the similarity between each image window and the K-th template image is calculated, and the image window with the largest similarity is determined as the target image area of the K-th image to be searched; the image area corresponding to the target image area of the K-th image to be searched in the K-1th image to be searched is used as the candidate image area of the K-1th image to be searched, and the K-1th template image is used to traverse and search in the candidate image area of the K-1th image to be searched, and multiple image windows matching the K-1th template image are obtained; the similarity between each image window and the K-1th template image is calculated, and the image window with the largest similarity is determined as the K-1th image to be searched. -1 image to be searched; taking the image area corresponding to the target image area of the K-1th image to be searched in the K-2th image to be searched as the candidate image area of the K-2th image to be searched…matching step by step based on the same method until the target image area of the second image to be searched is determined, taking the image area corresponding to the target image area of the second image to be searched in the first image to be searched as the candidate image area of the first image to be searched, using the first template image to traverse and search in the candidate image area of the first image to be searched to obtain multiple image windows matching the first template image, calculating the similarity between each image window and the first template image, and determining the image window with the largest similarity as the target image area of the first image to be searched.
[0085] That is, in the embodiment of the present application, the search is started from the image to be searched with the lowest resolution, and a rough matching position will be obtained. The next matching operation is performed on the rough matching position obtained by the previous matching, and the amount of calculated data is small. In this way, the resolution of the image to be searched and the template image will become higher and higher, and the search range will become smaller and smaller. Finally, the NCC algorithm is used to accurately calculate the mutual correlation coefficient, and the exact matching position can be finally found.
[0086] S14: Determine the target image area of the first image to be searched as the matching position of the target object in the initial image to be searched.
[0087] Furthermore, the next frame image of the current frame can be tracked based on the same method. Based on the image matching method provided in the embodiment of the present application, the Kalman filter is used to predict the position of the target object. During the search process, the pyramid search strategy is combined with the normalized cross-correlation template matching algorithm to effectively improve the matching speed and the matching accuracy of the target in partial occlusion conditions, thereby effectively improving the real-time performance of the target tracking algorithm.
[0088] The embodiment of the present application provides an image matching method, comprising: obtaining an initial template image and an initial image to be searched, wherein the initial template image is an image window of a target object, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image; preprocessing the initial template image and the initial image to be searched respectively to obtain a template image set and a set of images to be searched, wherein the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image; wherein the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and among the K images to be searched, the Nth image to be searched is an image obtained by averaging a preset number of pixels in the N-1th template image. an image obtained by averaging a preset number of pixels in an image to be searched, where K and N are both integers greater than or equal to 1, and N≤K; searching in the Kth image to be searched using the Kth template image to obtain a target image region in the Kth image to be searched with the greatest similarity to the Kth template image, using an image region corresponding to the target image region in the K-1th image to be searched as a candidate image region of the K-1th image to be searched, searching in the candidate image region of the K-1th image to be searched using the K-1th template image to obtain a target image region in the K-1th image to be searched with the K-1th template image, and gradually obtaining a target image region of the first image to be searched; and determining the target image region of the first image to be searched as a matching position of the target object in the initial image to be searched. In the embodiment of the present application, since the initial image to be searched is an adaptive window centered on the image window of the target object, the size of the adaptive window is larger than the size of the initial template image, that is, the matching in the embodiment of the present application is performed in the adaptive window rather than the entire image area. Therefore, not only the amount of data to be processed is reduced, but also other interference factors outside the adaptive window are reduced, which can effectively avoid mismatching of the target object when it is partially obscured, thereby improving the matching accuracy.
[0089] Based on the same inventive concept, as an implementation of the above method, an embodiment of the present application also provides an image matching device. The device embodiment corresponds to the above method embodiment. For ease of reading, the device embodiment will no longer repeat the details of the above method embodiment one by one, but it should be clear that the device in this embodiment can correspond to all the contents in the above method embodiment.
[0090] Figure 3 The structural block diagram of the image matching device provided in the embodiment of the present application is as follows: Figure 3 As shown, the image matching device 300 provided in this embodiment includes:
[0091] An acquisition module 310 is used to acquire an initial template image and an initial image to be searched, wherein the initial template image is an image window of a target object, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image;
[0092] The processing module 320 is used to preprocess the initial template image and the initial image to be searched, respectively, to obtain a template image set and a set of images to be searched, wherein the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image; wherein the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and among the K images to be searched, the Nth image to be searched is an image obtained by averaging a preset number of pixels in the N-1th image to be searched, and K and N are both integers greater than or equal to 1, and N≤K;
[0093] The matching module 330 is used to use the Kth template image to search in the Kth image to be searched, obtain the target image region in the Kth image to be searched that has the greatest similarity with the Kth template image, use the image region corresponding to the target image region in the K-1th image to be searched as the candidate image region of the K-1th image to be searched, use the K-1th template image to search in the candidate image region of the K-1th image to be searched, obtain the target image region in the K-1th image to be searched that has the greatest similarity with the K-1th template image, and gradually obtain the target image region of the first image to be searched;
[0094] The determination module 340 is configured to determine that the target image region of the first image to be searched is a matching position of the target object in the initial image to be searched.
[0095] As an optional implementation of the embodiment of the present application, the acquisition module 310 is specifically used to determine the current frame image, determine the image window corresponding to the target object in the frame image previous to the current frame image, as the initial template image; predict the target position where the target object appears in the current frame image; determine an adaptive window with the target position as the center, and use the adaptive window as the initial image to be searched, wherein the size of the adaptive window is smaller than the size of the current frame image.
[0096] As an optional implementation of the embodiment of the present application, the processing module 320 is specifically used to, for the initial template image, average every m*m pixels as one pixel to obtain a second template image, in the second template image, average every m*m pixels as one pixel to obtain a third template image, and gradually perform pixel averaging processing until the Kth template image is obtained, and the K template images constitute a template image set; for the initial image to be searched, average every m*m pixels as one pixel to obtain a second image to be searched, in the second image to be searched, average every m*m pixels as one pixel to obtain a third image to be searched, and gradually perform pixel averaging processing until the Kth image to be searched is obtained, and the K images to be searched constitute a template image set.
[0097] As an optional implementation of the embodiment of the present application, the matching module 330 is specifically used to use the Kth template image to traverse and search in the Kth image to be searched, and obtain multiple image windows that match the Kth template image; calculate the similarity between each image window and the Kth template image, and determine the image window with the largest similarity as the target image area of the Kth image to be searched.
[0098] As an optional implementation of the embodiment of the present application, the acquisition module 310 is specifically used to determine the eight-neighborhood windows of the center window with the image window corresponding to the target position as the center window; and use the center window and the eight-neighborhood windows of the center window as adaptive windows.
[0099] As an optional implementation of the embodiment of the present application, m takes a value of 2; the processing module 320 is specifically used to average every 2*2 pixels into one pixel for the initial template image to obtain a second template image; and to average every 2*2 pixels into one pixel for the initial image to be searched to obtain a second image to be searched.
[0100] As an optional implementation of the embodiment of the present application, the acquisition module 310 is specifically used to predict the target position of the target object in the current frame image by using a Kalman filter algorithm.
[0101] The image matching device provided in the embodiment of the present application executes an image matching method, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image. That is, the matching in the embodiment of the present application is performed in the adaptive window rather than the entire image area. Therefore, not only the amount of data to be processed is reduced, but also other interference factors outside the adaptive window are reduced, which can effectively avoid mismatching of the target object when it is partially obscured, thereby improving the matching accuracy.
[0102] The image matching device provided in this embodiment can execute the image matching method provided in the above method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here. Each module in the above image matching device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0103] In one embodiment, the present disclosure provides an electronic device, referring to Figure 4 As shown, the electronic device includes: a processor 410, a memory 420, and a computer program stored in the memory 420 and executable on the processor 410. When the computer program is executed by the processor 410, each process of the image matching method in the above method embodiment is implemented. And the same technical effect can be achieved, so it will not be described here to avoid repetition.
[0104] An embodiment of the present disclosure provides a computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, each process of the image matching method in the above method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0105] Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0106] In one embodiment, the image matching method provided by the present application can be implemented in the form of a computer program. The computer program can be Figure 4 The memory of the electronic device may store various program modules constituting the electronic device, for example, Figure 3 The acquisition module 310 and the matching module 330 are shown. The computer program composed of various program modules enables the processor to execute the steps of the image matching method of each embodiment of the present application described in this specification.
[0107] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the following steps when executing the computer program: obtaining an initial template image and an initial image to be searched, wherein the initial template image is an image window of a target object, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image; preprocessing the initial template image and the initial image to be searched respectively to obtain a template image set and a set of images to be searched, wherein the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image; wherein the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and the K images to be searched are obtained by averaging a preset number of pixels in the K-1th template image. In the search image, the Nth image to be searched is an image obtained by averaging a preset number of pixels in the N-1th image to be searched, K and N are both integers greater than or equal to 1, N≤K; the Kth template image is used to search in the Kth image to be searched, and a target image region with the greatest similarity to the Kth template image in the Kth image to be searched is obtained, and an image region corresponding to the target image region in the K-1th image to be searched is used as a candidate image region of the K-1th image to be searched, and the K-1th template image is used to search in the candidate image region of the K-1th image to be searched, and a target image region of the first image to be searched is obtained step by step; and the target image region of the first image to be searched is determined to be a matching position of the target object in the initial image to be searched.
[0108] In one embodiment, when the processor executes the computer program, the following steps are also implemented: determining a current frame image, determining an image window corresponding to a target object in a frame image previous to the current frame image as an initial template image; predicting a target position where the target object appears in the current frame image; determining an adaptive window with the target position as the center, using the adaptive window as the initial image to be searched, wherein the size of the adaptive window is smaller than the size of the current frame image.
[0109] In one embodiment, the processor further implements the following steps when executing the computer program: for the initial template image, average every m*m pixels as one pixel to obtain a second template image, in the second template image, average every m*m pixels as one pixel to obtain a third template image, and gradually perform pixel averaging processing until the Kth template image is obtained, and the K template images constitute a template image set; for the initial image to be searched, average every m*m pixels as one pixel to obtain a second image to be searched, in the second image to be searched, average every m*m pixels as one pixel to obtain a third image to be searched, and gradually perform pixel averaging processing until the Kth image to be searched is obtained, and the K images to be searched constitute a template image set.
[0110] In one embodiment, when the processor executes the computer program, the following steps are also implemented: using the Kth template image to traverse and search in the Kth image to be searched, and obtaining multiple image windows that match the Kth template image; calculating the similarity between each image window and the Kth template image, and determining the image window with the greatest similarity as the target image area of the Kth image to be searched.
[0111] In one embodiment, when the processor executes the computer program, the following steps are also implemented: taking the image window corresponding to the target position as the center window, determining the eight neighborhood windows of the center window; and taking the center window and the eight neighborhood windows of the center window as adaptive windows.
[0112] In one embodiment, when the processor executes the computer program, the following steps are also implemented: m takes a value of 2; for the initial template image, every 2*2 pixels are averaged into one pixel to obtain a second template image; for the initial image to be searched, every 2*2 pixels are averaged into one pixel to obtain a second image to be searched.
[0113] In one embodiment, when the processor executes the computer program, the following steps are further implemented: using a Kalman filter algorithm to predict the target position where the target object appears in the current frame image.
[0114] The electronic device provided in the embodiment of the present application executes an image matching method, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image. That is, the matching in the embodiment of the present application is performed in the adaptive window rather than the entire image area. Therefore, not only the amount of data to be processed is reduced, but also other interference factors outside the adaptive window are reduced, which can effectively avoid mismatching of the target object when it is partially obscured, thereby improving the matching accuracy.
[0115] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented: obtaining an initial template image and an initial image to be searched, wherein the initial template image is an image window of a target object, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image; preprocessing the initial template image and the initial image to be searched respectively to obtain a template image set and a set of images to be searched, wherein the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image; wherein the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and among the K images to be searched , the Nth image to be searched is an image obtained by averaging a preset number of pixels in the N-1th image to be searched, K and N are both integers greater than or equal to 1, N≤K; using the Kth template image to search in the Kth image to be searched, obtaining a target image region in the Kth image to be searched with the greatest similarity to the Kth template image, using an image region corresponding to the target image region in the K-1th image to be searched as a candidate image region of the K-1th image to be searched, using the K-1th template image to search in the candidate image region of the K-1th image to be searched, obtaining a target image region in the K-1th image to be searched with the greatest similarity to the K-1th template image, and gradually obtaining a target image region of the first image to be searched; determining the target image region of the first image to be searched as a matching position of the target object in the initial image to be searched.
[0116] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented: determining a current frame image, determining an image window corresponding to a target object in a frame image previous to the current frame image as an initial template image; predicting a target position where the target object appears in the current frame image; determining an adaptive window with the target position as the center, using the adaptive window as the initial image to be searched, wherein the size of the adaptive window is smaller than the size of the current frame image.
[0117] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: for the initial template image, every m*m pixels are averaged as one pixel to obtain a second template image, in the second template image, every m*m pixels are averaged as one pixel to obtain a third template image, and pixel averaging processing is gradually performed until the Kth template image is obtained, and the K template images constitute a template image set; for the initial image to be searched, every m*m pixels are averaged as one pixel to obtain a second image to be searched, in the second image to be searched, every m*m pixels are averaged as one pixel to obtain a third image to be searched, and pixel averaging processing is gradually performed until the Kth image to be searched is obtained, and the K images to be searched constitute a template image set.
[0118] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: using the Kth template image to traverse and search in the Kth image to be searched, and obtaining multiple image windows that match the Kth template image; calculating the similarity between each image window and the Kth template image, and determining the image window with the greatest similarity as the target image area of the Kth image to be searched.
[0119] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: taking the image window corresponding to the target position as the center window, determining the eight neighborhood windows of the center window; and taking the center window and the eight neighborhood windows of the center window as adaptive windows.
[0120] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: m takes a value of 2; for the initial template image, every 2*2 pixels are averaged into one pixel to obtain a second template image; for the initial image to be searched, every 2*2 pixels are averaged into one pixel to obtain a second image to be searched.
[0121] In one embodiment, when the computer program is executed by the processor, the following steps are further implemented: using a Kalman filter algorithm to predict the target position where the target object appears in the current frame image.
[0122] When the computer program provided in the embodiment of the present application is executed by an electronic device, the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image, that is, the matching in the embodiment of the present application is performed in the adaptive window rather than the entire image area. Therefore, not only the amount of data to be processed is reduced, but also other interference factors outside the adaptive window are reduced, which can effectively avoid mismatching of the target object when it is partially obscured, thereby improving the matching accuracy.
[0123] The computer program stored on the computer-readable storage medium provided in this embodiment can implement the image matching method provided in the above method embodiment. Its implementation principle and technical effect are similar and will not be repeated here.
[0124] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in various forms, such as static random access memory (SRAM) and dynamic random access memory (DRAM).
[0125] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, 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.
[0126] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. An image matching method, characterized in that: include: Acquire an initial template image and an initial image to be searched, wherein the initial template image is an image window of a target object, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image; Preprocessing the initial template image and the initial image to be searched respectively to obtain a template image set and a set of images to be searched, wherein the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image; wherein the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and among the K images to be searched, the Nth image to be searched is an image obtained by averaging a preset number of pixels in the N-1th image to be searched, and both K and N are integers greater than or equal to 1, and N≤K; Using the Kth template image to search in the Kth image to be searched, obtaining the target image region in the Kth image to be searched that has the greatest similarity with the Kth template image, using the image region corresponding to the target image region in the K-1th image to be searched as the candidate image region of the K-1th image to be searched, using the K-1th template image to search in the candidate image region of the K-1th image to be searched, obtaining the target image region in the K-1th image to be searched that has the greatest similarity with the K-1th template image, and gradually obtaining the target image region of the first image to be searched; The target image region of the first image to be searched is determined as a matching position of the target object in the initial image to be searched.
2. The method according to claim 1, characterized in that The obtaining of the initial template image and the initial image to be searched comprises: Determine a current frame image, and determine an image window corresponding to the target object in a frame image before the current frame image as an initial template image; Predicting a target position where the target object appears in the current frame image; An adaptive window is determined with the target position as the center, and the adaptive window is used as the initial image to be searched. The size of the adaptive window is smaller than the size of the current frame image.
3. The method according to claim 1, characterized in that The preprocessing of the initial template image and the initial image to be searched respectively to obtain a template image set and an image set to be searched comprises: For the initial template image, average every m*m pixels as one pixel to obtain a second template image. In the second template image, average every m*m pixels as one pixel to obtain a third template image. Perform pixel averaging processing step by step until the Kth template image is obtained. The K template images constitute a template image set. For the initial image to be searched, every m*m pixels are averaged as one pixel to obtain the second image to be searched. In the second image to be searched, every m*m pixels are averaged as one pixel to obtain the third image to be searched. Pixel averaging processing is performed step by step until the Kth image to be searched is obtained. The K images to be searched constitute the template image set.
4. The method according to claim 1, characterized in that: The step of searching the Kth image to be searched using the Kth template image to obtain a target image region in the Kth image to be searched that has the greatest similarity to the Kth template image includes: Using the K-th template image to traverse and search in the K-th image to be searched, to obtain a plurality of image windows matching the K-th template image; The similarity between each image window and the K-th template image is calculated, and the image window with the greatest similarity is determined as the target image region of the K-th image to be searched.
5. The method according to claim 2, characterized in that: The step of determining an adaptive window with the target position as the center and using the adaptive window as the initial image to be searched includes: Taking the image window corresponding to the target position as the center window, determining eight neighborhood windows of the center window; The central window and eight neighboring windows of the central window are used as adaptive windows.
6. The method according to claim 3, characterized in that: The value of m is 2; The method of averaging each m*m pixels into one pixel for the initial template image to obtain a second template image includes: For the initial template image, average every 2*2 pixels into one pixel to obtain the second template image; The method of averaging each m*m pixels into one pixel for the initial image to be searched to obtain a second image to be searched includes: For the initial image to be searched, every 2*2 pixels are averaged into one pixel to obtain the second image to be searched.
7. The method according to claim 2, characterized in that The predicting a target position where the target object appears in the current frame image includes: A Kalman filter algorithm is used to predict the target position where the target object appears in the current frame image.
8. An image matching device, characterized in that: include: An acquisition module, used for acquiring an initial template image and an initial image to be searched, wherein the initial template image is an image window of a target object, and the initial image to be searched is an adaptive window centered on the image window of the target object, and the size of the adaptive window is larger than the size of the initial template image; A processing module, used for preprocessing the initial template image and the initial image to be searched respectively to obtain a template image set and a set of images to be searched, wherein the template image set includes K template images with the initial template image as the first image, and the set of images to be searched includes K images to be searched with the initial image to be searched as the first image; wherein the Nth template image is an image obtained by averaging a preset number of pixels in the N-1th template image, and among the K images to be searched, the Nth image to be searched is an image obtained by averaging a preset number of pixels in the N-1th image to be searched, and both K and N are integers greater than or equal to 1, and N≤K; a matching module, configured to use the Kth template image to search in the Kth image to be searched, obtain a target image region in the Kth image to be searched that has the greatest similarity with the Kth template image, use an image region corresponding to the target image region in the K-1th image to be searched as a candidate image region of the K-1th image to be searched, use the K-1th template image to search in the candidate image region of the K-1th image to be searched, obtain a target image region in the K-1th image to be searched that has the greatest similarity with the K-1th template image, and gradually obtain the target image region of the first image to be searched; A determination module is used to determine that the target image area of the first image to be searched is the matching position of the target object in the initial image to be searched.
9. An electronic device, characterized in that: include: A memory and a processor, the memory is used to store a computer program; the processor is used to execute the image matching method described in any one of claims 1 to 7 when calling the computer program.
10. An electronic device, characterized in that: include: A memory and a processor, the memory is used to store a computer program; the processor is used to execute the image matching method described in any one of claims 1 to 7 when calling the computer program.
