Search

CN-117152469-B - Method and device for generating matching template, electronic equipment and storage medium

CN117152469BCN 117152469 BCN117152469 BCN 117152469BCN-117152469-B

Abstract

The embodiment of the application provides a method, a device, electronic equipment and a storage medium for generating a matching template, wherein the electronic equipment can acquire a first number of template images and a second number of target images, generates initial templates based on contour points of targets in the template images for each template image, matches targets in each target image based on the contour points in each initial template for each initial template to obtain a corresponding matching result, screens the contour points in the initial template based on the matching result to obtain screened contour points, and generates the matching template according to the screened contour points. Because the contour points included in the initial template are screened according to the matching result, the contour points which are poorly matched with the target image in the initial template can be screened, and then the matching template of the target is generated according to the screened contour points. Rather than generating templates based only on images captured by the object under certain conditions, the accuracy of image matching can be improved.

Inventors

  • GU RUI
  • DENG ZHIHUI

Assignees

  • 杭州海康机器人股份有限公司

Dates

Publication Date
20260505
Application Date
20230814

Claims (11)

  1. 1. A method for generating a matching template, the method comprising: Acquiring a first number of template images and a second number of target images; generating an initial template based on contour points of a target in the template image aiming at the template image; Matching contour points included in the initial template with contour points of targets included in the target image aiming at the initial template to obtain a matching state corresponding to the contour points included in the initial template, wherein the matching state comprises a first state and a second state as a matching result, the first state is used for identifying that the contour points have matched contour points in the corresponding target image, and the second state is used for identifying that the contour points do not have matched contour points in the corresponding target image; screening contour points included in the initial template based on the matching result to obtain screened contour points; And generating a matching template of the target according to the screened contour points.
  2. 2. The method according to claim 1, wherein the first number and/or the second number is a plurality.
  3. 3. The method according to claim 2, wherein the step of screening contour points included in the initial template based on the matching result to obtain screened contour points includes: Calculating, for the initial template, a ratio between a third number and a fourth number of contour points according to a matching state between the contour points included in the initial template and the corresponding contour points in the target image, where the third number is the number of contour points in the first state in the matching state corresponding to the contour points, and the fourth number is the number of contour points in the second state in the matching state corresponding to the contour points; And deleting the contour points with the corresponding proportion smaller than a first preset threshold value aiming at the contour points included in the initial template to obtain the screened contour points.
  4. 4. A method according to claim 3, wherein the second number is a plurality; Before the step of calculating, for the initial template, a ratio between a third number and a fourth number of contour points according to a matching state between contour points included in the initial template and corresponding contour points in the target image, the method further includes: Calculating, for the initial template, a ratio between a fifth number and a sixth number of contour points included in the target image according to matching states between the contour points included in the target image and the contour points included in the initial template, where the fifth number is the number of contour points whose matching states correspond to the contour points included in the target image are third states, the sixth number is the number of contour points whose matching states correspond to the contour points included in the target image are fourth states, the third states are used to identify that the contour points have matched contour points in the corresponding initial template, and the fourth states are used to identify that the contour points do not have matched contour points in the corresponding initial template; determining a valid matching image from the target image based on a size relationship between a corresponding proportion of the target image and a second preset threshold; The step of calculating, for the initial template, a ratio between a third number and a fourth number of contour points according to a matching state between contour points included in the initial template and corresponding contour points in the target image, includes: And calculating the ratio between the third number and the fourth number of the contour points according to the matching state between the contour points included in the initial template and the corresponding contour points in the effective matching image aiming at the initial template.
  5. 5. The method of claim 4, wherein after the step of deleting contour points having a corresponding proportion less than a first predetermined threshold to obtain screened contour points, the method further comprises: And carrying out the step of matching the contour points of the target included in the target image by the contour points included in the initial template until the ratio between the fifth number and the sixth number of the contour points included in the target image reaches a second preset threshold, wherein the invalid matching image is an image except the valid matching image in the target image.
  6. 6. The method according to any one of claims 1-5, wherein the step of generating a matching template of the object from the screened contour points comprises: mapping the screened contour points included in the initial template to the same coordinate system according to the contour point gesture corresponding to the initial template; And fusing the mapped contour points to obtain a matching template of the target.
  7. 7. The method of claim 6, wherein the step of fusing the mapped contour points to obtain a matching template for the object comprises: dividing the initial template into a plurality of grids according to a preset mode; calculating the coordinate average value of the mapped contour points included in the grid aiming at the grid; And taking the coordinate average value as the position of the contour point included in the grid to obtain the matching template of the target.
  8. 8. A match template generation apparatus, the apparatus comprising: An image acquisition module for acquiring a first number of template images and a second number of target images; the initial template generation module is used for generating an initial template aiming at the template image based on the outline points of the target in the template image; the target matching module is used for matching the contour points of the targets included in the target image with the contour points included in the initial template aiming at the initial template to obtain a matching state corresponding to the contour points included in the initial template, wherein the matching state comprises a first state and a second state as a matching result, the first state is used for marking that the contour points have matched contour points in the corresponding target image, and the second state is used for marking that the contour points do not have matched contour points in the corresponding target image; The contour point screening module is used for screening contour points included in the initial template based on the matching result to obtain screened contour points; and the matching template generation module is used for generating a matching template of the target according to the screened contour points.
  9. 9. The apparatus of claim 8, wherein the first number and/or the second number is a plurality; The contour point screening module comprises: The proportion calculating sub-module is used for calculating the proportion between a third quantity and a fourth quantity of contour points according to the matching state between the contour points included in the initial template and the corresponding contour points in the target image, wherein the third quantity is the quantity of contour points in the first state in the matching state corresponding to the contour points, and the fourth quantity is the quantity of contour points in the second state in the matching state corresponding to the contour points; the contour point deleting sub-module is used for deleting contour points with the corresponding proportion smaller than a first preset threshold value aiming at the contour points included in the initial template to obtain screened contour points; the second number is a plurality; The apparatus further comprises: The proportion calculating module is used for calculating the proportion between a fifth number and a sixth number of contour points included in the target image according to the matching state between the contour points included in the target image and the contour points included in the initial template, wherein the fifth number is the number of contour points with the matching state corresponding to the contour points included in the target image being the third state, the sixth number is the number of contour points with the matching state corresponding to the contour points included in the target image being the fourth state, the third state is used for identifying that the contour points have matched contour points in the corresponding initial template, and the fourth state is used for identifying that the contour points do not have matched contour points in the corresponding initial template; the effective matching image determining module is used for determining an effective matching image from the target image based on the size relation between the corresponding proportion of the target image and a second preset threshold value; The proportion calculation submodule comprises: The proportion calculating unit is used for calculating the proportion between the third number and the fourth number of the contour points according to the matching state between the contour points included in the initial template and the corresponding contour points in the effective matching image aiming at the initial template; The apparatus further comprises: A matching state obtaining module, configured to perform the step of matching, for the target image, contour points of a target included in the target image by using contour points included in the initial template, until ratios between a fifth number and a sixth number of contour points included in the target image reach a second preset threshold, where the invalid matching image is an image, except for the valid matching image, in the target image; The matching template generation module comprises: the contour point mapping sub-module is used for mapping the screened contour points included in the initial template to the same coordinate system according to the contour point gesture corresponding to the initial template; The matching template acquisition sub-module is used for fusing the mapped contour points to obtain a matching template of the target; The matching template obtaining sub-module comprises: the grid dividing unit is used for dividing the initial template into a plurality of grids according to a preset mode; An average value calculating subunit, configured to calculate, for the grid, a coordinate average value of the mapped contour points included in the grid; and the matching template generation subunit is used for taking the coordinate average value as the position of the contour point included by the grid to obtain the matching template of the target.
  10. 10. An electronic device, comprising: a memory for storing a computer program; a processor for implementing the method of any of claims 1-7 when executing a program stored on a memory.
  11. 11. A computer readable storage medium, characterized in that the computer readable storage medium has stored therein a computer program which, when executed by a processor, implements the method of any of claims 1-7.

