Image contour template matching method and device
By using pyramid hierarchical features and sliding window traversal methods in image matching, combined with similarity matching and weighting processing of template feature points and feature points to be matched, the problem of inaccurate and unstable positioning in complex scenes is solved and improved Matching accuracy and stability.
Patent Information
- Application Number
- CN202411382406.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-01-24
AI Technical Summary
Existing image template matching methods can easily lead to inaccurate positioning and instability in complex scenarios, affecting the accuracy and stability of the target product.
An image contour template matching method is proposed. By obtaining the pyramid hierarchical feature information of the template image and the image to be matched, a sliding window is used to traverse the image to be matched, and similarity is performed based on the position information of the template feature points and the edge amplitude of the feature points to be matched. degree matching and weighting processing to find the target qualified position.
The accuracy and stability of template matching in complex scenarios has been improved, and the problem of inaccurate and unstable positioning of existing methods in complex scenarios is solved.
Smart Images

Figure CN119360058A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image contour template matching method and device. Background Art
[0002] In industrial production, automation systems often need to accurately locate target products in order to perform operations such as sorting, grasping, alignment, and gluing. Target products are usually located using image template matching methods, which extract contour features and create templates by shooting standard target images, and then find targets that match the template features in the image to be matched to determine the target's position. In simple scenes with a single target, uniform lighting, and obvious product feature contrast, existing image template matching methods can accurately and quickly locate the target.
[0003] However, in some complex scenarios, such as uneven distribution of product features, uneven material reflection, or irregular light and dark polarity of feature points, existing methods are prone to inaccurate and unstable positioning, or even positioning failure, thereby affecting the accuracy and stability of target product positioning.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of this application is to provide an image contour template matching method, aiming to solve the problems of inaccurate and unstable positioning of existing template matching methods in complex scenes.
[0006] To achieve the above object, the present application proposes an image contour template matching method, the method comprising: S100, acquiring template feature information of each layer of the pyramid of the template image, where the template feature information includes feature information of a plurality of template feature points; S200, obtaining feature information of the image to be matched of each layer of the pyramid of the image to be matched; S300, based on the pyramid hierarchical structure from top to bottom, in the to-be-matched area of the to-be-matched image of the current layer of the pyramid, a sliding window of the same size as the template image is used to traverse, and based on the position information of the multiple template feature points and the feature information of the to-be-matched image, feature information of the multiple to-be-matched feature points in the window is extracted at each pixel position; the feature information of the multiple to-be-matched feature points is similarly matched with the feature information of the corresponding template feature points one by one to obtain a similarity matching score, and a target candidate position whose total similarity matching score at the pixel position is greater than or equal to a first preset threshold is found; wherein the feature information of the multiple template feature points includes position information; S400, at each target candidate position, weighting the similarity matching scores of the multiple feature points to be matched in the window according to the edge amplitudes of the multiple feature points to be matched, and finding a target qualified position at the target candidate position whose total weighted matching score is greater than or equal to a second preset threshold; wherein the feature information of the feature points to be matched includes edge amplitude information; S500, mapping the target qualified position of the image to be matched in the current layer of pyramid to the corresponding area of the image to be matched in the next layer of pyramid, constructing the area to be matched in the next layer of pyramid, and repeating steps S300 to S400 until the target qualified position of the image to be matched is found in the bottom layer of pyramid.
[0007] In one embodiment, the feature information includes directional feature information, and the steps of performing similarity matching on the feature information of the plurality of feature points to be matched with the feature information of the corresponding template feature points one by one to obtain a similarity matching score, and finding a target candidate position whose total similarity matching score at the pixel position reaches a first preset threshold include: The directional feature information of multiple feature points to be matched is matched with the directional feature information of the corresponding template feature points one by one by cosine similarity, and a similarity matching score is calculated; based on the similarity matching scores of the multiple feature points to be matched, a total similarity matching score at the pixel position is obtained; based on the total similarity matching score at the pixel position, a target candidate position whose total similarity matching score at the pixel position is greater than or equal to a first preset threshold is found.
[0008] In one embodiment, the step of obtaining a total similarity matching score at a pixel position according to the similarity matching scores of a plurality of feature points to be matched comprises: The similarity matching scores of the feature points to be matched whose calculation results are negative values are eliminated to obtain a non-negative similarity matching score set; based on the non-negative similarity matching score set, the total similarity matching score at the pixel position is obtained.
[0009] In one embodiment, the step of weighting the similarity matching scores of the plurality of feature points to be matched according to the edge amplitudes of the plurality of feature points to be matched in the window, and finding a target qualified position at the target candidate position whose total weighted matching score is greater than or equal to a second preset threshold comprises: According to the edge amplitudes of multiple feature points to be matched in the window, amplitude weighted values of multiple matching feature points in the window are determined; according to the amplitude weighted values of multiple matching feature points in the window, the similarity matching scores of the multiple matching feature points in the window are weighted to obtain a weighted matching total score at the target candidate position; according to the weighted matching total score at the target candidate position, a target qualified position whose weighted matching total score at the target candidate position is greater than or equal to a second preset threshold is found.
[0010] In one embodiment, the step of determining amplitude weighted values of multiple matching feature points in the window according to edge amplitudes of multiple to-be-matched feature points in the window comprises: An edge amplitude limit threshold is determined according to similarity matching scores of multiple feature points to be matched in the window and edge amplitudes of multiple feature points to be matched; amplitude weighted values of multiple feature points to be matched in the window are determined according to the edge amplitudes of multiple feature points to be matched in the window and the edge amplitude limit threshold; wherein, when the edge amplitude of the feature point to be matched is less than the edge amplitude limit threshold, the amplitude weighted value of the feature point to be matched increases as the edge amplitude of the feature point to be matched increases; when the edge amplitude of the feature point to be matched is greater than or equal to the edge amplitude limit threshold, the amplitude weighted value of the feature point to be matched remains unchanged as the edge amplitude of the feature point to be matched increases.
[0011] In one embodiment, the step S100 includes: The template image is decomposed into a pyramid image sequence of different sizes and resolutions to form a pyramid hierarchical structure from top to bottom; in each layer of the pyramid of the template image, based on the gradient filter, a template gradient feature set whose edge amplitude in the template image is greater than a preset amplitude threshold is extracted; wherein the template gradient feature set includes a horizontal gradient information set, a vertical gradient information set and an edge amplitude information set; non-maximum suppression is performed on the edge amplitude information set of the template image to obtain a refined edge of the template image; single-pixel processing is performed on the refined edge of the template image and traversed to obtain directional feature information and position information of multiple template feature points of the template image.
[0012] In one embodiment, the directional feature information includes unit directional feature information, and the position information includes standard position information; the step of performing single-pixel processing on the thinned edge of the template image and traversing to obtain feature information of multiple template feature points of the template image includes: The refined edges of the template image are processed by single pixel and traversed to obtain the directional features, edge amplitude, position information and center position information of multiple template feature points of the template image; based on the directional features and edge amplitude of the multiple template feature points, normalization processing is performed to obtain the unit directional feature information of the template feature points; based on the position information and center position information of the multiple template feature points, the standard position information of the positions of the multiple template feature points relative to the center of the template image is obtained.
[0013] In one embodiment, the image feature information to be matched includes directional feature information and edge amplitude information; the step S200 includes: The image to be matched is decomposed into a pyramid image sequence of different sizes and resolutions to form a pyramid hierarchical structure from top to bottom; in each layer of the pyramid of the image to be matched, based on the gradient filter, a gradient feature set to be matched whose edge amplitude in the image to be matched is greater than a preset amplitude threshold is extracted; wherein the gradient feature set to be matched includes a horizontal gradient information set, a vertical gradient information set and an edge amplitude set; the horizontal gradient information set and the vertical gradient information set are used to indicate directional feature information, and the edge amplitude set is used to indicate edge amplitude information.
[0014] In one embodiment, the directional feature information includes a unit directional feature, and the edge amplitude information is set within a preset range; after the step of extracting, in each layer of the pyramid of the image to be matched, a gradient feature set to be matched whose edge amplitude in the image to be matched is greater than a preset amplitude threshold based on a gradient filter, the step S200 further includes: Based on the gradient feature set to be matched, normalization processing is performed to obtain unit direction feature information of the image to be matched and edge amplitude information within a preset range.
[0015] In addition, to achieve the above-mentioned purpose, the present application also proposes an image contour template matching device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the image contour template matching method as described in the above-mentioned embodiment.
[0016] One or more technical solutions proposed in this application have at least the following technical effects: Step S100, obtaining the template feature information of each pyramid layer of the template image, wherein the template feature information includes feature information of multiple template feature points. Step S200, obtaining the feature information of the image to be matched of each pyramid layer of the image to be matched. Step S300, based on the pyramid hierarchical structure from top to bottom, traverse the to-be-matched area of the image to be matched of the current pyramid layer using a sliding window of the same size as the template image, and extract the feature information of multiple to-be-matched feature points in the window at each pixel position based on the position information of multiple template feature points and the feature information of the image to be matched; perform similarity matching on the feature information of multiple to-be-matched feature points with the feature information of the corresponding template feature points one by one to obtain a similarity matching score, and find out the target candidate position whose total similarity matching score at the pixel position is greater than or equal to the first preset threshold; wherein the feature information of multiple template feature points includes position information. wherein the total similarity matching score is the superposition of multiple similarity matching scores. Step S400, at each target candidate position, weighted scores are performed on the similarity matching scores of the multiple feature points to be matched according to the edge amplitudes of the multiple feature points to be matched in the window, and a target qualified position whose weighted matching total score at the target candidate position is greater than or equal to the second preset threshold is found; wherein the feature information of the feature points to be matched includes edge amplitude information. Step S500, mapping the target qualified position of the image to be matched in the current layer of the pyramid to the corresponding area of the image to be matched in the next layer of the pyramid, constructing the area to be matched in the next layer of the pyramid, and repeating steps S300 to S400 until the target qualified position of the image to be matched is found in the bottom layer of the pyramid. In this way, the present application divides the image to be matched into different pyramid layers, and preliminarily finds the target candidate position from multiple pixel positions of the image to be matched in the current pyramid layer under different pyramid layers, and then finds the target qualified position from the target candidate position, and maps the target qualified position of the image to be matched in the current layer of the pyramid to the next layer for search, until the target qualified position of the image to be matched in the bottom layer of the pyramid is found, and the matching result is obtained. In this way, the present application uses a similarity matching method to find the target candidate position whose total similarity matching score at the pixel position is greater than or equal to the first preset threshold, and then finds the target qualified position whose weighted matching total score at the target candidate position is greater than or equal to the second preset threshold according to the different contribution weights of the edge amplitude of the feature point to be matched. This can improve the accuracy and stability of template matching in complex scenes, and solves the problem of inaccurate and unstable positioning of existing template matching methods in complex scenes. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] 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.
[0018] 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 labor.
[0019] Figure 1 A schematic diagram of a flow chart provided for an embodiment of the image contour template matching method of the present application; Figure 2 A flowchart diagram of another embodiment of the image contour template matching method of the present application is provided; Figure 3 A flowchart diagram of another embodiment of the image contour template matching method of the present application is provided; Figure 4 A flowchart diagram of another embodiment of the image contour template matching method of the present application is provided; Figure 5 is a relationship diagram of an exemplary method for calculating the cosine similarity of the unit direction vector of the template feature point and the feature point to be matched within the range of the angle [0, 360] degrees; Figure 6 A relationship diagram of the cosine similarity calculation method of the unit direction vector of the template feature point and the feature point to be matched provided in this application within the range of the angle [0, 360] degrees; Figure 7 A piecewise function diagram of the amplitude weighted value of the feature point to be matched provided by the present application according to the change of the edge amplitude; Figure 8 A schematic diagram of the device structure of the hardware operating environment involved in the image contour template matching method in the embodiment of the present application; Fig. 9 A schematic diagram of traversing a sliding window provided in an embodiment of the image contour template matching method in an embodiment of the present application.
[0020] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0021] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0022] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0023] The main solutions of the embodiments of this application are: Step S100, obtaining the template feature information of each pyramid layer of the template image, wherein the template feature information includes feature information of multiple template feature points. Step S200, obtaining the feature information of the image to be matched of each pyramid layer of the image to be matched. Step S300, based on the pyramid hierarchical structure from top to bottom, traverse the to-be-matched area of the image to be matched of the current pyramid layer using a sliding window of the same size as the template image, and extract the feature information of multiple to-be-matched feature points in the window at each pixel position based on the position information of multiple template feature points and the feature information of the image to be matched; perform similarity matching one by one on the feature information of the multiple to-be-matched feature points and the feature information of the corresponding template feature points to obtain a similarity matching score, and find the target candidate position whose total similarity matching score at the pixel position is greater than or equal to the first preset threshold; wherein the feature information of multiple template feature points includes position information. Step S400, at each target candidate position, weight the similarity matching scores of the multiple feature points to be matched according to the edge amplitudes of the multiple feature points to be matched in the window, and find the target qualified position at the target candidate position whose total weighted matching score is greater than or equal to the second preset threshold; wherein the feature information of the feature points to be matched includes edge amplitude information. Step S500, map the target qualified position of the image to be matched in the current layer of the pyramid to the corresponding area of the image to be matched in the next layer of the pyramid, construct the area to be matched in the next layer of the pyramid, and repeat steps S300 to S400 until the target qualified position of the image to be matched is found in the bottom layer of the pyramid. In this embodiment, for ease of description, the following is explained with the image contour template matching device as the execution subject.
[0024] Existing template matching methods can easily lead to inaccurate and unstable positioning, or even positioning failure, in some complex scenarios, such as uneven distribution of product features, uneven material reflection, or irregular light and dark polarity of feature points, thus affecting the accuracy and stability of target product positioning.
[0025] The present application provides a solution, so that the image to be matched can be divided into different pyramid layers for template matching, reducing the complexity of data processing. Under different pyramid layers, the present application can find the target qualified position from the pixel position of the image to be matched in the current pyramid layer, and map it to the next pyramid layer for positioning search according to the positioning information of the target qualified position, until the positioning result of the target qualified position is obtained in the bottom pyramid layer. In this way, the present application finds the target candidate position whose total similarity matching score at the pixel position is greater than or equal to the first preset threshold value through the similarity matching method, and then finds the target qualified position whose weighted matching total score at the target candidate position is greater than or equal to the second preset threshold value according to the different contribution weights of the edge amplitude of the feature point to be matched, which can improve the accuracy and stability of template matching in complex scenes, and solves the problem of inaccurate and unstable positioning of existing template matching methods in complex scenes.
[0026] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, such as an image contour template matching device, etc. The following takes the image contour template matching device as an example to illustrate this embodiment and the following embodiments.
[0027] Based on this, the present application embodiment provides an image contour template matching method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the image contour template matching method of the present application.
[0028] In this embodiment, the image contour template matching method includes steps S100 to S500: Step S100 , obtaining template feature information of each pyramid layer of the template image, where the template feature information includes feature information of a plurality of template feature points.
[0029] Step S200, obtaining feature information of the image to be matched of each layer of the pyramid of the image to be matched.
[0030] It should be noted that the image to be matched and the template image are processed according to the pyramid hierarchical structure, that is, the image is reduced to different scale levels. In this way, matching can be performed at different resolutions, enhancing the detection capability of objects of various scales.
[0031] Step S300, based on the pyramid hierarchical structure from top to bottom, in the to-be-matched area of the to-be-matched image of the current layer of the pyramid, a sliding window of the same size as the template image is used to traverse, and based on the position information of the multiple template feature points and the feature information of the to-be-matched image, feature information of the multiple to-be-matched feature points in the window is extracted at each pixel position; the feature information of the multiple to-be-matched feature points is similarly matched with the feature information of the corresponding template feature points one by one to obtain a similarity matching score, and a target candidate position whose total similarity matching score at the pixel position is greater than or equal to a first preset threshold is found; wherein the feature information of the multiple template feature points includes position information.
[0032] It should be noted that the highest level of the pyramid is a low-resolution version of the image, which can be used to capture the global information of the image and perform rough matching or positioning. Then the resolution can be gradually improved on the basis of the low resolution until the positioning target is found on the highest resolution image. Fig. 9 , Fig. 9 The pyramid shows an exemplary process of mapping layer by layer until a qualified target position of the bottom pyramid layer is obtained. This embodiment aims to obtain the final target positioning on a high-resolution image.
[0033] It should be noted that the area to be matched includes multiple pixel positions. In the current layer pyramid of the image to be matched, a sliding window with the same size as the template image is set. Each pixel position can correspond to a traversal position of the sliding window. Starting from the upper left corner of the image to be matched, the sliding window is gradually moved to each possible position until the entire area to be matched is found. Please refer to Fig. 9 , Fig. 9 The figure shows an exemplary process of traversing a to-be-matched region of an image to be matched in a pyramid layered structure from top to bottom using a sliding window of the same size as the template image.
[0034] It should be noted that, according to the position information of the template feature points, the corresponding feature points to be matched in each window are extracted, and according to the feature information of the image to be matched in the current layer, the feature information of multiple feature points to be matched in the window is obtained, and the similarity matching can be performed one by one with the feature information of the template feature points. A matching score is calculated for each window position, that is, the total similarity matching score, which reflects the similarity between the feature points in the window and the template feature points. The window position with a high score indicates a higher matching degree. In this way, the window with a higher score can be found according to the matching score, and the position of the window is recorded, which is the target candidate position.
[0035] Step S400, at each target candidate position, weighted scores are performed on the similarity matching scores of the multiple feature points to be matched according to the edge amplitudes of the multiple feature points to be matched within the window, and a target qualified position whose weighted matching total score at the target candidate position is greater than or equal to a second preset threshold is found; wherein the feature information of the feature points to be matched includes edge amplitude information.
[0036] It should be noted that the amplitude of the noise on the image to be matched is weak, and the amplitude of the edge of the line with a clear contour is strong. Among them, the contour with a strong amplitude is more likely to be the edge contour of the target. Therefore, the contribution to the similarity matching score can be weighted according to the edge amplitude of the feature point to be matched in the current pyramid layer. The stronger the amplitude, the greater the contribution weight to the matching score.
[0037] Step S500, mapping the target qualified position of the image to be matched in the current layer of pyramid to the corresponding area of the image to be matched in the next layer of pyramid, constructing the area to be matched in the next layer of pyramid, and repeating steps S300 to S400 until the target qualified position of the image to be matched is found in the bottom layer of pyramid.
[0038] It should be noted that, based on the pyramid hierarchical structure from top to bottom and the pyramid matching strategy from top to bottom, the target qualified position of the current layer can be mapped to the corresponding area of the image to be matched of the next pyramid layer to construct the local area to be matched of the image to be matched of the next layer. Steps S300 to S400 are repeatedly performed in the local area to be matched of the next layer to obtain the target qualified position of the bottom pyramid layer.
[0039] In this way, the present embodiment reduces the complexity of data processing by dividing the image to be matched into different pyramid layers for template matching. Under different pyramid layers, the present embodiment can find the target qualified position from the pixel position of the image to be matched in the current pyramid layer, and map it to the next pyramid layer for positioning search according to the positioning information of the target qualified position, until the positioning result of the target qualified position is obtained in the bottom pyramid layer. In this way, the present embodiment finds the target candidate position whose total similarity matching score at the pixel position is greater than or equal to the first preset threshold value through the similarity matching method, and then finds the target qualified position whose weighted matching total score at the target candidate position is greater than or equal to the second preset threshold value according to the different contribution weights of the edge amplitude of the feature point to be matched, which can improve the accuracy and stability of template matching in complex scenes, and solves the problem of inaccurate and unstable positioning of the existing template matching method in complex scenes.
[0040] It should be noted that, for the convenience of explanation, when performing sliding traversal, it can be noted that the i-th template feature point at each pixel position corresponds to the i-th feature point to be matched in the window.
[0041] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated later. On this basis, the characteristic information includes directional characteristic information, and step S300 includes steps S310~S340: Step S310, based on the pyramid hierarchical structure from top to bottom, traverse the to-be-matched area of the to-be-matched image of the current layer of the pyramid using a sliding window of the same size as the template image, and extract feature information of multiple to-be-matched feature points in the window at each pixel position based on the position information of multiple template feature points and the feature information of the to-be-matched image.
[0042] Step S320 , performing cosine similarity matching on the directional feature information of the plurality of feature points to be matched and the directional feature information of the corresponding template feature points one by one, and calculating a similarity matching score.
[0043] Step S330: derive a total similarity matching score at the pixel position according to the similarity matching scores of the plurality of feature points to be matched.
[0044] Step S340 , searching for a target candidate position whose total similarity matching score at the pixel position is greater than or equal to a first preset threshold value according to the total similarity matching score at the pixel position.
[0045] It should be noted that the template feature of the current pyramid layer is mod={x i -c x , y i -c y , gx i ,gy i}; Among them, mod is the feature information of the i-th template feature point, c x is the horizontal coordinate of the center of the template image, c y is the vertical coordinate of the center of the template image, x i is the horizontal coordinate of the position information of the i-th template feature point, y i is the vertical coordinate of the position information of the i-th template feature point. i is the horizontal coordinate of the unit direction vector of the i-th template feature point, gy i is the vertical coordinate of the unit direction vector of the template feature point. x = w / 2, c y = h / 2, w is the width of the template image, and h is the height of the template image.
[0046] The feature information of the feature point to be matched in the current pyramid layer is specifically a unit direction vector (gx, gy); where gx = g x / mag,gy = g y / mag; g x is the horizontal gradient of the feature point to be matched at the corresponding position of the image to be matched, g x is the vertical gradient of the feature point to be matched at the corresponding position of the image to be matched, and mag is the edge amplitude of the feature point to be matched at the corresponding position of the image to be matched. Use the template feature mod to slide row by row and column by column under the current pyramid layer of the image to be matched, and calculate the total similarity matching score s of multiple template feature points and the corresponding feature point to be matched at each position (x, y). If s is greater than or equal to the first preset threshold s T , then find out the position coordinates (x, y) of the pixel position, which are the position coordinates of the target candidate position.
[0047] It should be noted that the similarity calculation between the template feature points and the feature points of the image to be matched can be performed using the cosine of the angle between the two vectors. Specifically, at the pixel position (x, y) of the image to be matched, we have: Formula 1:
[0048] in, is the modulus of the unit direction vector of the template feature point, which is 1; is the modulus of the unit direction vector of the template feature point, which is 1; The cosine of the angle between the unit direction vector of the i-th template feature point and the unit direction vector of the i-th feature point to be matched, that is, the similarity matching score of the two vectors at this point; is the horizontal gradient of the i-th template feature point, is the vertical gradient of the i-th template feature point; is the horizontal gradient of the i-th feature point to be matched, is the vertical gradient of the i-th feature point to be matched.
[0049] Therefore, the similarity calculation is simplified to: Formula 2:
[0050] Formula 3:
[0051] in, is the total score of the similarity match between the unit direction vector of the i template feature points at the pixel position (x, y) of the image to be matched and the i feature points to be matched in the window.
[0052] In this way, this embodiment can obtain all target candidate positions whose total similarity matching scores are greater than or equal to the first preset threshold, and preliminarily filter out matching areas of pixel positions with poor similarity.
[0053] Based on the second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the above-mentioned second embodiment can be referred to the above introduction, and will not be repeated in the following. On this basis, step S330 includes steps S331~S332: Step S331 , eliminating similarity matching scores of to-be-matched feature points whose calculation results are negative values, and obtaining a non-negative similarity matching score set.
[0054] Step S332: derive the total similarity matching score at the pixel position based on the non-negative similarity matching score set.
[0055] It should be noted that in order to increase the stability and robustness of the matching, in this embodiment, Formula 4:
[0056] Formula 5:
[0057] Coming soon When the calculated result is negative, it is set to zero. is the total similarity matching score at the pixel position (x, y) obtained based on the non-negative similarity matching score set.
[0058] Please note that Figure 5 , Figure 5 This is a relationship diagram of the cosine similarity calculation method of the unit direction vector of the template feature point and the corresponding unit direction vector of the feature point to be matched within the range of [0, 360] degrees. However, assuming that the polarity of the template feature point and the feature point to be matched are exactly the same, that is, the two direction vectors are in the same direction, the definition of this time is =1. Assume that the polarity of the template feature point and the feature point to be matched are completely opposite, that is, the two direction vectors are opposite, and define = -1, The range is [-1,1]. In complex environments, the edge contour of the target is usually deformed, or due to noise interference at the edge, or due to the reflection of the material, the polarity of the template feature points and the feature points to be matched are usually not completely consistent. Some directions may be the same, and some may be opposite. If the total score of the similarity match is calculated by formula 3, the total score will be reduced and will not reach the first preset threshold, resulting in distortion. For example, when the first preset threshold is 50 points, if 70% of the feature points to be matched have the same polarity as the corresponding template feature points, and 30% have the opposite polarity, then the total score of the similarity match s(x, y)=40, which does not reach the first preset threshold of 50 points, and the match fails.
[0059] In this embodiment, Formula 4 and Formula 5 are used to convert The negative value of the calculation result is set to zero, and the obtained To eliminate the superposition of non-negative similarity matching scores with negative calculation results. At this time, when the first preset threshold is 50 points, if 70% of the feature points to be matched have the same polarity as the corresponding template feature points, and 30% have the opposite polarity, then the total similarity matching score s(x, y) = 70, reaching the preset score, and the match is successful. At this time, please refer to Figure 6 , Figure 6 The relationship diagram of the cosine similarity calculation method of the unit direction vector of the template feature point provided by the present application and the unit direction vector of the feature point to be matched within the angle range of [0, 360] degrees. In this way, the present embodiment can eliminate the negative contribution of the cosine similarity with a negative calculation result to the total score of the similarity matching, thereby enhancing the accuracy and stability of the similarity matching.
[0060] Based on the first embodiment of the present application, in the fourth embodiment of the present application, the same or similar contents as those in the first embodiment can be referred to the above description, and will not be described in detail later. On this basis, step S400 includes steps S410 to S430: Step S410: determining amplitude weighted values of multiple matching feature points in the window according to edge amplitudes of multiple to-be-matched feature points in the window.
[0061] Step S420 , weighting the similarity matching scores of the multiple matching feature points in the window according to the amplitude weighted values of the multiple matching feature points in the window to obtain a weighted total matching score at the target candidate position.
[0062] It should be noted that at the candidate target position (x, y), rate(mag i ) Weight the calculation of formula 4 to obtain the weighted matching total score at the candidate target position (x, y) ,as follows: Formula 6:
[0063] Among them, mag i is the edge amplitude of the i-th feature point to be matched, rate(mag i ) is the amplitude weighted value of the feature point, Obtained by formula 2. Preset rate(mag i ) has a value range of [0, 1], then the amplitude weighted value of the i-th feature point to be matched can be determined according to its edge amplitude.
[0064] Step S430: Find a target qualified position whose weighted total matching score at the target candidate position is greater than or equal to a second preset threshold value according to the weighted total matching score at the target candidate position.
[0065] It should be noted that the weighted matching total score can be calculated using Formula 5 , the preset first proportionality coefficient can be k, then the second preset threshold is k*s T , k can be specifically 0.8. Greater than or equal to k*s T , then the target candidate position (x, y) is recorded as the target qualified position.
[0066] Based on the fourth embodiment of the present application, in the fifth embodiment of the present application, the same or similar contents as those in the fourth embodiment can be referred to the above description, and will not be described in detail later. On this basis, step S410 includes steps S411~S412: Step S411 , determining an edge amplitude limit threshold according to the similarity matching scores of the plurality of feature points to be matched in the window and the edge amplitudes of the plurality of feature points to be matched.
[0067] It should be noted that in order to improve the accuracy and robustness of feature point matching, it is necessary to weight the similarity matching score according to the contribution of the edge amplitude of the matching feature point. Specifically, it includes: Formula 7:
[0068] In order to simplify the calculation, the value range of the edge amplitude can be normalized to 0-255, that is, the value range of the edge amplitude m is [0, 255]. n is the number of feature points to be matched, is the similarity matching score of the i-th feature point to be matched, is the cumulative sum of all values of n feature points to be matched on the edge amplitude [0, 255], that is, It can be the cumulative sum of all values of the n feature points to be matched on all edge amplitudes.
[0069] by As the limit, according to: Formula 8:
[0070] It can be calculated that when the two are equal, the value of the edge amplitude m is the edge amplitude threshold m t .
[0071] According to the edge amplitude threshold m t The edge amplitude limit threshold is determined by the second preset proportional coefficient. Specifically, the second preset proportional coefficient can be 0.65, and mt=0.65 *m t .
[0072] Step S412, determining amplitude weighted values of the plurality of feature points to be matched in the window according to the edge amplitudes of the plurality of feature points to be matched in the window and the edge amplitude limit threshold.
[0073] When the edge amplitude of the feature point to be matched is less than the edge amplitude limit threshold, the amplitude weighted value of the feature point to be matched increases as the edge amplitude of the feature point to be matched increases; When the edge amplitude of the feature point to be matched is greater than or equal to the edge amplitude limit threshold, the amplitude weighted value of the feature point to be matched remains unchanged as the edge amplitude of the feature point to be matched increases.
[0074] When the amplitude of the feature point to be matched is greater than or equal to mt, rate(mag i )=1, otherwise it is a linear increasing relationship, the smaller the amplitude, the greater the amplitude weighting value rate(mag i ) is smaller, the amplitude weighted value of the feature point to be matched changes according to the piecewise function of the amplitude: Formula 9:
[0075] Among them, rate(mag i ) is the amplitude weighted value, mag i is the edge amplitude of the i-th feature point to be matched, and mt is the edge amplitude limit threshold.
[0076] In this way, this embodiment can calculate the weighted matching total score, find the target qualified position at the target candidate position whose weighted matching total score is greater than or equal to the second preset threshold, and the contour of the obtained target qualified position is relatively similar to the contour of the template image, and the obtained result is more accurate.
[0077] Based on the first embodiment of the present application, in the sixth embodiment of the present application, the same or similar contents as those in the first embodiment can be referred to the above description, and will not be described in detail later. Figure 2 , step S100 includes steps S110 to S140: Step S110 , decomposing the template image into pyramid image sequences of different sizes and resolutions to form a pyramid hierarchical structure from top to bottom.
[0078] Step S120, in each pyramid layer of the template image, based on the gradient filter, extracting the template gradient feature set whose edge amplitude in the template image is greater than a preset amplitude threshold; wherein the template gradient feature set includes a horizontal gradient information set, a vertical gradient information set and an edge amplitude information set.
[0079] In this embodiment, the horizontal gradient g can be calculated by a Sobel filter. x Figure 1, i.e. the horizontal gradient information set, represents the grayscale change of the template image in the horizontal direction, and shows the intensity and direction of the image at the horizontal edge; calculate the vertical gradient g y The vertical gradient information set represents the grayscale change of the template image in the vertical direction, showing the strength and direction of the vertical edge in the image; the amplitude mag map, i.e. the amplitude information set, reflects the strength of the edge in the template image. If the amplitude mag is greater than the preset amplitude threshold, the g at the corresponding position is retained. x , g y , mag value is called a valid value, otherwise it is invalid and set to zero. In this way, pixels below the preset amplitude threshold can be regarded as noise or irrelevant details, thereby preventing these pixels from interfering with the edge detection results.
[0080] It should be noted that the edge contour features of the target in the image are usually at the gray value mutation point, which is manifested as a smaller gradient amplitude at a flat point and a larger gradient amplitude at an edge. In this embodiment, the features of the template image sequence use gradient direction features.
[0081] It should be noted that there are many ways to extract the contour edge gradient directional features, such as Roberts, Prewitt, Sobel, and Lapacian filter sliding window methods. In this embodiment, the Sobel filter is used for extraction, which has a certain noise resistance and can improve accuracy and stability. Among them, Sobel is divided into horizontal and vertical direction filters, and the template image is subjected to sliding window operation to obtain the horizontal and vertical direction gradient maps, respectively. The Sobel filter is as follows: Formula 10:
[0082] Among them, g x is the horizontal gradient; Formula 11:
[0083] Among them, g y is the vertical gradient; Formula 12. Where mag is the edge amplitude.
[0084] Step S130, performing non-maximum suppression on the edge amplitude information set of the template image to obtain a refined edge of the template image.
[0085] It should be noted that in the amplitude information image, the purpose of non-maximum suppression is to remove non-edge pixels in the amplitude information image during edge detection. The specific method is to compare the amplitude value of each pixel with the amplitude value of its neighboring pixels in the edge direction, and only retain the local maximum value. That is, when the amplitude value of a pixel is the local maximum in its neighborhood in the edge direction, it is considered to be part of the edge, otherwise, it will be suppressed (i.e. set to zero).
[0086] Step S140 , performing single-pixel processing on the thinned edge of the template image and traversing, to obtain directional feature information and position information of a plurality of template feature points of the template image.
[0087] In one feasible implementation, step S140 includes steps S141 to S143: Step S141 , single-pixel processing is performed on the thinned edge of the template image and traversal is performed to obtain direction features, edge amplitudes, position information and center position information of multiple template feature points of the template image.
[0088] It should be noted that the thinned edge is not single-pixel wide, so the edge is thinned by single pixel to obtain a 1-pixel wide edge point. In this embodiment, the thinned edge of the template image is processed by single pixel to obtain a 1-pixel wide template feature point, and then the directional feature and edge amplitude corresponding to the 1-pixel wide template feature point are obtained.
[0089] It should be noted that by traversing the thinned edge of the template image, the position information and center position information of the template feature points can be obtained.
[0090] Step S142, performing normalization processing based on the directional features and edge amplitudes of the plurality of template feature points to obtain unit directional feature information of the template feature points.
[0091] It should be noted that the horizontal gradient and vertical gradient of the template feature point indicate the directional characteristics of the template feature point. The directional characteristics can be normalized as follows: gx = g x / mag,gy = g y / mag; Among them, g x is the horizontal gradient of the template feature point at the corresponding position, g xis the vertical gradient of the template feature point at the corresponding position, mag is the edge amplitude of the template feature point at the corresponding position, and the obtained (gx, gy) is the unit direction vector of the template feature point, which reflects the unit direction feature of the template feature point. In this embodiment, the normalization process uses the unit direction feature of the template feature point for analysis, which can not only improve the robustness to illumination changes, but also simplify the calculation of the similarity with the feature point to be matched.
[0092] Step S143, obtaining standard position information of the positions of the plurality of template feature points relative to the center of the template image according to the position information and the center position information of the plurality of template feature points.
[0093] It should be noted that normalizing the positions of the template feature points of the template image to the center of the template image can facilitate traversal using a sliding window of the same size as the template image, and based on the position information of multiple template feature points, find the feature points to be matched at the corresponding positions in the window.
[0094] Among them, the template features are specifically: mod={x i -c x , y i -c y , gx i , gy i}; Among them, mod is the feature information of the i-th template feature point, c x is the horizontal coordinate of the center of the template image, c y is the vertical coordinate of the center of the template image, x i is the horizontal coordinate of the position information of the i-th template feature point, y i is the vertical coordinate of the position information of the i-th template feature point. i is the horizontal coordinate of the unit direction vector of the i-th template feature point, gy i is the vertical coordinate of the unit direction vector of the template feature point. x = w / 2, c y = h / 2, w is the width of the template image, and h is the height of the template image.
[0095] In summary, the present embodiment can extract template features of different pyramid layers from the template image, and can extract standard position information of multiple template feature points, so as to facilitate subsequent traversal and extract feature points to be matched at corresponding positions according to the standard position information of multiple template feature points.
[0096] Based on the first embodiment of the present application, in the seventh embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. On this basis, step S200 includes steps S210~S230: Step S210 , decomposing the image to be matched into a pyramid image sequence of different sizes and resolutions to form a pyramid hierarchical structure from top to bottom.
[0097] Step S220 , in each pyramid layer of the image to be matched, based on the gradient filter, extracting a set of gradient features to be matched whose edge amplitude in the image to be matched is greater than a preset amplitude threshold.
[0098] It should be noted that the Sobel filter can be used for extraction, which has a certain noise resistance and can improve accuracy and stability. Among them, Sobel is divided into horizontal and vertical filters, and the horizontal and vertical gradient maps are obtained by sliding window operation on the matching image respectively. The Sobel filter is shown in Formula 10, Formula 11 and Formula 12 of the sixth embodiment, which will not be repeated here.
[0099] In this embodiment, the horizontal gradient g can be calculated by a Sobel filter. x Figure 1, i.e. the horizontal gradient information set, represents the grayscale change of the image to be matched in the horizontal direction, and shows the intensity and direction of the horizontal edge of the image; calculate the vertical gradient g y The vertical gradient information set represents the grayscale change of the image to be matched in the vertical direction, showing the strength and direction of the vertical edge in the image; the amplitude mag map, i.e. the amplitude information set, reflects the strength of the edge in the image to be matched. If the amplitude mag is greater than the preset amplitude threshold, the g at the corresponding position is retained. x , g y , mag value is called a valid value, otherwise it is invalid and set to zero. In this way, pixels below the preset amplitude threshold can be regarded as noise or irrelevant details, thereby preventing these pixels from interfering with the edge detection results.
[0100] Step S230: performing normalization processing based on the to-be-matched gradient feature set to obtain unit direction feature information of the to-be-matched image and edge amplitude information within a preset range.
[0101] It should be noted that the normalization process for the directional features of the image to be matched is as follows: gx = g x / mag,gy = g y / mag; Among them, g x is the horizontal gradient of the feature point to be matched at the corresponding position, g xis the vertical gradient of the feature point to be matched at the corresponding position, mag is the edge amplitude of the feature point to be matched at the corresponding position, and the obtained (gx, gy) is the unit direction vector of the feature point to be matched at the corresponding position, reflecting the unit direction feature information of the feature point to be matched. In this embodiment, the normalization process can improve the robustness of template matching to illumination changes, and can also simplify the calculation when performing similarity matching with template feature points.
[0102] In this embodiment, the edge amplitude of the feature point to be matched is also normalized to 0-255, which can unify the amplitude range of the feature points so that different feature points have similar scales, which is convenient for comparison and matching.
[0103] In this embodiment, feature information of the image to be matched can be obtained, so that when traversing using a sliding window of the same size as the template image, feature points to be matched at corresponding positions in the window can be extracted at each pixel position based on the position information of multiple template feature points, and feature information of multiple feature points to be matched in the window can be extracted based on the feature information of the image to be matched.
[0104] In the eighth embodiment of the present application, in order to help understand the implementation process of the image contour template matching method obtained by combining this embodiment with the above-mentioned embodiments, please refer to Figure 2 , Figure 3 and Figure 4 , the method specifically includes: Step S110 , decomposing the template image into pyramid image sequences of different sizes and resolutions to form a pyramid hierarchical structure from top to bottom.
[0105] Step S120, in each pyramid layer of the template image, based on the gradient filter, extracting the template gradient feature set whose edge amplitude in the template image is greater than a preset amplitude threshold; wherein the template gradient feature set includes a horizontal gradient information set, a vertical gradient information set and an edge amplitude information set.
[0106] Step S130, performing non-maximum suppression on the edge amplitude information set of the template image to obtain a refined edge of the template image.
[0107] Step S141 , single-pixel processing is performed on the thinned edge of the template image and traversal is performed to obtain direction features, edge amplitudes, position information and center position information of multiple template feature points of the template image.
[0108] Step S142, performing normalization processing based on the directional features and edge amplitudes of the plurality of template feature points to obtain unit directional feature information of the template feature points.
[0109] Step S143, obtaining standard position information of the positions of the plurality of template feature points relative to the center of the template image according to the position information and the center position information of the plurality of template feature points.
[0110] It should be noted that the horizontal gradient and vertical gradient of the template feature point indicate the directional characteristics of the template feature point. The directional characteristics are normalized as follows: gx = g x / mag,gy = g y / mag; Among them, g x is the horizontal gradient of the template feature point at the corresponding position, g x is the vertical gradient of the template feature point at the corresponding position, mag is the edge amplitude of the template feature point at the corresponding position, and the obtained (gx, gy) is the unit direction vector of the template feature point, which reflects the unit direction feature of the template feature point. In this embodiment, the normalization process uses the unit direction feature of the template feature point for analysis, which can not only improve the robustness to illumination changes, but also simplify the calculation of the similarity with the feature point to be matched.
[0111] It should be noted that normalizing the positions of the template feature points of the template image to the center of the template image can facilitate traversal using a sliding window of the same size as the template image, and based on the position information of multiple template feature points, find the feature points to be matched at the corresponding positions in the window.
[0112] Among them, the template features are specifically: mod={x i -c x , y i -c y , gx i , gy i}; Among them, mod is the feature information of the i-th template feature point, c x is the horizontal coordinate of the center of the template image, c y is the vertical coordinate of the center of the template image, x i is the horizontal coordinate of the position information of the i-th template feature point, y i is the vertical coordinate of the position information of the i-th template feature point. i is the horizontal coordinate of the unit direction vector of the i-th template feature point, gy i is the vertical coordinate of the unit direction vector of the template feature point. x = w / 2, c y = h / 2, w is the width of the template image, and h is the height of the template image.
[0113] In summary, steps S110 to S140 can extract template features of different pyramid layers from the template image, and can extract standard position information of multiple template feature points, so as to facilitate subsequent traversal and extract feature points to be matched at corresponding positions according to the standard position information of multiple template feature points.
[0114] Step S210 , decomposing the image to be matched into pyramid image sequences of different sizes and resolutions to form a pyramid hierarchical structure from top to bottom.
[0115] Step S220 , in each pyramid layer of the image to be matched, based on the gradient filter, extracting a set of gradient features to be matched whose edge amplitude in the image to be matched is greater than a preset amplitude threshold.
[0116] Step S230: performing normalization processing based on the to-be-matched gradient feature set to obtain unit direction feature information of the to-be-matched image and edge amplitude information within a preset range.
[0117] It should be noted that the normalization process for the directional features of the image to be matched is as follows: gx = g x / mag,gy = g y / mag; Among them, g x is the horizontal gradient of the feature point to be matched at the corresponding position, g x is the vertical gradient of the feature point to be matched at the corresponding position, mag is the edge amplitude of the feature point to be matched at the corresponding position, and the obtained (gx, gy) is the unit direction vector of the feature point to be matched at the corresponding position, reflecting the unit direction feature information of the feature point to be matched. In this embodiment, the normalization process can improve the robustness of template matching to illumination changes, and can also simplify the calculation when performing similarity matching with template feature points.
[0118] In this embodiment, the edge amplitude of the feature point to be matched is also normalized to 0-255, which can unify the amplitude range of the feature points so that different feature points have similar scales, which is convenient for comparison and matching.
[0119] To sum up, steps S210~S23 can obtain the feature information of the image to be matched, so that when using a sliding window of the same size as the template image for traversal, the feature points to be matched at the corresponding positions in the window can be extracted at each pixel position according to the position information of multiple template feature points, and the feature information of multiple feature points to be matched in the window can be extracted according to the feature information of the image to be matched.
[0120] For the convenience of explanation, when sliding traversal is performed, it is recorded that the i-th template feature point at each pixel position corresponds to the i-th feature point to be matched in the window.
[0121] Step S310, based on the pyramid hierarchical structure from top to bottom, traverse the to-be-matched area of the to-be-matched image of the current layer of the pyramid using a sliding window of the same size as the template image, and extract feature information of multiple to-be-matched feature points in the window at each pixel position based on the position information of multiple template feature points and the feature information of the to-be-matched image.
[0122] Step S320 , performing cosine similarity matching on the directional feature information of the plurality of feature points to be matched and the directional feature information of the corresponding template feature points one by one, and calculating a similarity matching score.
[0123] It should be noted that the template feature of the current pyramid layer is mod={x i -c x , y i -c y , gx i ,gy i}; Among them, mod is the feature information of the i-th template feature point, c x is the horizontal coordinate of the center of the template image, c y is the vertical coordinate of the center of the template image, x i is the horizontal coordinate of the position information of the i-th template feature point, y i is the vertical coordinate of the position information of the i-th template feature point. i is the horizontal coordinate of the unit direction vector of the i-th template feature point, gy i is the vertical coordinate of the unit direction vector of the template feature point. x = w / 2, c y = h / 2, w is the width of the template image, and h is the height of the template image.
[0124] The feature information of the feature point to be matched in the current pyramid layer is specifically a unit direction vector (gx, gy); where gx = g x / mag,gy = g y / mag; g x is the horizontal gradient of the feature point to be matched at the corresponding position of the image to be matched, g x is the vertical gradient of the feature point to be matched at the corresponding position of the image to be matched, and mag is the edge amplitude of the feature point to be matched at the corresponding position of the image to be matched. Use the template feature mod to slide row by row and column by column under the current pyramid layer of the image to be matched, and calculate the total similarity matching score s of multiple template feature points and the corresponding feature point to be matched at each position (x, y). If s is greater than or equal to the first preset threshold s T, then find out the position coordinates (x, y) of the pixel position, which are the position coordinates of the target candidate position.
[0125] It should be noted that the similarity calculation between the template feature points and the feature points of the image to be matched can be performed using the cosine of the angle between the two vectors. Specifically, at the pixel position (x, y) of the image to be matched, we have: Formula 1:
[0126] in, is the modulus of the unit direction vector of the template feature point, which is 1; is the modulus of the unit direction vector of the template feature point, which is 1; The cosine of the angle between the unit direction vector of the i-th template feature point and the unit direction vector of the i-th feature point to be matched, that is, the similarity matching score of the two vectors at this point; is the horizontal gradient of the i-th template feature point, is the vertical gradient of the i-th template feature point; is the horizontal gradient of the i-th feature point to be matched, is the vertical gradient of the i-th feature point to be matched.
[0127] Therefore, the similarity calculation is simplified to: Formula 2:
[0128] Formula 3:
[0129] in, is the total score of the similarity match between the unit direction vector of the i template feature points at the pixel position (x, y) of the image to be matched and the i feature points to be matched in the window.
[0130] Step S331 , eliminating similarity matching scores of to-be-matched feature points whose calculation results are negative values, and obtaining a non-negative similarity matching score set.
[0131] Step S332: derive the total similarity matching score at the pixel position based on the non-negative similarity matching score set.
[0132] It should be noted that in order to increase the stability and robustness of the matching, in this embodiment, Formula 4:
[0133] Formula 5:
[0134] Coming Soon When the calculated result is negative, it is set to zero. is the total similarity matching score at the pixel position (x, y) obtained based on the non-negative similarity matching score set.
[0135] Step S340 , searching for a target candidate position whose total similarity matching score at the pixel position is greater than or equal to a first preset threshold value according to the total similarity matching score at the pixel position.
[0136] In summary, steps S310 to S340 can eliminate the negative contribution of the cosine similarity with a negative calculation result to the total similarity matching score, obtain the total similarity matching score at the pixel position, and find the target candidate position whose total similarity matching score is greater than or equal to the first preset threshold. In this way, steps S310 to S340 can preliminarily filter out targets at pixel positions with poor similarity, and eliminate negative similarity matching scores, thereby enhancing the stability of finding similar targets.
[0137] Step S411 , determining an edge amplitude limit threshold according to the similarity matching scores of the plurality of feature points to be matched in the window and the edge amplitudes of the plurality of feature points to be matched.
[0138] It should be noted that in order to improve the accuracy and robustness of feature point matching, it is necessary to weight the similarity matching score according to the contribution of the edge amplitude of the matching feature point. Specifically, it includes: Formula 7:
[0139] In step S230, the value range of the edge amplitude is normalized to 0-255, that is, the value range of the edge amplitude m is [0, 255]. n is the number of feature points to be matched, is the similarity matching score of the i-th feature point to be matched, It is the cumulative sum of all values of the n feature points to be matched on the edge amplitude [0, 255].
[0140] by As the limit, according to: Formula 8:
[0141] It can be calculated that when the two are equal, the value of the edge amplitude m is the edge amplitude threshold m t .
[0142] According to the edge amplitude threshold m t The edge amplitude limit threshold is determined by the second preset proportional coefficient. Specifically, the second preset proportional coefficient can be 0.65, and mt=0.65 *mt .
[0143] Step S412, determining amplitude weighted values of the plurality of feature points to be matched in the window according to the edge amplitudes of the plurality of feature points to be matched in the window and the edge amplitude limit threshold.
[0144] When the edge amplitude of the feature point to be matched is less than the edge amplitude limit threshold, the amplitude weighted value of the feature point to be matched increases as the edge amplitude of the feature point to be matched increases; When the edge amplitude of the feature point to be matched is greater than or equal to the edge amplitude limit threshold, the amplitude weighted value of the feature point to be matched remains unchanged as the edge amplitude of the feature point to be matched increases.
[0145] When the amplitude of the feature point to be matched is greater than or equal to mt, take rate(mag i )=1, otherwise it is a linear increasing relationship, the smaller the amplitude, the greater the amplitude weighting value rate(mag i ) is smaller, the amplitude weighted value of the feature point to be matched changes according to the piecewise function of the amplitude: Formula 9:
[0146] Among them, rate(mag i ) is the amplitude weighted value, mag i is the edge amplitude of the i-th feature point to be matched, and mt is the edge amplitude limit threshold.
[0147] Step S420 , weighting the similarity matching scores of the multiple matching feature points in the window according to the amplitude weighted values of the multiple matching feature points in the window to obtain a weighted total matching score at the target candidate position.
[0148] It should be noted that at the target candidate position (x, y), rate(mag i ) Weight the calculation of formula 4 to obtain the weighted matching total score ,as follows: Formula 6:
[0149] Among them, mag i is the edge amplitude of the feature point to be matched, rate(mag i ) is the amplitude weighted value of the feature point, obtained by formula nine, Obtained by formula 2. Preset rate(mag i ) has a value range of [0, 1], the amplitude weighted value of the feature point to be matched can be determined according to the edge amplitude of the feature point to be matched.
[0150] Step S430, according to the weighted matching total score at the target candidate position, find the target qualified position whose weighted matching total score at the target candidate position is greater than or equal to the second preset threshold, wherein the second preset threshold can be the product of the first preset threshold and the preset first proportionality coefficient.
[0151] It should be noted that the weighted matching total score at the target candidate position can be calculated by Formula 5: , the preset first proportionality coefficient can be k, then the second preset threshold is k*s T , k can be specifically 0.8. Greater than or equal to k*s T , then find out that the target candidate position (x, y) is the qualified target position.
[0152] In summary, steps S410 to S430 can calculate the total weighted matching score at the target candidate position, and perform screening according to the total weighted matching score to find the target qualified position.
[0153] Step S500, mapping the target qualified position of the image to be matched in the current layer of pyramid to the corresponding area of the image to be matched in the next layer of pyramid, constructing the area to be matched in the next layer of pyramid, and repeating steps S300 to S400 until the target qualified position of the image to be matched is found in the bottom layer of pyramid.
[0154] It should be noted that, based on the pyramid hierarchical structure from top to bottom and the pyramid matching strategy from top to bottom, the target qualified position of the current layer can be mapped to the corresponding area of the image to be matched of the next pyramid layer to construct the local area to be matched of the image to be matched of the next layer. Steps S300 to S400 are repeatedly performed in the local area to be matched of the next layer to obtain the target qualified position of the bottom pyramid layer. In this way, the target qualified position of the bottom pyramid layer can be obtained, and the final image matching result can be obtained.
[0155] In this way, the present embodiment divides the image to be matched into different pyramid layers for template matching, thereby reducing the complexity of data processing. Under different pyramid layers, the present embodiment searches for the target qualified position whose weighted matching total score reaches the second preset threshold at different pixel positions of the image to be matched. After the qualified target position is found in the current layer, the qualified target position can be mapped to the next layer of the pyramid based on its position information until the target qualified position of the image to be matched is found in the bottom layer of the pyramid. The present embodiment can improve the accuracy and stability of template matching in complex scenes, and solve the problem of inaccurate and unstable positioning of existing template matching methods in complex scenes.
[0156] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the image contour template matching method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0157] The present application provides an image contour template matching device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the image contour template matching method in the above-mentioned embodiment one.
[0158] Reference below Figure 8 , which shows a schematic diagram of the structure of an image contour template matching device suitable for implementing the embodiment of the present application. The image contour template matching device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The image contour template matching device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0159] like Figure 8As shown, the image contour template matching device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the image contour template matching device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the image contour template matching device to communicate with other devices wirelessly or by wire to exchange data. Although the image contour template matching device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided alternatively.
[0160] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application 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 such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0161] The image contour template matching device provided by the present application adopts the image contour template matching method in the above embodiment, which can solve the technical problems of inaccurate and unstable positioning of the existing template matching method in complex scenes. Compared with the prior art, the beneficial effects of the image contour template matching device provided by the present application are the same as the beneficial effects of the image contour template matching method provided by the above embodiment, and the other technical features in the image contour template matching device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0162] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0163] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. An image contour template matching method, characterized in that: The steps of the method include: S100, acquiring template feature information of each layer of the pyramid of the template image, where the template feature information includes feature information of a plurality of template feature points; S200, obtaining feature information of the image to be matched of each layer of the pyramid of the image to be matched; S300, based on the pyramid hierarchical structure from top to bottom, in the to-be-matched area of the to-be-matched image of the current layer of the pyramid, a sliding window of the same size as the template image is used to traverse, and based on the position information of the multiple template feature points and the feature information of the to-be-matched image, feature information of the multiple to-be-matched feature points in the window is extracted at each pixel position; the feature information of the multiple to-be-matched feature points is similarly matched with the feature information of the corresponding template feature points one by one to obtain a similarity matching score, and a target candidate position whose total similarity matching score at the pixel position is greater than or equal to a first preset threshold is found; wherein the feature information of the multiple template feature points includes position information; S400, at each target candidate position, weighting the similarity matching scores of the multiple feature points to be matched in the window according to the edge amplitudes of the multiple feature points to be matched, and finding a target qualified position at the target candidate position whose total weighted matching score is greater than or equal to a second preset threshold; wherein the feature information of the feature points to be matched includes edge amplitude information; S500, mapping the target qualified position of the image to be matched in the current layer of pyramid to the corresponding area of the image to be matched in the next layer of pyramid, constructing the area to be matched in the next layer of pyramid, and repeating steps S300 to S400 until the target qualified position of the image to be matched is found in the bottom layer of pyramid.
2. The method according to claim 1, characterized in that The feature information includes directional feature information, and the steps of performing similarity matching one by one between the feature information of the plurality of feature points to be matched and the feature information of the corresponding template feature points to obtain a similarity matching score, and finding a target candidate position whose total similarity matching score at the pixel position reaches a first preset threshold include: Perform cosine similarity matching on the directional feature information of multiple feature points to be matched and the directional feature information of corresponding template feature points one by one, and calculate a similarity matching score; According to the similarity matching scores of multiple feature points to be matched, a total similarity matching score at the pixel position is obtained; According to the total similarity matching score at the pixel position, a target candidate position whose total similarity matching score at the pixel position is greater than or equal to a first preset threshold is found.
3. The method according to claim 2, characterized in that The step of obtaining the total similarity matching score at the pixel position according to the similarity matching scores of the plurality of feature points to be matched comprises: Eliminate the similarity matching scores of the feature points to be matched whose calculation results are negative values, and obtain a non-negative similarity matching score set; Based on the set of non-negative similarity matching scores, the total similarity matching score at the pixel position is obtained.
4. The method according to claim 1, characterized in that The step of weighting the similarity matching scores of the plurality of feature points to be matched according to the edge amplitudes of the plurality of feature points to be matched in the window, and finding a target qualified position at the target candidate position whose total weighted matching score is greater than or equal to a second preset threshold comprises: Determine amplitude weight values of multiple matching feature points in the window according to edge amplitudes of multiple to-be-matched feature points in the window; According to the amplitude weighted values of the multiple matching feature points in the window, the similarity matching scores of the multiple matching feature points in the window are weighted to obtain the weighted matching total score at the target candidate position; According to the weighted matching total score at the target candidate position, a target qualified position whose weighted matching total score at the target candidate position is greater than or equal to a second preset threshold is found.
5. The method according to claim 4, characterized in that The step of determining the amplitude weighted values of the plurality of matching feature points in the window according to the edge amplitudes of the plurality of to-be-matched feature points in the window comprises: Determine an edge amplitude limit threshold according to the similarity matching scores of the multiple feature points to be matched in the window and the edge amplitudes of the multiple feature points to be matched; According to the edge amplitudes of the multiple feature points to be matched in the window and the edge amplitude limit threshold, the amplitude weighted values of the multiple feature points to be matched in the window are determined; wherein, When the edge amplitude of the feature point to be matched is less than the edge amplitude limit threshold, the amplitude weighted value of the feature point to be matched increases as the edge amplitude of the feature point to be matched increases; When the edge amplitude of the feature point to be matched is greater than or equal to the edge amplitude limit threshold, the amplitude weighted value of the feature point to be matched remains unchanged as the edge amplitude of the feature point to be matched increases.
6. The method according to claim 1, characterized in that The step S100 includes: Decompose the template image into a pyramid image sequence of different sizes and resolutions to form a pyramid hierarchical structure from top to bottom; In each pyramid layer of the template image, based on the gradient filter, a template gradient feature set whose edge amplitude in the template image is greater than a preset amplitude threshold is extracted; wherein the template gradient feature set includes a horizontal gradient information set, a vertical gradient information set and an edge amplitude information set; Perform non-maximum suppression on the edge amplitude information set of the template image to obtain a refined edge of the template image; Single-pixel processing is performed on the thinned edge of the template image and traversal is performed to obtain directional feature information and position information of multiple template feature points of the template image.
7. The method according to claim 6, characterized in that The directional feature information includes unit directional feature information, and the position information includes standard position information; the step of performing single-pixel processing on the thinned edge of the template image and traversing to obtain feature information of multiple template feature points of the template image includes: Single-pixel processing is performed on the thinned edge of the template image and traversal is performed to obtain the directional characteristics, edge amplitude, position information and center position information of multiple template feature points of the template image; Based on the directional features and edge amplitudes of multiple template feature points, normalization processing is performed to obtain unit directional feature information of the template feature points; According to the position information and the center position information of the plurality of template feature points, the standard position information of the positions of the plurality of template feature points relative to the center of the template image is obtained.
8. The method according to claim 1, characterized in that The image feature information to be matched includes directional feature information and edge amplitude information; the step S200 includes: Decompose the image to be matched into a pyramid image sequence of different sizes and resolutions to form a pyramid hierarchical structure from top to bottom; In each pyramid layer of the image to be matched, based on the gradient filter, a gradient feature set to be matched whose edge amplitude in the image to be matched is greater than a preset amplitude threshold is extracted; The gradient feature set to be matched includes a horizontal gradient information set, a vertical gradient information set and an edge amplitude set; the horizontal gradient information set and the vertical gradient information set are used to indicate directional feature information, and the edge amplitude set is used to indicate edge amplitude information.
9. The method according to claim 8, characterized in that The directional feature information includes a unit directional feature, and the edge amplitude information is set within a preset range; after the step of extracting, in each layer of the pyramid of the image to be matched, a gradient feature set to be matched whose edge amplitude in the image to be matched is greater than a preset amplitude threshold based on a gradient filter, the step S200 further includes: Based on the gradient feature set to be matched, normalization processing is performed to obtain unit direction feature information of the image to be matched and edge amplitude information within a preset range.
10. An image contour template matching device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the image contour template matching method according to any one of claims 1 to 9.