A matching template generation method and device, electronic equipment and storage medium
By filtering valid contour points during the image matching process and generating matching templates, the problem of low accuracy caused by changes in angle and lighting conditions is solved, thus improving the accuracy of image matching.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU HIKROBOT TECH CO LTD
- Filing Date
- 2023-08-14
- Publication Date
- 2026-05-05
AI Technical Summary
Existing matching templates have low accuracy during image matching due to changes in angle and lighting conditions, and are prone to missed detections and false detections.
An initial template is generated by acquiring multiple template images and target images, and valid contour points are selected based on the matching results to generate the final matching template.
It improves the accuracy of image matching and reduces missed detections and false detections.
Smart Images

Figure CN117152469B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image matching technology, and in particular to a method, apparatus, electronic device and storage medium for generating matching templates. Background Technology
[0002] Template matching is a widely used visual matching algorithm. Electronic devices can match the position, angle and size of the target in the image to be processed based on the matching between the contour points of the target in the pre-generated matching template and the contour points of the object to be searched in the image to be processed. In this way, a score reflecting the degree of matching between the target in the image to be processed and the target in the matching template can be obtained.
[0003] In the above method, the matching template is generated based on an image of the target taken at a certain angle and under certain lighting conditions. However, in actual image matching, the acquisition angle, lighting conditions, etc. of the image to be processed may differ significantly from the conditions corresponding to the matching template. This results in a large number of contour points of the object to be searched in the image to be processed failing to match the contour points of the target in the matching template. Therefore, a method of lowering the score threshold can be used to adapt to the changes in conditions. However, this method is prone to missed detections. Therefore, the accuracy of image matching based on the above matching template is currently low. Summary of the Invention
[0004] The purpose of this application is to provide a method, apparatus, electronic device, and storage medium for generating matching templates to improve the accuracy of image matching. The specific technical solution is as follows:
[0005] In a first aspect, embodiments of this application provide a method for generating a matching template, the method comprising:
[0006] Obtain a first number of template images and a second number of target images;
[0007] For each template image, an initial template is generated based on the contour points of the target in the template image;
[0008] For each initial template, the targets included in each target image are matched based on the contour points included in the initial template to obtain the corresponding matching results;
[0009] Based on the matching results, the contour points included in the initial template are filtered to obtain the filtered contour points.
[0010] Based on the filtered contour points, a matching template for the target is generated.
[0011] Optionally, the first quantity and / or the second quantity may be multiple;
[0012] The step of matching the targets included in each target image based on the contour points included in each initial template to obtain the corresponding matching result includes:
[0013] For each initial template, each contour point included in the initial template is matched with the contour points of the target included in each target image to obtain the matching state corresponding to each contour point included in the initial template, which is used as the matching result;
[0014] The matching state includes a first state and a second state. The first state is used to indicate that the contour point has a matching contour point in the corresponding target image, and the second state is used to indicate that the contour point does not have a matching contour point in the corresponding target image.
[0015] Optionally, the step of filtering the contour points included in the initial template based on the matching result to obtain the filtered contour points includes:
[0016] For each initial template, based on the matching status between each contour point included in the initial template and the corresponding contour point in the target image, the ratio between the third quantity and the fourth quantity of each contour point is calculated, wherein the third quantity is the number of contour points whose matching status is the first state, and the fourth quantity is the number of contour points whose matching status is the second state.
[0017] For each initial template containing contour points, those contour points with a proportion less than the first preset threshold are deleted to obtain the filtered contour points.
[0018] Optionally, the second quantity can be multiple;
[0019] Before the step of calculating the ratio between the third and fourth quantities of each contour point based on the matching status between each contour point included in the initial template and the corresponding contour point in the target image for each initial template, the method further includes:
[0020] For each initial template, based on the matching status between the contour points included in each target image and the contour points included in the initial template, the ratio between the fifth number and the sixth number of contour points included in each target image is calculated. The fifth number is the number of contour points in the target image whose matching status is the third state, and the sixth number is the number of contour points in the target image whose matching status is the fourth state. The third state is used to indicate that the contour point has a matching contour point in the corresponding initial template, and the fourth state is used to indicate that the contour point does not have a matching contour point in the corresponding initial template.
[0021] Based on the relationship between the proportion of each target image and the second preset threshold, a valid matching image is determined from the target images;
[0022] The step of calculating the ratio between the third and fourth quantities of each contour point for each initial template, based on the matching status between each contour point included in the initial template and the corresponding contour point in the target image, includes:
[0023] For each initial template, the ratio between the third and fourth quantities of each contour point is calculated based on the matching status between each contour point included in the initial template and the corresponding contour point in the effective matching image.
[0024] Optionally, after the step of deleting contour points with a corresponding proportion less than a first preset threshold to obtain filtered contour points, the method further includes:
[0025] If the target image includes an invalid matching image, return to the step of matching each contour point included in the initial template with the contour points of the target included in each target image to obtain the matching status corresponding to each contour point included in the initial template, until the ratio between the fifth and sixth number of contour points included in each target image reaches the second preset threshold, wherein the invalid matching image is an image in the target image other than the valid matching image.
[0026] Optionally, the step of generating a matching template for the target based on the filtered contour points includes:
[0027] Based on the pose of the contour points corresponding to each initial template, the filtered contour points included in the initial template are mapped to the same coordinate system;
[0028] The mapped contour points are then fused to obtain a matching template for the target.
[0029] Optionally, the step of fusing the mapped contour points to obtain a matching template for the target includes:
[0030] The initial template is divided into multiple grids according to a preset method;
[0031] For each grid cell, calculate the average coordinates of all mapped contour points included in that grid cell;
[0032] The average coordinates are used as the positions of the contour points included in the grid to obtain the matching template of the target.
[0033] Secondly, embodiments of this application provide a template generation apparatus, the apparatus comprising:
[0034] The image acquisition module is used to acquire a first number of template images and a second number of target images;
[0035] The initial template generation module is used to generate an initial template for each template image based on the contour points of the target in the template image;
[0036] The target matching module is used to match the targets included in each target image based on the contour points included in the initial template for each initial template, and obtain the corresponding matching results;
[0037] The contour point filtering module is used to filter the contour points included in the initial template based on the matching results to obtain the filtered contour points.
[0038] The matching template generation module is used to generate a matching template for the target based on the filtered contour points.
[0039] Optionally, the first quantity and / or the second quantity may be multiple;
[0040] The target matching module includes:
[0041] The matching result acquisition submodule is used to match each contour point included in the initial template with the contour points of the target included in each target image for each initial template, and obtain the matching status corresponding to each contour point included in the initial template as the matching result;
[0042] The matching state includes a first state and a second state. The first state is used to indicate that the contour point has a matching contour point in the corresponding target image, and the second state is used to indicate that the contour point does not have a matching contour point in the corresponding target image.
[0043] Optionally, the contour point filtering module includes:
[0044] The ratio calculation submodule is used to calculate the ratio between the third quantity and the fourth quantity of each contour point for each initial template, based on the matching status between each contour point included in the initial template and the corresponding contour point in the target image. The third quantity is the number of contour points whose matching status is the first state, and the fourth quantity is the number of contour points whose matching status is the second state.
[0045] The contour point deletion submodule is used to delete contour points whose proportion is less than a first preset threshold for each initial template, thus obtaining the filtered contour points.
[0046] Optionally, the second quantity can be multiple;
[0047] The device further includes:
[0048] The ratio calculation module is used to calculate, for each initial template, the ratio between the fifth number and the sixth number of contour points included in each target image, based on the matching status between the contour points included in each target image and the contour points included in the initial template. The fifth number is the number of contour points in the target image whose matching status is the third state, and the sixth number is the number of contour points in the target image whose matching status is the fourth state. The third state is used to indicate that the contour point has a matching contour point in the corresponding initial template, and the fourth state is used to indicate that the contour point does not have a matching contour point in the corresponding initial template.
[0049] The effective matching image determination module is used to determine effective matching images from the target images based on the relationship between the proportion of each target image and a second preset threshold.
[0050] Optionally, the ratio calculation submodule includes:
[0051] The ratio calculation unit is used to calculate the ratio between the third and fourth quantities of each contour point for each initial template, based on the matching status between each contour point included in the initial template and the corresponding contour point in the effective matching image.
[0052] Optionally, the device further includes:
[0053] The matching status acquisition module is used to, for the target image including invalid matching images, return to execute the step of matching each contour point included in the initial template with the contour points of the target included in each target image to obtain the matching status corresponding to each contour point included in the initial template, until the ratio between the fifth and sixth numbers of contour points included in each target image reaches a second preset threshold, wherein the invalid matching image is an image in the target image other than the valid matching image.
[0054] Optionally, the matching template generation module includes:
[0055] The contour point mapping submodule is used to map the filtered contour points included in the initial template to the same coordinate system according to the contour point pose corresponding to each initial template.
[0056] The matching template acquisition submodule is used to fuse the mapped contour points to obtain the matching template of the target.
[0057] Optionally, the matching template acquisition submodule includes:
[0058] A grid division unit is used to divide the initial template into multiple grids according to a preset method;
[0059] The average value calculation sub-unit is used to calculate the average coordinates of the mapped contour points included in each grid cell.
[0060] A matching template generation sub-unit is used to obtain the matching template of the target by taking the average coordinate value as the position of the contour points included in the grid.
[0061] Thirdly, embodiments of this application provide an electronic device, including:
[0062] Memory, used to store computer programs;
[0063] When a processor executes a program stored in memory, it implements any of the methods described in the first aspect above.
[0064] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the methods described in the first aspect above.
[0065] Beneficial effects of the embodiments in this application:
[0066] In the solution provided in this application embodiment, the electronic device can acquire a first number of template images and a second number of target images; for each template image, an initial template is generated based on the contour points of the target in the template image; for each initial template, the target included in each target image is matched based on the contour points included in the initial template to obtain a corresponding matching result; based on the matching result, the contour points included in the initial template are filtered to obtain filtered contour points; and a matching template for the target is generated based on the filtered contour points. Since the electronic device can filter the contour points included in the initial template according to the matching result, it can filter out contour points in the initial template that have poor matching results with the target in the target image, and then generate a matching template for the target based on the filtered contour points. This improves the accuracy of image matching, rather than simply generating the template based on an image of the target taken under certain conditions.
[0067] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0068] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0069] Figure 1 This is a schematic diagram of a template image in related technologies;
[0070] Figure 2 for Figure 1 A schematic diagram of the image to be processed corresponding to the matching template shown;
[0071] Figure 3 for Figure 1 Another schematic diagram of the image to be processed corresponding to the matching template shown;
[0072] Figure 4 This is another schematic diagram of template images in related technologies;
[0073] Figure 5 for Figure 4 A schematic diagram of the image to be processed corresponding to the matching template shown;
[0074] Figure 6 A flowchart illustrating a method for generating a matching template as provided in an embodiment of this application;
[0075] Figure 7 For based on Figure 6 The illustrated embodiment is for Figure 4 This is a schematic diagram of an initial template obtained by filtering the contour points included in the matching template.
[0076] Figure 8 For based on Figure 6 A flowchart of a contour point filtering method in the illustrated embodiment;
[0077] Figure 9 For based on Figure 8 A flowchart of an effective matching image determination method in the embodiment shown;
[0078] Figure 10 for Figure 6 A specific flowchart of step S605 in the illustrated embodiment;
[0079] Figure 11 for Figure 10 A specific flowchart of step S1002 in the illustrated embodiment;
[0080] Figure 12 A schematic diagram of the structure of a matching template generation device provided in an embodiment of this application;
[0081] Figure 13 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0082] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0083] In current related technologies, matching templates are generated based on images of the target taken at a certain angle and under specific lighting conditions. For example, matching templates can be based on... Figure 1 The template image shown is generated. Figure 1 The target is a triangular object with its apex facing right. The contour points of the target in the generated matching template are... Figure 1 The outline points of the target object, that is, the outer contour of the triangle.
[0084] After generating the matching template, the electronic device can determine the target's position, angle, and size in the image to be processed based on the matching between the contour points of the target in the matching template and the contour points of the object to be searched in the image to be processed. This results in a score reflecting the degree of matching between the target in the image to be processed and the target in the matching template. A higher degree of matching leads to a higher score, specifically, a higher degree of matching when the contour points of the target in the matching template have a larger number of matching contour points in the corresponding image to be processed.
[0085] The score output by the electronic device is greatly affected by the completeness of the target's outline in the image to be processed. If the target is relatively complete, the outline points of the target in the matching template match the corresponding image to be processed to a high degree, and the score output by the electronic device is high. If the object to be searched is partially missing, the score output by the electronic device is low.
[0086] For example, the image to be processed can be as follows: Figure 2 and Figure 3 As shown. Figure 2 The goal in it is complete, and Figure 3 The target part is missing. If the score is a value between 0 and 1, the higher the value, the higher the degree of matching. Then the electronic device... Figure 1 The contour points of the target in the matching template shown are Figure 2 and Figure 3 The matching results between the contour points of the target are obtained respectively. Figure 2 and Figure 3The corresponding scores can be 1.0 and 0.71.
[0087] After obtaining the score, the electronic device can compare the score with a pre-set score threshold. If the score reaches the threshold, it means that the image to be processed has successfully matched the matching template; if the score does not reach the threshold, it means that the image to be processed has failed to match the matching template.
[0088] In the above method, the matching template is generated based on an image of the target taken at a certain angle and under specific lighting conditions. However, in actual image matching, the acquisition angle and lighting conditions of the image to be processed may differ significantly from the conditions corresponding to the matching template. This could result in a large number of contour points of the target in the image to be processed failing to match the contour points of the target in the matching template. Consequently, the output score is significantly reduced, possibly even falling below the threshold, leading to missed detections.
[0089] For example, the matching template can be based on, such as Figure 4 The template image shown is generated. Figure 4 The target in the image appears as a triangle with multiple circles irregularly distributed inside. The contour points of the target in the generated matching template are... Figure 4 The outer contour of the triangle and the contour points included in the circumference of each circle.
[0090] If based on Figure 4 The contour points of the target in the matching template shown are Figure 5 Matching the contour points of the target in the image, then because... Figure 5 The angle of the target in the middle, etc. Figure 4 The targets differed significantly, leading to Figure 5 The outline points of the target contain a large number of points that cannot be matched. Figure 4 The contour points shown in the matching template are successfully matched. Therefore, the score output by the electronic device is low. For example, it could be 0.58.
[0091] If the preset score threshold is 0.6 points, then because Figure 5 The corresponding score did not reach the score threshold, therefore based on Figure 4 The matching template shown is Figure 5 The image to be processed shown failed to match. However, due to... Figure 5 The goal in fact is indeed Figure 4 The target in the image is not accurately matched, leading to missed detections. To accommodate changes in the target and reduce missed detections, a lower score threshold is usually set. However, this approach is prone to false positives. Therefore, the accuracy of image matching based on the above matching template is currently low.
[0092] To improve the accuracy of image matching, embodiments of this application provide a method, apparatus, electronic device, computer-readable storage medium, and computer program product for generating matching templates. The method for generating matching templates provided in this application embodiment will be described first below.
[0093] The matching template generation method provided in this application can be applied to any electronic device that needs to generate matching templates, such as an image processing device or an image matching device, etc., without specific limitations. For clarity, it will be referred to as an electronic device below.
[0094] like Figure 6 As shown, a method for generating a matching template includes:
[0095] S601, Obtain a first number of template images and a second number of target images;
[0096] S602, For each template image, an initial template is generated based on the contour points of the target in the template image;
[0097] S603, For each initial template, match the target included in each target image based on the contour points included in the initial template to obtain the corresponding matching result;
[0098] S604, Based on the matching result, the contour points included in the initial template are filtered to obtain the filtered contour points;
[0099] S605, Generate a matching template for the target based on the filtered contour points.
[0100] As can be seen, the electronic device can acquire a first number of template images and a second number of target images. For each template image, an initial template is generated based on the contour points of the target in the template image. For each initial template, the target in each target image is matched based on the contour points included in the initial template to obtain the corresponding matching result. Based on the matching result, the contour points included in the initial template are filtered to obtain filtered contour points. Based on the filtered contour points, a matching template for the target is generated. Since the electronic device can filter the contour points included in the initial template according to the matching result, it can filter out contour points in the initial template that have poor matching results with the target in the target image, and then generate a matching template for the target based on the filtered contour points. This is not based solely on an image of the target taken under certain conditions to generate a template, thus improving the accuracy of image matching.
[0101] In step S601 above, the electronic device can acquire a first number of template images and a second number of target images. There are four possible values for the first number and the second number: the first number is one and the second number is multiple; the second number is multiple and the second number is one; the third number is multiple for both the first number and the second number; and the fourth number is one for both the first number and the second number.
[0102] The template image contains the same target as the target image. In the first case where there are multiple template images, the target content of the multiple template images varies to some extent, that is, the acquisition angle, lighting conditions, etc., corresponding to the targets contained in the multiple template images are different. In the second case where there are multiple target images, the target content of the multiple target images varies to some extent, that is, the acquisition angle, lighting conditions, etc., corresponding to the targets contained in the multiple target images are different.
[0103] In one implementation, the target image can be a template image. Thus, in step S601, the electronic device can acquire only multiple template images and use these multiple template images simultaneously as the target image for matching in subsequent steps.
[0104] In order to match the template image with the target image, for each template image, the electronic device can generate an initial template based on the contour points of the target in the template image, i.e., execute step S602.
[0105] For example, if the electronic device acquires five template images in step S601, and these five template images contain the same target but differ in acquisition angle, lighting conditions, etc., then for each template image, the electronic device can generate initial templates M1, M2, M3, M4, and M5 corresponding to the five template images based on the contour points of the target in the template image.
[0106] If a target in each target image is matched based on the contour points included in the initial template, and a certain contour point in the matching result does not have a corresponding contour point in many target images, then it means that when this contour point is used as a contour point in the matching template, it may reduce the accuracy of matching the target in the image to be processed using the matching template in the subsequent process.
[0107] Therefore, in order to filter the contour points included in the initial template, the electronic device can, for each initial template, match the targets included in each target image based on the contour points included in the initial template to obtain the corresponding matching results, i.e., execute step S603. The matching results may include the matching state corresponding to each contour point in the initial template, and the pose corresponding to each contour point in the target image.
[0108] If the matching results show that no contour point in the initial template is found to match a certain contour point in a large number of target images, it indicates that the contour point has a poor matching effect on the target images, and this will lead to a decrease in the accuracy of image matching. Therefore, the electronic device can filter the contour points included in the initial template based on the matching results to obtain the filtered contour points, i.e., execute step S604.
[0109] For example, if the initial template is like Figure 4 As shown, the electronic device can then use this initial template to... Figure 5 The target image is matched to obtain the corresponding matching results. In the matching results, since there are almost no contour points in the target image that correspond to the circular parts in the initial template, but there are a large number of contour points that correspond to the contour points of the triangular parts in the initial template, the electronic device can remove the contour points of the circular parts in the initial template and retain the contour points of the triangular parts.
[0110] In this way, after filtering the initial template, the contour points retained in the initial template are those points with a high probability of successful matching in the target image, thus effectively reducing the occurrence of missed detections and false detections. Subsequently, the electronic device can generate a matching template for the target based on the filtered contour points, i.e., execute step S605.
[0111] Continuing from the previous example, the outline points of the initial template after filtering are the outline points of the triangle portion. Electronic devices can filter out elements such as... Figure 4 The outline points of the circular part in the initial template shown are used to generate the following: Figure 7 The matching template for the target shown.
[0112] As can be seen, in this embodiment, since the electronic device can filter the contour points included in the initial template according to the matching results, it can filter out contour points in the initial template that have poor matching results with the target in the target image, and then generate a matching template for the target based on the filtered contour points. Instead of generating the template solely based on an image of the target taken under certain conditions, this improves the accuracy of image matching.
[0113] As one embodiment of this application, the first quantity and / or the second quantity described above are multiple;
[0114] The steps described above, which involve matching the targets in each target image based on the contour points included in each initial template to obtain the corresponding matching results, may include:
[0115] For each initial template, each contour point included in the initial template is matched with the contour points of the target included in each target image to obtain the matching state corresponding to each contour point included in the initial template, which is used as the matching result.
[0116] The matching state includes a first state and a second state. The first state is used to indicate that the contour point has a matching contour point in the corresponding target image, and the second state is used to indicate that the contour point does not have a matching contour point in the corresponding target image.
[0117] If a contour point in the initial template has no matching contour points in many target images, it indicates that the matching effect of that contour point is poor. If this contour point is not filtered out, the matching results corresponding to the target images may be inaccurate.
[0118] Therefore, in order to filter out contour points with poor matching results among the contour points included in the initial template, the electronic device can determine the matching status of the contour points included in the initial template in the target image. Thus, for each initial template, the electronic device can match each contour point included in the initial template with the contour points of the target included in each target image to obtain the matching status of each contour point included in the initial template as the matching result.
[0119] The matching state includes a first state and a second state. The first state indicates that the contour point has a matching contour point in the corresponding target image, i.e., a successfully matched contour point. The second state indicates that the contour point does not have a matching contour point in the corresponding target image, i.e., a failed match.
[0120] The first quantity and / or the second quantity mentioned above can be multiple. That is to say, there are three possible values for the first quantity and the second quantity: the first is one and the second is multiple; the second is multiple and the second is one; and the third is multiple for both the first and the second.
[0121] In one implementation, the first quantity is multiple, and the second quantity is multiple. That is, there are multiple template images and multiple target images. The electronic device can generate an initial template corresponding to each template image. For each initial template, each contour point included in the initial template is matched with the contour points of the target included in each target image to obtain the matching state corresponding to each contour point included in the initial template, which is used as the matching result.
[0122] In another implementation, the first quantity is one, and the second quantity is multiple. That is, there is one template image and multiple target images. The electronic device can generate an initial template corresponding to the template image, and match each contour point included in the initial template with the contour points of the target included in each target image to obtain the matching state corresponding to each contour point in the initial template, which is used as the matching result.
[0123] In another implementation, the first quantity is multiple, and the second quantity is one. That is, there are multiple template images and one target image. The electronic device can generate an initial template corresponding to each template image, and for each initial template, match each contour point included in the initial template with the contour points of the target included in the target image to obtain the matching state corresponding to each contour point in the initial template, which is used as the matching result.
[0124] As can be seen, the electronic device can match each contour point included in the initial template with the contour points of the target objects included in each target image, obtaining the matching state corresponding to each contour point included in the initial template as the matching result. In this way, the electronic device can subsequently filter contour points based on the matching results, thereby improving the accuracy of image matching. Since the first and / or second number are multiple, the electronic device can filter the contour points included in the initial template based on the matching results corresponding to multiple target images, or, based on the matching results corresponding to the target images, filter the contour points included in multiple initial templates. This can further improve the contour point filtering effect.
[0125] As one implementation method of this application, such as Figure 8 As shown, the step of filtering the contour points included in the initial template based on the matching results to obtain the filtered contour points may include:
[0126] S801, For each initial template, based on the matching status between each contour point included in the initial template and the corresponding contour point in the target image, calculate the ratio between the third number and the fourth number of each contour point;
[0127] Wherein, the third quantity is the number of contour points whose matching state is the first state corresponding to the contour point, and the fourth quantity is the number of contour points whose matching state is the second state corresponding to the contour point.
[0128] If a certain contour point has a high proportion of matching states in the second state, it means that the contour point does not have a matching contour point in most target images, and the contour point can be removed. Therefore, a filtering condition can be a high proportion of matching states in the second state. To determine contour points that meet the above filtering conditions, the electronic device can, for each initial template, calculate the ratio between the third and fourth quantities of each contour point based on the matching state between each contour point included in the initial template and the corresponding contour point in the target image.
[0129] The third quantity is the number of contour points whose matching state is the first state, and the fourth quantity is the number of contour points whose matching state is the second state.
[0130] For example, if there are 10 target images, and the initial template includes a certain contour point, in the matching states between the contour point and the corresponding contour point in each target image, the number of matching states in the first state is 7, and the number of matching states in the second state is 3. This means that the third number of the contour point is 3, and the fourth number is 7. The electronic device can calculate that the ratio between the third and fourth numbers of the contour point is 3 / 7.
[0131] S802, for each initial template including contour points, delete the contour points whose corresponding proportion is less than the first preset threshold to obtain the filtered contour points.
[0132] If the proportion corresponding to a certain contour point is small, it means that there are no matching contour points for that contour point in most target images, so the contour point can be removed. Specifically, the electronic device can delete contour points whose corresponding proportions are less than a first preset threshold for each initial template, thus obtaining the filtered contour points.
[0133] Continuing from the previous example, if the first preset threshold is 1 / 2, then for the contour point with a corresponding ratio of 3 / 7, since the ratio of the contour point is less than the first preset threshold, the contour point can be filtered out.
[0134] As one implementation method, electronic devices can use C i This represents the matching result obtained by matching a contour point in the initial template with the i-th target image. If the contour point is in the first state, then C... i It can be set to 1; if the contour point is in the second state, then C i It can be set to 0. If there are k target images in total, then k matching results corresponding to the contour point can be obtained: C1, C2, ..., C k .
[0135] In this way, the sum of the matching results corresponding to the contour point can represent the number of matching states in the first state corresponding to that contour point. The electronic device can compare the above sum with a preset threshold, and if the above sum does not reach the preset threshold, the contour point is filtered out.
[0136] For example, if there are 6 target images, the matching status between a certain contour point in the initial template and the corresponding contour point in each target image is: C1, C2, C3, C4, C5, and C6, where C1, C3, and C4 have a value of 1, and C2, C5, and C6 have a value of 0. The electronic device can sum these matching statuses to obtain a value of 3. If the preset threshold is 4, then since the summed value is less than the preset threshold, the electronic device can filter out the contour point.
[0137] As can be seen in this embodiment, if the proportion of matching states in the second state is relatively high for a certain contour point, it indicates that the contour point does not have a matching contour point in most target images, and therefore the contour point can be filtered out. To determine contour points that meet the above conditions, the electronic device can calculate the ratio between the third and fourth quantities of each contour point for each initial template, based on the matching state between each contour point included in the initial template and the corresponding contour point in the target image. If the ratio corresponding to a certain contour point is small, it indicates that the contour point does not have a matching contour point in most target images, and therefore the contour point can be filtered out. Since contour points with poor matching effects in the initial template are filtered out, the accuracy of image matching can be improved.
[0138] As one implementation method of this application, such as Figure 9 As shown, the second quantity can be multiple. Before the step of calculating the ratio between the third and fourth quantities of each contour point based on the matching status between each contour point included in the initial template and the corresponding contour point in the target image for each initial template, the method may further include:
[0139] S901, For each initial template, based on the matching status between the contour points included in each target image and the contour points included in the initial template, calculate the ratio between the fifth number and the sixth number of contour points included in each target image;
[0140] Wherein, the fifth quantity is the number of contour points in the target image whose matching state is the third state, the sixth quantity is the number of contour points in the target image whose matching state is the fourth state, the third state is used to indicate that the contour point has a matching contour point in the corresponding initial template, and the fourth state is used to indicate that the contour point does not have a matching contour point in the corresponding initial template.
[0141] If an initial template is used to match a target in a target image, and most contour points in the target image do not have corresponding contour points in the initial template, then the initial template has a low matching degree, and the matching status of the contour points in the target image is not of reference value for contour point selection.
[0142] Therefore, in order to determine the target image that is of reference value for screening contour points, and thus effectively screen the contour points, the electronic device can, for each initial template, calculate the ratio between the fifth and sixth numbers of contour points included in each target image based on the matching status between the contour points included in each target image and the contour points included in the initial template.
[0143] The fifth quantity is the number of contour points in the target image whose matching state is the third state, and the sixth quantity is the number of contour points in the target image whose matching state is the fourth state.
[0144] For example, if there are 100 contour points in the target image, of which 21 correspond to the third matching state and 79 correspond to the fourth matching state, then the target image has 21 fifth contour points and 79 sixth contour points. The electronic device can calculate the ratio of the fifth to the sixth contour points in the target image as 21 / 79.
[0145] In one implementation, the electronic device can calculate a score based on the fifth and sixth counts of contour points included in the target image. Then, based on the score corresponding to the target image, it can determine whether the target image is a valid matching image.
[0146] For example, an electronic device can calculate a score between 0 and 1 based on the fifth and sixth number of contour points included in the target image. If there are 100 contour points in the target image, of which 21 correspond to the third matching state and 79 correspond to the fourth matching state, the electronic device can divide the number of contour points in the third state by the total number of contour points, i.e., 21 / 100, to obtain a score of 0.21.
[0147] S902, based on the relationship between the proportion of each target image and the second preset threshold, determine the valid matching image from the target images;
[0148] If the proportion of the target image is low, it indicates that the target image matches the initial template poorly, and the matching status of the contour points in the target image is not valuable for contour point selection. Therefore, in order to determine the effective matching images that are valuable for contour point selection, the electronic device can determine the effective matching images from the target images based on the relationship between the proportion of each target image and a second preset threshold.
[0149] In one implementation, the first quantity is one, meaning the number of template images is one. Then, for each initial template, the electronic device can calculate the ratio between a fifth and a sixth quantity of contour points in each target image, based on the matching status between the contour points in a target image and the contour points in the initial template. Then, based on the relationship between this ratio and a second preset threshold, the electronic device can determine a valid matching image from the target images.
[0150] For example, if there is one template image and five target images, the electronic device can generate an initial template corresponding to the template image, and then match the targets in the five target images based on the initial template. The ratio between the fifth and sixth contour points included in each target image is then calculated, as shown in the table below:
[0151] Target image 1 Target image 2 Target image 3 Target image 4 Target image 5 Initial Template 1 0.67 0.89 0.73 0.49 0.76
[0152] If the second preset threshold is 0.60, then the effective matching images are target image 1, target image 2, target image 3 and target image 5.
[0153] In another implementation, the first quantity is multiple, meaning the number of template images is multiple. Then, for each initial template, the electronic device can calculate the ratio between a fifth and a sixth quantity of contour points in each target image, based on the matching status between the contour points included in each of the multiple target images and the contour points included in the initial template. Then, the electronic device can determine a valid matching image from the target images based on the relationship between the ratio corresponding to each target image and a second preset threshold.
[0154] For example, if there are 3 template images and 3 target images, the electronic device can generate 3 initial templates corresponding to the 3 template images, and then perform target matching in the 3 target images based on the 3 initial templates. The ratio between the fifth and sixth numbers of contour points included in each target image is then calculated, as shown in the table below:
[0155]
[0156]
[0157] If the second preset threshold is 0.60, then for initial template 1, the effective matching images are target image 2 and target image 3; for initial template 2, the effective matching images are target image 2 and target image 3; for initial template 3, the effective matching images are target image 1 and target image 3.
[0158] The above-mentioned step of calculating the ratio between the third and fourth quantities of each contour point based on the matching status between each contour point included in the initial template and the corresponding contour point in the target image can include:
[0159] For each initial template, the ratio between the third and fourth quantities of each contour point is calculated based on the matching status between each contour point included in the initial template and the corresponding contour point in the effective matching image.
[0160] Since the contour points in the effective matching image match the contour points in the initial target to a high degree, the matching status of the contour points in the effective matching image is valuable for contour point selection. Therefore, after determining the effective matching image, the electronic device can, for each initial template, calculate the ratio between the third and fourth quantities of each contour point based on the matching status between each contour point included in the initial template and the corresponding contour points in the effective matching image.
[0161] For example, if there are a total of 8 target images, the matching status of a certain contour point included in the initial template 1 in target images 1-8 is shown in the table below:
[0162]
[0163] If, for initial template 1, the effective matching images are target image 1, target image 2, target image 4, target image 5, target image 7, and target image 8, then the electronic device can calculate the third quantity of the contour point as 4 and the fourth quantity as 2 based on the matching status of the contour point in the above effective matching images, and further calculate the ratio between the third quantity and the fourth quantity of the contour point as 4 / 2.
[0164] As can be seen, in this embodiment, in order to determine a valid matching image that is valuable for screening contour points, the electronic device can, for each initial template, calculate the ratio between the fifth and sixth numbers of contour points in each target image based on the matching status between the contour points included in each target image and the contour points included in the initial template. Then, based on the relationship between the ratio corresponding to each target image and a second preset threshold, a valid matching image is determined from the target images. Since the contour points in the valid matching image match the contour points in the initial target image to a high degree, the matching status of the contour points in the valid matching image is valuable for contour point screening. Therefore, the electronic device can, for each initial template, calculate the ratio between the third and fourth numbers of each contour point based on the matching status between each contour point included in the initial template and the corresponding contour points in the valid matching image. This improves the accuracy of contour point screening, thereby improving the accuracy of image matching.
[0165] As one embodiment of this application, after the step of deleting contour points with a corresponding proportion less than a first preset threshold to obtain filtered contour points, the method may further include:
[0166] If the target image includes an invalid matching image, return to the step of matching each contour point included in the initial template with the contour points of the target included in each target image to obtain the matching status corresponding to each contour point included in the initial template, until the ratio between the fifth and sixth number of contour points included in each target image reaches the second preset threshold, wherein the invalid matching image is an image in the target image other than the valid matching image.
[0167] Since the target image is identified as an invalid match image, it may be due to inadequate screening of contour points in the initial template. If the target in the invalid match image is matched based on the initial template that has been screened for contour points, it may cause the ratio between the fifth and sixth contour points in the invalid match image to reach the second preset threshold.
[0168] To thoroughly filter the contour points in the initial template, after filtering the contour points in the initial template based on the matching status between corresponding contour points in the valid matching images, the electronic device can return to the step of matching each contour point included in the initial template with the contour points of the target image for each target image, obtaining the matching status corresponding to each contour point included in the initial template, until the ratio between the fifth and sixth numbers of contour points included in each target image reaches a second preset threshold. Invalid matching images are those in the target images other than the valid matching images.
[0169] In one implementation, the first quantity is one, that is, the number of template images is one. Then the electronic device can, for the target image including invalid matching images, return to the step of matching each contour point included in the initial template with the contour points of the target included in each target image to obtain the matching status corresponding to each contour point included in the initial template, until the ratio between the fifth quantity and the sixth quantity of contour points included in each target image reaches the second preset threshold.
[0170] For example, if there is one template image and five target images, the electronic device can generate an initial template corresponding to the template image, and then match the targets in the five target images based on the initial template. The ratio between the fifth and sixth contour points included in each target image is then calculated, as shown in the table below:
[0171] Target image 1 Target image 2 Target image 3 Target image 4 Target image 5 Initial Template 1 0.67 0.89 0.53 0.49 0.76
[0172] If the second preset threshold is 0.60, then the valid matching images are target image 1, target image 2, and target image 5, and the invalid matching images are target image 3 and target image 4. The electronic device can perform the first screening of the contour points in the initial template 1 based on the matching status of the contour points in the valid matching images.
[0173] Then, the electronic device can match the targets in target image 3 and target image 4 based on the initial template 1 after the first screening of contour points, and calculate the ratio between the fifth and sixth numbers of contour points included in target image 3 and target image 4, as shown in the table below:
[0174] Target image 3 Target image 4 Initial Template 1 0.65 0.56
[0175] The proportion corresponding to target image 3 reaches the second preset threshold, while the proportion corresponding to target image 4 does not, and is therefore still an invalid matching image. Thus, the electronic device can perform a second filtering of the contour points in the initial template 1 based on the matching status of the contour points in the valid matching images. Then, the electronic device can match the targets in target image 4 based on the initial template 1 after the second filtering of contour points, calculating that the ratio between the fifth and sixth number of contour points included in target image 4 is 0.63. At this point, the proportions corresponding to all target images have reached the second preset threshold.
[0176] In another implementation, the first quantity is multiple, that is, the number of template images is multiple. Then the electronic device can, for the target image including invalid matching images, return to the step of matching each contour point included in the initial template with the contour points of the target included in each target image to obtain the matching state corresponding to each contour point included in the initial template, until the ratio between the fifth quantity and the sixth quantity of contour points included in each target image reaches the second preset threshold.
[0177] As can be seen, in this embodiment, the determination of a target image as an invalid match image may be caused by inadequate screening of contour points in the initial template. If the target in the invalid match image is matched based on the initial template with screened contour points, it is possible to make the ratio between the fifth and sixth numbers of contour points in the invalid match image reach the second preset threshold. Simultaneously, the contour points in the initial template can be sufficiently screened. Therefore, the electronic device can, for invalid match images included in the target image, return to the step of matching each contour point included in the initial template with the contour points of the target image included in each target image, obtaining the matching status corresponding to each contour point included in the initial template, until the ratio between the fifth and sixth numbers of contour points included in each target image reaches the second preset threshold. This allows for more thorough screening of contour points in the initial template, thereby improving the accuracy of image matching.
[0178] As one implementation method of this application, such as Figure 10 As shown, the step of generating a matching template for the target based on the filtered contour points may include:
[0179] S1001, based on the pose of the contour points corresponding to each initial template, map the filtered contour points included in the initial template to the same coordinate system;
[0180] In one implementation, the first quantity is multiple, meaning there are multiple template images. Since the template images can be taken of the target under different angles, lighting conditions, etc., fusing the filtered contour points included in the initial template generated based on different template images can improve the matching degree between the template and the target image.
[0181] Therefore, in order to fuse multiple initial templates, the electronic device can map the filtered contour points included in the initial templates to the same coordinate system based on the contour point poses corresponding to each initial template. The contour point poses can include the rotation angles and translation distances of the contour points in the initial templates to match the contour points of the target image.
[0182] In another implementation, the first quantity is one, that is, the number of template images is one. The electronic device can map the filtered contour points included in the initial template to the same coordinate system according to the pose of the contour points corresponding to the initial template.
[0183] S1002, the mapped contour points are fused to obtain the matching template of the target.
[0184] In one implementation, the first quantity is multiple, meaning there are multiple template images. To integrate multiple initial templates after filtering contour points into a single template, the electronic device can fuse the mapped contour points to obtain a matching template for the target.
[0185] In another implementation, the first quantity is one, that is, the number of template images is one. The electronic device can obtain the matching template of the target based on the contour points corresponding to the mapped initial template.
[0186] As can be seen, in this embodiment, the electronic device can map the filtered contour points included in the initial template to the same coordinate system according to the pose of the contour points corresponding to each initial template; and fuse the mapped contour points to obtain the matching template of the target. Since the template image can be taken of the target under different angles, lighting conditions, etc., fusing the filtered contour points included in the initial template generated based on different template images can improve the matching degree between the template and the target image, thereby improving the accuracy of image matching.
[0187] As one implementation method of this application, such as Figure 11 As shown, the step of fusing the mapped contour points to obtain the matching template of the target may include:
[0188] S1101, the initial template is divided into multiple grids according to a preset method;
[0189] In order to accurately map each contour point to the same coordinate system, the electronic device can divide the initial template into multiple grids according to a preset method, and then merge the contour points in the same grid on a grid-by-grid basis.
[0190] S1102, For each grid cell, calculate the average coordinates of the mapped contour points included in that grid cell;
[0191] To reflect the average position of the contour points included in each grid, the electronic device can calculate the average coordinates of the mapped contour points included in each grid.
[0192] For example, if there are 5 mapped contour points within a certain grid, the coordinates of contour points 1-5 are shown in the table below:
[0193] Contour Points Contour point coordinates Contour point 1 (19.3,42.6) Outline point 2 (18.9,42.8) Contour point 3 (19.2,43.1) Outline point 4 (19.3,42.7) Contour point 5 (19.1,42.9)
[0194] Then, the electronic device can calculate the average abscissa and average ordinate of contour points 1-5 respectively, and obtain the average abscissa as 19.16 and the average ordinate as 42.82.
[0195] S1103, the average coordinates are used as the positions of the contour points included in the grid to obtain the matching template of the target.
[0196] Since the average coordinates of all contour points in the same grid can reflect the average position of all contour points in the grid, the electronic device can use the average coordinates as the position of the contour points included in the grid to obtain the matching template of the target.
[0197] Continuing from the previous example, the electronic device can use (19.16, 42.82) as the location of the contour points included in the grid.
[0198] As can be seen, in this embodiment, the electronic device can divide the initial template into multiple grids according to a preset method; for each grid, the average coordinates of the mapped contour points included in the grid are calculated; the average coordinates are used as the position of the contour points included in the grid to obtain the matching template of the target. Since the average coordinates of the contour points in the same grid can reflect the average position of the contour points in the grid, the electronic device can use the average coordinates as the position of the contour points included in the grid to obtain the matching template of the target, which can improve the accuracy of image matching.
[0199] Corresponding to the above-described method for generating matching templates, this application also provides a device for generating matching templates. The device for generating matching templates provided in this application will be described below.
[0200] like Figure 12 As shown, a template matching generation apparatus includes:
[0201] Image acquisition module 1201 is used to acquire a first number of template images and a second number of target images;
[0202] The initial template generation module 1202 is used to generate an initial template for each template image based on the contour points of the target in the template image;
[0203] The target matching module 1203 is used to match the targets included in each target image based on the contour points included in the initial template for each initial template, and obtain the corresponding matching results;
[0204] The contour point filtering module 1204 is used to filter the contour points included in the initial template based on the matching results to obtain the filtered contour points.
[0205] The matching template generation module 1205 is used to generate a matching template for the target based on the filtered contour points.
[0206] As can be seen, the electronic device can acquire a first number of template images and a second number of target images. For each template image, an initial template is generated based on the contour points of the target in the template image. For each initial template, the target in each target image is matched based on the contour points included in the initial template to obtain the corresponding matching result. Based on the matching result, the contour points included in the initial template are filtered to obtain filtered contour points. Based on the filtered contour points, a matching template for the target is generated. Since the electronic device can filter the contour points included in the initial template according to the matching result, it can filter out contour points in the initial template that have poor matching results with the target in the target image, and then generate a matching template for the target based on the filtered contour points. This is not based solely on an image of the target taken under certain conditions to generate a template, thus improving the accuracy of image matching.
[0207] As one embodiment of this application, the first quantity and / or the second quantity described above are multiple;
[0208] The target matching module 1203 mentioned above may include:
[0209] The matching result acquisition submodule is used to match each contour point included in the initial template with the contour points of the target included in each target image for each initial template, and obtain the matching status corresponding to each contour point included in the initial template as the matching result;
[0210] The matching state includes a first state and a second state. The first state is used to indicate that the contour point has a matching contour point in the corresponding target image, and the second state is used to indicate that the contour point does not have a matching contour point in the corresponding target image.
[0211] As one embodiment of this application, the contour point filtering module 1204 may include:
[0212] The ratio calculation submodule is used to calculate the ratio between the third quantity and the fourth quantity of each contour point for each initial template, based on the matching status between each contour point included in the initial template and the corresponding contour point in the target image. The third quantity is the number of contour points whose matching status is the first state, and the fourth quantity is the number of contour points whose matching status is the second state.
[0213] The contour point deletion submodule is used to delete contour points whose proportion is less than a first preset threshold for each initial template, thus obtaining the filtered contour points.
[0214] As one embodiment of this application, the above-mentioned second quantity is multiple;
[0215] The device may further include:
[0216] The ratio calculation module is used to calculate, for each initial template, the ratio between the fifth number and the sixth number of contour points included in each target image, based on the matching status between the contour points included in each target image and the contour points included in the initial template. The fifth number is the number of contour points in the target image whose matching status is the third state, and the sixth number is the number of contour points in the target image whose matching status is the fourth state. The third state is used to indicate that the contour point has a matching contour point in the corresponding initial template, and the fourth state is used to indicate that the contour point does not have a matching contour point in the corresponding initial template.
[0217] The effective matching image determination module is used to determine effective matching images from the target images based on the relationship between the proportion corresponding to each target image and a second preset threshold.
[0218] The aforementioned ratio calculation submodule may include:
[0219] The ratio calculation unit is used to calculate the ratio between the third and fourth quantities of each contour point for each initial template, based on the matching status between each contour point included in the initial template and the corresponding contour point in the effective matching image.
[0220] As one embodiment of this application, the above-described apparatus may further include:
[0221] The matching status acquisition module is used to, for the target image including invalid matching images, return to execute the step of matching each contour point included in the initial template with the contour points of the target included in each target image to obtain the matching status corresponding to each contour point included in the initial template, until the ratio between the fifth and sixth numbers of contour points included in each target image reaches a second preset threshold, wherein the invalid matching image is an image in the target image other than the valid matching image.
[0222] As one embodiment of this application, the matching template generation module 1205 may include:
[0223] The contour point mapping submodule is used to map the filtered contour points included in the initial template to the same coordinate system according to the contour point pose corresponding to each initial template.
[0224] The matching template acquisition submodule is used to fuse the mapped contour points to obtain the matching template of the target.
[0225] As one embodiment of this application, the above-mentioned template matching submodule may include:
[0226] A grid division unit is used to divide the initial template into multiple grids according to a preset method;
[0227] The average value calculation sub-unit is used to calculate the average coordinates of the mapped contour points included in each grid cell.
[0228] A matching template generation sub-unit is used to obtain the matching template of the target by taking the average coordinate value as the position of the contour points included in the grid.
[0229] This application also provides an electronic device, such as... Figure 13 As shown, it includes:
[0230] Memory 1301 is used to store computer programs;
[0231] The processor 1302, when executing the program stored in the memory 1301, implements the steps of the matching template generation method described in any of the above embodiments.
[0232] Furthermore, the aforementioned electronic device may also include a communication bus and / or a communication interface, with the processor 1302, the communication interface, and the memory 1301 communicating with each other via the communication bus.
[0233] As can be seen, the electronic device can acquire a first number of template images and a second number of target images. For each template image, an initial template is generated based on the contour points of the target in the template image. For each initial template, the target in each target image is matched based on the contour points included in the initial template to obtain the corresponding matching result. Based on the matching result, the contour points included in the initial template are filtered to obtain filtered contour points. Based on the filtered contour points, a matching template for the target is generated. Since the electronic device can filter the contour points included in the initial template according to the matching result, it can filter out contour points in the initial template that have poor matching results with the target in the target image, and then generate a matching template for the target based on the filtered contour points. This is not based solely on an image of the target taken under certain conditions to generate a template, thus improving the accuracy of image matching.
[0234] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0235] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0236] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0237] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0238] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of the above-described method for generating any of the matching templates.
[0239] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the matching template generation methods in the above embodiments.
[0240] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.
[0241] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0242] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0243] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A method for generating a matching template, characterized in that, The method includes: Obtain a first number of template images and a second number of target images; For the template image, an initial template is generated based on the contour points of the target in the template image; For the initial template, the contour points included in the initial template are matched with the contour points of the target included in the target image to obtain the matching state corresponding to the contour points included in the initial template, which is used as the matching result. The matching state includes a first state and a second state. The first state is used to indicate that the contour point has a matching contour point in the corresponding target image, and the second state is used to indicate that the contour point does not have a matching contour point in the corresponding target image. Based on the matching results, the contour points included in the initial template are filtered to obtain the filtered contour points. Based on the filtered contour points, a matching template for the target is generated.
2. The method according to claim 1, characterized in that, The first quantity and / or the second quantity are multiple.
3. The method according to claim 2, characterized in that, The step of filtering the contour points included in the initial template based on the matching result to obtain the filtered contour points includes: For the initial template, based on the matching status between the contour points included in the initial template and the corresponding contour points in the target image, the ratio between the third number and the fourth number of the contour points is calculated, wherein the third number is the number of contour points whose matching status is the first state, and the fourth number is the number of contour points whose matching status is the second state. For the contour points included in the initial template, those contour points with a proportion less than a first preset threshold are deleted to obtain the filtered contour points.
4. The method according to claim 3, characterized in that, The second quantity is multiple; Before the step of calculating the ratio between the third and fourth numbers of contour points based on the matching status between the contour points included in the initial template and the corresponding contour points in the target image, the method further includes: For the initial template, based on the matching status between the contour points included in the target image and the contour points included in the initial template, the ratio between the fifth number and the sixth number of contour points included in the target image is calculated. The fifth number is the number of contour points in the target image whose matching status is the third state, and the sixth number is the number of contour points in the target image whose matching status is the fourth state. The third state is used to indicate that the contour point has a matching contour point in the corresponding initial template, and the fourth state is used to indicate that the contour point does not have a matching contour point in the corresponding initial template. Based on the relationship between the proportion of the target image and the second preset threshold, a valid matching image is determined from the target image; The step of calculating the ratio between the third and fourth quantities of contour points based on the matching status between the contour points included in the initial template and the corresponding contour points in the target image includes: For the initial template, the ratio between the third and fourth quantities of the contour points is calculated based on the matching status between the contour points included in the initial template and the corresponding contour points in the effective matching image.
5. The method according to claim 4, characterized in that, After the step of deleting contour points whose corresponding proportions are less than a first preset threshold to obtain filtered contour points, the method further includes: If the target image includes an invalid matching image, return to the step of matching the contour points of the target image with the contour points of the target image included in the initial template to obtain the matching status corresponding to the contour points included in the initial template, until the ratio between the fifth and sixth numbers of contour points included in the target image both reach the second preset threshold, wherein the invalid matching image is an image in the target image other than the valid matching image.
6. The method according to any one of claims 1-5, characterized in that, The step of generating a matching template for the target based on the filtered contour points includes: Based on the pose of the contour points corresponding to the initial template, the filtered contour points included in the initial template are mapped to the same coordinate system; The mapped contour points are then fused to obtain a matching template for the target.
7. The method according to claim 6, characterized in that, The step of fusing the mapped contour points to obtain the matching template of the target includes: The initial template is divided into multiple grids according to a preset method; For the grid, calculate the average coordinates of the mapped contour points included in the grid; The average coordinates are used as the positions of the contour points included in the grid to obtain the matching template of the target.
8. An apparatus for generating a matching template, characterized in that, The device includes: The image acquisition module is used to acquire a first number of template images and a second number of target images; An initial template generation module is used to generate an initial template for the template image based on the contour points of the target in the template image; The target matching module is used to match the contour points included in the initial template with the contour points of the target image to obtain the matching state corresponding to the contour points included in the initial template as the matching result. The matching state includes a first state and a second state. The first state is used to indicate that the contour point has a matching contour point in the corresponding target image, and the second state is used to indicate that the contour point does not have a matching contour point in the corresponding target image. The contour point filtering module is used to filter the contour points included in the initial template based on the matching results to obtain the filtered contour points. The matching template generation module is used to generate a matching template for the target based on the filtered contour points.
9. The apparatus according to claim 8, characterized in that, The first quantity and / or the second quantity can be multiple; The contour point filtering module includes: The ratio calculation submodule is used to calculate the ratio between the third number and the fourth number of contour points for the initial template based on the matching status between the contour points included in the initial template and the corresponding contour points in the target image. The third number is the number of contour points whose matching status is the first state, and the fourth number is the number of contour points whose matching status is the second state. The contour point deletion submodule is used to delete contour points whose proportion is less than a first preset threshold from the contour points included in the initial template, so as to obtain the filtered contour points. The second quantity is multiple; The device further includes: The ratio calculation module is used to calculate, for the initial template, the ratio between a fifth number and a sixth number of contour points included in the target image based on the matching status between the contour points included in the target image and the contour points included in the initial template. The fifth number is the number of contour points in the target image whose matching status is in the third state, and the sixth number is the number of contour points in the target image whose matching status is in the fourth state. The third state indicates that the contour point has a matching contour point in the corresponding initial template, and the fourth state indicates that the contour point does not have a matching contour point in the corresponding initial template. The effective matching image determination module is used to determine an effective matching image from the target image based on the size relationship between the proportion corresponding to the target image and a second preset threshold. The ratio calculation submodule includes: The ratio calculation unit is used to calculate the ratio between the third number and the fourth number of contour points for the initial template, based on the matching status between the contour points included in the initial template and the corresponding contour points in the effective matching image. The device further includes: The matching status acquisition module is used to, when the target image includes an invalid matching image, return to execute the step of matching the contour points of the target image with the contour points of the target image included in the initial template to obtain the matching status corresponding to the contour points included in the initial template, until the ratio between the fifth and sixth numbers of contour points included in the target image both reach a second preset threshold, wherein the invalid matching image is an image in the target image other than the valid matching image; The matching template generation module includes: The contour point mapping submodule is used to map the filtered contour points included in the initial template to the same coordinate system according to the contour point pose corresponding to the initial template. The matching template acquisition submodule is used to fuse the mapped contour points to obtain the matching template of the target; The matching template acquisition submodule includes: A grid division unit is used to divide the initial template into multiple grids according to a preset method; The average value calculation subunit is used to calculate the average coordinates of the mapped contour points included in the grid for the grid. A matching template generation sub-unit is used to obtain the matching template of the target by taking the average coordinate value as the position of the contour points included in the grid.
10. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-7.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-7.