Description

Method and device for generating matching template, electronic equipment and storage medium Technical Field The present application relates to the field of image matching technologies, and in particular, to a method and apparatus for generating a matching template, an electronic device, and a storage medium. Background The template matching is a visual matching algorithm which is widely applied, and the electronic equipment can match the position, angle and size of the target in the image to be processed according to the matching condition between the contour point of the target in the pre-generated matching template and the contour point of the object to be searched in the image to be processed, so that the score reflecting the matching degree of the target in the image to be processed and the target in the matching template can be obtained. In the above manner, the matching template is generated based on an image captured by the subject under a certain angle and illumination condition. However, in the actual image matching process, conditions such as an acquisition angle and illumination of an image to be processed may have a larger difference from conditions corresponding to a matching template, so that contour points of objects to be searched in a large number of images to be processed cannot be matched with contour points of targets in the matching template, and therefore a mode of reducing a fraction threshold value can be adopted to adapt to condition changes, but the mode is easy to cause missed detection, so that the accuracy of image matching based on the matching template is low at present. Disclosure of Invention The embodiment of the application aims to provide a method and a device for generating a matching template, electronic equipment and a storage medium, so as to improve the accuracy of image matching. The specific technical scheme is as follows: In a first aspect, an embodiment of the present application provides a method for generating a matching template, where the method includes: Acquiring a first number of template images and a second number of target images; Generating an initial template for each template image based on contour points of a target in the template image; For each initial template, matching targets included in each target image based on contour points included in the initial template to obtain a corresponding matching result; screening contour points included in the initial template based on the matching result to obtain screened contour points; And generating a matching template of the target according to the screened contour points. Optionally, the first number and/or the second number is a plurality; the step of matching the targets included in each target image based on the contour points included in the initial template for each initial template to obtain a corresponding matching result includes: for each initial template, matching each contour point included in the initial template with a contour point of a target included in each target image to obtain a matching state corresponding to each contour point included in the initial template, and taking the matching state as a matching result; the matching states include a first state for identifying that the contour point has a matched contour point in the corresponding target image and a second state for identifying that the contour point does not have a matched contour point in the corresponding target image. Optionally, the step of screening the contour points included in the initial template based on the matching result to obtain screened contour points includes: For each initial template, calculating the ratio between the third quantity and the fourth quantity of each contour point according to the matching state between each contour point included in the initial template and the corresponding contour point in the target image, wherein the third quantity is the quantity of contour points in the first state in the matching state corresponding to the contour point, and the fourth quantity is the quantity of contour points in the second state in the matching state corresponding to the contour point; And deleting the contour points with the corresponding proportion smaller than a first preset threshold value aiming at the contour points included in each initial template to obtain the screened contour points. Optionally, the second number is a plurality; Before the step of calculating, for each initial template, a ratio between the third number and the fourth number of each contour point according to a matching state between each contour point included in the initial template and a corresponding contour point in the target image, the method further includes: Calculating, for each initial template, a ratio between a fifth number and a sixth number of contour points included in each target image according to a matching state between the contour points included in each target image and the contour points included in