Single target template matching method, electronic device and storage medium
By grayscale and block processing the Mini-LED panel template image, and using the integral map to calculate the matching error, the problem of slow speed of the existing template matching algorithm is solved, fast and accurate template matching is achieved, and production efficiency is improved.
Patent Information
- Application Number
- CN202410346099.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-26
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-03-26
AI Technical Summary
In the production of Mini-LED panels, the existing template matching algorithm has a slow matching speed and it is difficult to complete the detection and positioning of tens or even hundreds of thousands of LED chips in a short time, resulting in reduced production efficiency.
Using a single-target template matching method, the template image is grayscaled and divided into blocks. The integral map is used to calculate the matching error and compared with the overall allowable error. Sliding window matching is performed to prune in advance, reducing the amount of calculation and improving matching. speed.
It achieves fast and accurate template matching, reduces the amount of calculation, increases the matching speed, and improves production efficiency.
Smart Images

Figure CN117953247B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of semiconductor technology, and in particular to a single-target template matching method, electronic equipment and storage medium. Background Art
[0002] Mini-LED technology is a liquid crystal display (LCD) backlight technology that is mainly used to improve the brightness, contrast and image quality of display screens. It is widely used in the field of display technology.
[0003] During the production process of Mini-LED panels, tens of thousands or even hundreds of thousands of LED chips need to be mounted on the panel. Since the mounting of LED chips needs to meet certain mounting accuracy to achieve the required yield of the product, after the LED chips are mounted, they need to be detected and located by using template matching algorithms. Figure 1 A red light-emitting chip of MiniLED and a search image in the actual positioning scene. Figure 2 The conventional matching starts from the upper left corner of the image, and the line-by-line scanning matching method is Figure 2 Each point starting from the upper left corner shown in the figure is matched as the starting point of the template size sliding window. Therefore, most template matching algorithms have a slow matching speed, and it is difficult to detect and locate tens of thousands or even hundreds of thousands of chips on the panel in a short time, which leads to reduced production efficiency. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a single-target template matching method, an electronic device and a storage medium. The method can quickly and accurately complete template matching, reduce the calculation amount of template matching, and improve the matching speed.
[0005] To solve the above technical problems, the embodiments of the present invention provide the following technical solutions:
[0006] In a first aspect, an embodiment of the present invention provides a single target template matching method, which is applied to an electronic device, and the method includes:
[0007] Training steps:
[0008] Grayscale the template image to obtain a matching template;
[0009] Divide the matching template into blocks according to the complexity requirements into corresponding levels, and record the grayscale and corresponding grid coordinates of each block after division;
[0010] Matching steps:
[0011] Set the overall tolerance;
[0012] Sliding a window in the image to be searched through the divided matching template;
[0013] Use the integral graph to calculate the matching error for each sliding window level by level;
[0014] The matching errors in each level are respectively compared with the overall allowable error to perform template matching.
[0015] In some embodiments, the complexity requirement includes:
[0016] When the complexity of sliding window matching after block integration exceeds the complexity of complete sliding window matching calculation, block division is stopped.
[0017] In some embodiments, dividing the matching template into blocks according to complexity requirements into corresponding levels includes:
[0018] The theoretical maximum number of blocks of the matching template is calculated according to the complexity requirement;
[0019] Divide the matching template into blocks, calculate the number of newly added blocks after the blocks are divided, and add a level;
[0020] Determine whether the total number of blocks combined with the number of newly added blocks exceeds the theoretical maximum number of blocks;
[0021] If it is not exceeded, continue to divide into blocks and increase the level until the theoretical maximum number of blocks is reached;
[0022] When it exceeds the limit, the current block is exited and the level is the level of the previous block.
[0023] In some embodiments, the matching template further includes the number of pixels, and the setting of the overall error includes:
[0024] Determine the minimum allowable matching error based on empirical values;
[0025] An overall allowable error is set based on the minimum allowable matching error and the number of pixels.
[0026] In some embodiments, the step of calculating the matching error at each sliding window level by level using the integral graph includes:
[0027] Calculate the integral image of the image to be searched;
[0028] The overall grayscale accumulation corresponding to the blocks at each level of the matching template in the current sliding window is obtained through the integral image and the grid coordinate calculation;
[0029] The grayscale cumulative sum of the blocks in each level of the matching template is compared with the overall grayscale cumulative sum corresponding to the blocks at each level of the matching template in the current sliding window to obtain the matching error, and each level corresponds to a matching error.
[0030] In some embodiments, the comparing the matching errors in each level with the overall allowable error to perform template matching includes:
[0031] Starting from the first level, the matching error of each level is compared with the overall allowable error to determine whether it is less than the overall allowable error;
[0032] When the matching error of a certain level is greater than the overall allowable error, it means that the current sliding window position is not the best matching position, and the sliding window is skipped if the matching fails;
[0033] When the matching errors of all levels are less than the overall allowable error, the position with the smallest matching error is recorded until all sliding windows are calculated. The position with the smallest matching error is the best position.
[0034] In some embodiments, when the matching errors of all levels are less than the overall allowable error, the method further includes:
[0035] Calculating the matching error of the current sliding window pixel by pixel through a vector instruction set, and determining whether the matching error is greater than the overall allowable error;
[0036] If it is greater than , it means that the current sliding window position is not the best matching position, and the sliding window will be skipped if the matching fails;
[0037] When it is not greater than, the matching error is saved and incorporated into all matching errors after all sliding windows are calculated. The position with the smallest matching error is the best position.
[0038] In a second aspect, an embodiment of the present invention provides an electronic device, including:
[0039] A processor, and a memory communicatively connected to the processor;
[0040] The memory stores computer program instructions executable by the processor, and when the computer program instructions are called by the processor, the processor executes any one of the single-target template matching methods proposed in the first aspect, or steps in any one of the possible implementations of any one of the single-target template matching methods proposed in the first aspect.
[0041] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are called by a processor, the processor executes any one of the single-target template matching methods proposed in the first aspect, or steps in any possible implementation of any one of the single-target template matching methods proposed in the first aspect.
[0042] Beneficial effects of the embodiments of the present invention: Different from the prior art, the single-target template matching method provided by the embodiments of the present invention is applied to electronic devices, and the method includes: a training step: graying the template image to obtain a matching template; dividing the matching template into blocks according to complexity requirements into corresponding levels, and recording the grayscale and corresponding grid coordinates of each block after division; a matching step: setting an overall allowable error; sliding a window in the image to be searched through the divided matching template; using an integral map to calculate the matching error for each sliding window level by level; and comparing the matching error in each level with the overall allowable error to perform template matching.
[0043] The single-target template matching method provided by the embodiment of the present invention divides the matching template into blocks, uses the integral map to calculate the matching error of the matching template for each sliding window layer by layer, compares the matching error of each level of the matching template with the overall allowable error, performs early pruning of the sliding window, completes template matching quickly and accurately, reduces the calculation amount of template matching, and improves the matching speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope of protection. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 It is the red light-emitting chip of miniled in the background technology of the present invention and the search graph in the actual positioning scene;
[0046] Figure 2 It is a schematic diagram of conventional matching in the background technology of the present invention;
[0047] Figure 3 is a schematic diagram of an application scenario of a single target template matching method provided by some embodiments of the present invention;
[0048] Figure 4 is a schematic diagram of the structure of an electronic device provided by some embodiments of the present invention;
[0049] Figure 5 is a schematic flow chart of a single target template matching method provided by some embodiments of the present invention;
[0050] Figure 6 yes Figure 5 A schematic diagram of a sub-process of step S200 in the single target template matching method shown in the embodiment;
[0051] Figure 7 is an example diagram of dividing a matching template into blocks in some embodiments of the present invention;
[0052] Figure 8 yes Figure 5 A schematic diagram of a sub-process of step S300 in the single target template matching method shown in the embodiment;
[0053] Fig. 9 yes Figure 5 A schematic diagram of a sub-process of step S500 in the single target template matching method shown in the embodiment;
[0054] Fig.10 yes Figure 5 A schematic diagram of a sub-process of step S600 in the single target template matching method shown in the embodiment;
[0055] Fig.11 yes Figure 5 Another sub-process diagram of step S600 in the single-target template matching method shown in the embodiment. DETAILED DESCRIPTION
[0056] In order to make the purpose and advantages of the embodiments of the present invention easier to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. The detailed description of the embodiments of the present invention in the drawings below does not limit the scope of protection claimed by the present invention, but only represents the selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0057] It should be noted that, if no conflict is constituted, the various technical features involved in the embodiments of the present invention described below can be combined with each other, and are all within the scope of protection of the present invention. In addition, although the functional modules are divided in the device or structural schematic diagram, and the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in a different order from the module division in the device, or in a different order from the flow chart. In addition, the "first", "second", "third" and other similar expressions used herein do not limit the data and execution order, but are only for the purpose of convenience of explanation and to distinguish between the same or similar items with basically the same functions and effects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features.
[0058] Unless otherwise defined, the technical terms and scientific terms used in this specification have the same meanings as those generally understood by those of ordinary skill in the art of the present invention. The terms used in this specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. It should be understood that the term "and / or" used in this specification includes any and all combinations of one or more of the related listed items.
[0059] In the semiconductor manufacturing industry, the cut chips need to be mounted on the substrate. The chips mounted on the substrate need to meet certain mounting accuracy to achieve the required yield of the product. Therefore, after the chips are mounted on the substrate, AOI equipment (Automated Optical Inspection) is required to perform template inspection through visual inspection to detect and locate the mounting position of the chip, ensure that the chip is accurately mounted on the substrate, and then proceed to the next process.
[0060] See also Figure 3 , Figure 3 Schematic diagram of an application scenario of a single target template matching method provided by some embodiments of the present invention. The application scenario includes an electronic device 100, wherein the electronic device 100 may be a laptop computer, a desktop computer, a tablet computer, or other suitable type of device with certain computing and control capabilities. It should be understood that in Figure 3 In the application scenario shown, the electronic device 100 is a desktop computer, but this does not impose any restrictions on the structure and type of the electronic device 100. For example, the electronic device 100 can also be a notebook computer, a tablet computer or other types of devices. The electronic device 100 in other application scenarios can also be a desktop computer. Figure 3 The desktop computer shown in the embodiment may include more or fewer components, or may have the same Figure 3 The embodiments shown are different configurations of desktop computers.
[0061] It should be understood that in order to complete template matching, the electronic device 100 also needs to work in conjunction with some other software and hardware, including a camera or image acquisition device, a thermal imaging camera, image processing software, a display device, and a storage device, etc. Specifically, as a device that provides computing and control capabilities, the electronic device 100 performs grayscale processing on the template image to obtain a matching template, and then divides the matching template into blocks into corresponding levels; by controlling the camera or image acquisition device to detect and obtain the image to be searched formed by the chip mounted on the substrate, the divided matching template is used to slide the window in the image to be searched, and the integral map is used to calculate the matching error for each sliding window level by level, and then the matching error of each level of the matching template is compared with the overall allowable error to complete the template matching.
[0062] In the embodiment of the present invention, the template matching is performed on the image to be searched formed by the chip mounted on the substrate by using the template image through the AOI device, and the mounting position of the chip is detected and positioned as an example for explanation. In some other embodiments, the image to be searched formed by other targets mounted on other positions can also be obtained for template matching, and the relevant positions of other targets can be detected and positioned. The specific execution process can refer to the specific implementation method of obtaining the image to be searched formed by the chip mounted on the substrate for template matching in the embodiment of the present invention, and will not be repeated here.
[0063] To facilitate understanding of the single-target template matching method provided by the embodiment of the present invention, the electronic device 100 provided by the embodiment of the present invention is first introduced in detail.
[0064] See also Figure 4 As shown, Figure 4 FIG. 1 is a schematic diagram showing a structure of an electronic device 100 provided in some embodiments of the present invention. The electronic device 100 includes at least one processor 110 and a memory 120 ( Figure 4 In the example of a bus system connection and a processor, the components in the electronic device 100 are coupled together through the bus system 130, and the bus system 130 is used to realize the connection and communication between these components. It should be understood that the bus system 130 includes not only a data bus, but also a power bus, a control bus, and a status signal bus. However, for the sake of clarity and brevity, Figure 4 In the figure, various buses are labeled as bus system 130. Those skilled in the art will understand that Figure 4 The structure shown in the embodiment is only for illustration and does not impose any limitation on the structure of the electronic device 100. For example, the electronic device 100 may further include: Figure 4 More or fewer components as shown, or with Figure 4 Different configurations are shown.
[0065] Specifically, the processor 110 is used to provide computing and control capabilities to control the electronic device 100 to perform corresponding tasks. For example, the electronic device 100 is controlled to perform any single-target template matching method provided in the embodiment of the present invention, or any step in any possible implementation of any single-target template matching method provided in the embodiment of the present invention. Those skilled in the art can understand that the processor 110 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0066] The memory 120, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer executable programs, instructions and modules, for example, programs, instructions and modules corresponding to the single target template matching method in the embodiment of the present invention. In some embodiments, the memory 120 may include a storage program area and a storage data area, and the storage program area may store an operating system, an application required for at least one function; the storage data area may store data created according to the use of the processor 110, etc. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the non-transitory software programs, instructions and modules stored in the memory 120 to implement any single target template matching method provided in the embodiment of the present invention, or any step in any possible implementation of any single target template matching method provided in the embodiment of the present invention. Among them, the memory 120 may include a high-speed random access memory, and may also include a non-transitory memory. For example, at least one disk storage device, a flash memory device or other non-transitory solid-state storage device. In some embodiments, the memory 120 may also include a memory remotely arranged relative to the processor 110, and these remote memories may be connected to the processor 110 via a communication network. It can be understood that examples of the above-mentioned communication network include but are not limited to the Internet, corporate intranet, local area network, mobile communication network and combinations thereof.
[0067] It is easy to understand that the implementation and execution subject of any single target template matching method provided in the embodiments of the present invention can be any suitable type of electronic device with certain computing and control capabilities. In some possible implementations, any single target template matching method provided in the embodiments of the present invention can be implemented by a processor calling a computer program instruction stored in a memory.
[0068] It can be understood from the above that the single target template matching method provided by the embodiment of the present invention can be implemented by any suitable type of electronic device with certain computing and control capabilities, for example, it can be implemented by the above-mentioned desktop computer. The single target template matching method provided by the embodiment of the present invention is described in detail below in conjunction with the exemplary application and implementation of the electronic device provided by the embodiment of the present invention.
[0069] See also Figure 5 As shown, Figure 5 The flowchart of the single target template matching method provided by some embodiments of the present invention is shown. It should be understood that the single target template matching method provided by the embodiments of the present invention can be applied to the above electronic device (for example, a desktop computer), and the single target template matching method includes the following steps S100-S600:
[0070] Training steps:
[0071] S100: graying the template image to obtain a matching template.
[0072] Before performing template matching, it is necessary to grayscale the template image used for template matching by using image processing technology to obtain the corresponding matching template. Grayscale refers to the process of converting a color image into a grayscale image, that is, the process of converting the RGB (red, green, and blue) color value of each pixel into a single grayscale value. The template image can usually be grayscaled using methods such as averaging, weighted averaging, and grayscale coefficients to obtain a single-channel grayscale image, that is, a matching template. It is easy to understand that the template image can be pre-set and determined according to actual application requirements (for example, the number of pixels of the image to be searched and the matching accuracy, etc.).
[0073] S200: Divide the matching template into blocks according to complexity requirements into corresponding levels, and record the grayscale and corresponding grid coordinates of each block after division.
[0074] Among them, the complexity requirements include: for equal blocking at any level, when the complexity of sliding window matching after integrating the matching templates of each sub-block at this level exceeds the complexity of complete calculation of sliding window matching, it means that the advantage of sliding window matching by block integration is no longer obvious, so stop blocking and directly perform complete calculation of sliding window matching to save time and resources.
[0075] Specifically, the first level is the matching template when no block division is performed. In order to facilitate understanding and calculation in this embodiment, the matching template without block division is divided into the first level, the number of blocks in the first level is one, and the grayscale and corresponding grid coordinates of the first level are recorded. Then, the second level is evenly divided, and the sub-block matching template after the division is divided into the second level, and the grayscale and corresponding grid coordinates of each sub-block matching template of the second level after the division are recorded. Until the last level is evenly divided, if the complexity of sliding window matching after integrating the sub-block matching template after the last level is divided exceeds the complexity of sliding window matching after full calculation, it means that the advantage of sliding window matching by block integration is no longer obvious, and the matching template is stopped from being divided into blocks, and the full calculation sliding window matching is directly performed or other methods are used for matching calculation. This is explained in other embodiments and will not be repeated here.
[0076] In some embodiments, see Figure 6 and Figure 7 As shown, Figure 6 A sub-flow diagram of step S200 in the single target template matching method provided by some embodiments of the present invention is shown. Figure 7 An example diagram of dividing the matching template into blocks is shown. The matching template is divided into blocks into corresponding levels according to the complexity requirements, specifically including but not limited to the following steps S210-S250:
[0077] S210: Calculate and obtain the theoretical maximum number of blocks of the matching template according to the complexity requirement.
[0078] Specifically, to calculate the theoretical maximum number of blocks for a matching template, we first need to understand the computational complexity involved in the complexity requirement and the way the blocks are processed. Generally speaking, the complexity of a matching template can be evaluated by its size (number of pixels), the size of the blocks, and the sliding window step size. Assume that the size of the matching template is M×N, the size of each block is m×n, and the sliding window step size is s.
[0079] Next, consider the computational complexity of the matching process. The complexity of the complete sliding window matching is proportional to the size of the matching template, that is, O(MN). The complexity of sliding window matching after block integration is the number of blocks multiplied by the computational complexity of each block, that is, O((M / m)(N / n)(mn)), where (M / m)(N / n) represents the number of blocks and mn represents the computational complexity of each block.
[0080] Therefore, when the complexity of sliding window matching after block integration exceeds the complexity of fully calculating sliding window matching, we can get Inequality 1:
[0081] (M / m)(N / n)(mn)>MN, inequality 1 can be simplified to:
[0082] Inequality 2: m*n>m+n–1,
[0083] Since the size of a block can be any positive integer, the theoretical maximum number of blocks that meets the complexity requirement can be calculated according to Inequality 2. Inequality 2 can be simplified to finding the smallest combination of m and n that meets Inequality 2. After finding the smallest m and n that meet Inequality 2, the theoretical maximum number of blocks is (M / m)*(N / n).
[0084] S220: Divide the matching template into blocks, calculate the number of newly added blocks after the division, and add a level.
[0085] S230: Determine whether the total number of blocks combined with the number of newly added blocks exceeds the theoretical maximum number of blocks.
[0086] S240: When it is not exceeded, continue to divide into blocks and increase the level until the theoretical maximum number of blocks is reached.
[0087] S250: When it exceeds, exit the current block and the level is the level of the previous block.
[0088] Specifically, after calculating and determining the theoretical maximum number of blocks of the matching template, the matching template is equally divided into multiple levels to obtain a number of sub-block matching templates corresponding to each level, and the sub-block matching templates of each level are divided into the corresponding levels. Then the number of newly added blocks after the equal division of each level is calculated (that is, the number of blocks of the sub-block matching template of the level), and a level is added.
[0089] For equal block division at any level, add the number of new blocks after equal block division at this level to the number of blocks of sub-block matching templates obtained after equal block division at all previous levels, and obtain the total number of sub-block matching templates at each level after the division at this level (i.e., the total number of blocks). Compare the total number of blocks with the theoretical maximum number of blocks to determine whether the total number of blocks exceeds the theoretical maximum number of blocks.
[0090] If the total number of blocks does not exceed the theoretical maximum number of blocks, it means that the complexity of sliding window matching after block integration at this level does not exceed the complexity of complete sliding window matching calculation, and the advantage of block matching is still greater than that of complete sliding window matching calculation. Continue to divide the matching template into blocks and increase the corresponding levels until the total number of blocks reaches the theoretical maximum number of blocks.
[0091] If the total number of blocks exceeds the theoretical maximum number of blocks, it means that the complexity of sliding window matching after block integration at this level exceeds the complexity of fully calculating the sliding window matching, and the advantage of sliding window matching by block integration is no longer obvious. Exit this block and stop blocking the matching template. The last level of the block is the level of the previous block.
[0092] For example, in some embodiments, due to the small size of miniLED, even if the theoretical maximum block is one pixel per block, the total number of blocks is small, so the theoretical maximum number of blocks is also small. In this embodiment, it is assumed that the theoretical maximum number of blocks calculated is 64. The electronic device first performs equal block division on the matching template at the first level, divides the matching template into a complete block matching template, obtains a first sub-block matching template, divides the first sub-block matching template into the first level, and records the grayscale and corresponding grid coordinates of the first sub-block matching template.
[0093] At this time, the total number of sub-block matching templates at each level after the first-level blocking (i.e., the total number of blocks) is 1 (i.e., 1 first sub-block matching template at the first level), which does not exceed the theoretical maximum number of blocks of 64, and the first level is added as the level of matching template blocking.
[0094] The electronic device then equally divides the first sub-block matching template into blocks at the second level to obtain four second sub-block matching templates, divides the four second sub-block matching templates into the second level, and records the grayscale and corresponding grid coordinates of the four second sub-block matching templates.
[0095] At this time, the sum of the number of sub-block matching templates at each level after the second-level block division (i.e., the total number of blocks) is 1+4=5 (i.e., 1 first sub-block matching template at the first level and 4 second sub-block matching templates at the second level), which does not exceed the theoretical maximum number of blocks of 64. The second level is added as the level of matching template blocks, and at the same time Figure 7 What is shown in FIG. 1 is an example of dividing the matching templates into the second level.
[0096] The electronic device continues to equally divide the four second sub-block matching templates into blocks at the third level to obtain sixteen third sub-block matching templates, divides the sixteen third sub-block matching templates into the third level, and records the grayscale and corresponding grid coordinates of the sixteen third sub-block matching templates.
[0097] At this time, the total number of sub-block matching templates at each level after the third-level blocking (i.e., the total number of blocks) is 1+4+16=21 (i.e., the sum of 1 first sub-block matching template at the first level, 4 second sub-block matching templates at the second level, and 16 third sub-block matching templates at the third level), which does not exceed the theoretical maximum number of blocks of 64, and the third level is added as a level of matching template blocking.
[0098] The electronic device continues to perform equal block division of the sixteen third sub-block matching templates at the next level, calculates the total number of blocks, and compares the total number of blocks with the theoretical maximum number of blocks to determine whether the total number of blocks exceeds the theoretical maximum number of blocks. Until the sum of the number of sub-block matching templates at each level (i.e., the total number of blocks) after equal block division at the next level exceeds the theoretical maximum number of blocks of 64, it means that the complexity of sliding window matching after block integration at this level exceeds the complexity of sliding window matching after full calculation, and the advantage of sliding window matching by block integration is no longer obvious, and the current block division is exited, and the matching template is stopped from being divided into blocks, and the last level of the block division is the level of the previous block division.
[0099] It should be understood that in the above embodiment, the equal division of each level of the matching template is performed by dividing into four equal parts as an example, and in some other embodiments, the equal division of each level of the matching template can also be performed by dividing into two equal parts, six equal parts, etc., and the embodiment of the present invention does not impose any limitation on this. In other embodiments, when the template is divided equally in a certain direction, such as Figure 7 In the example, the size that has been equally divided in the width direction is equal to 1. At this time, the width direction cannot be equally divided any more, and only the length direction can be equally divided. Therefore, the equal division process varies with the type of template.
[0100] Matching steps:
[0101] S300: Set the overall tolerance.
[0102] Specifically, according to the actual application requirements of template matching (for example, the number of pixels of the matching template and the matching accuracy, etc.), the overall allowable error between the matching template and the pixel grayscale value in the image to be searched formed by mounting the chip on the substrate is preset.
[0103] See also Figure 8 As shown, Figure 8 A schematic diagram of a sub-process of step S300 in the single target template matching method provided in some embodiments of the present invention. In some embodiments, setting the overall allowable error specifically includes but is not limited to the following steps S310-S320:
[0104] S310: Determine a minimum allowable matching error based on empirical values.
[0105] The empirical value changes as the number of matches is performed. For example, the minimum allowable matching error determined in a certain miniLED matching can be set to 10, and set to 5 in other matching processes, depending on the actual matching.
[0106] S320: Setting the overall allowable error based on the minimum allowable matching error and the number of pixels.
[0107] Specifically, the matching template includes a number of pixels, for example, N pixels. In an embodiment of the present invention, the minimum allowable matching error of each pixel in the matching template is determined based on the historical experience data value of template matching, for example, M grayscales. Then the number of pixels and the minimum allowable matching error are multiplied to obtain the overall allowable error. In some embodiments, assuming that the matching template includes 16 pixels (that is, the number of pixels of the matching template is 16), the minimum allowable matching error of each pixel is 10 grayscales, then the overall allowable error is set to 16*10=160.
[0108] S400: Sliding a window in the image to be searched using the divided matching template.
[0109] Among them, it is necessary to use image processing technology to grayscale the image to be searched to obtain a single-channel grayscale image, that is, after the grayscale image to be searched is obtained, a window is slid in the grayscale image to be searched through the matching template after block division, and the matching error between the matching template in each sliding window and the grayscale value of the pixel in the grayscale image to be searched located in the sliding window is calculated, and then the matching error of the matching template is compared with the overall allowable error to determine the optimal position of the matching template. Obviously, the size of each sliding window is the same as the size of the matching template. Among them, when sliding the window, it is usually started from the upper left corner of the grayscale image to be searched, and the window is slid pixel by pixel in a sliding order from left to right and from top to bottom until the sliding window moves to the lower right corner of the grayscale image to be searched, and the sliding window is completed.
[0110] In some other embodiments, the sliding window may also be started from a position near the center of the grayscale image to be searched. In most actual application scenarios, the best position for template matching is more likely to appear near the center of the image to be searched. Therefore, starting the sliding window from a position near the center of the image to be searched can find a smaller matching error more quickly, which is used to screen out sliding windows that do not correspond to the best position for template matching in advance, thereby reducing the amount of calculation for template matching and improving matching efficiency.
[0111] S500: Calculate the matching error for each sliding window level by level using the integral graph.
[0112] Among them, the integral map is an image representation obtained by performing a cumulative sum operation on the original image, in which the integral value of each pixel represents the cumulative sum of the pixel grayscales of the upper left rectangular area. The integral map can greatly improve the calculation efficiency of the cumulative sum of the pixel grayscales of the rectangular area. Specifically, the integral map can be used to quickly calculate the cumulative sum of the pixel grayscales of a rectangular area. It only takes the integral value of the lower right corner of the rectangular area, minus the integral value of the lower left corner, minus the integral value of the upper right corner, and then adds the integral value of the overlapping part of the upper left corner that is repeatedly subtracted.
[0113] In the embodiment of the present invention, the integral value of each pixel in the grayscale image to be searched is calculated using the integral map, and the integral value of each pixel represents the cumulative sum of the pixel grayscales of the rectangular area in the upper left corner. For each sliding window, the integral map can be used to quickly calculate the cumulative sum of the overall pixel grayscales of the area corresponding to the sliding window in the grayscale image to be searched, and the cumulative sum of the pixel grayscales of any rectangular area in the area corresponding to the sliding window can be calculated.
[0114] In the aforementioned training step, the grayscale and corresponding grid coordinates of each sub-block matching template at each level after the matching template is divided into blocks have been recorded. For each level of the matching template, according to the grid coordinates of each sub-block matching template at each level, find the first area in the grayscale image to be searched that corresponds to the grid coordinates of the sub-block matching template at that level, calculate the cumulative sum of the pixel grayscales of the first area, and compare the cumulative sum of the pixel grayscales of the first area with the cumulative sum of the pixel grayscales of the sub-block matching template at that level to obtain the difference value between the pixel grayscale values of the sub-block matching template and the first area in the grayscale image to be searched. Then, the difference between the next sub-block matching template of the level and the pixel grayscale value of the corresponding area in the grayscale image to be searched is calculated, until the difference between all sub-block matching templates of the level and the pixel grayscale value of the corresponding area in the grayscale image to be searched is calculated, and then all the calculated difference values are added to obtain the matching error of the level, that is, the matching error between the pixel grayscale value of the matching template of the level and the grayscale image to be searched in the current sliding window. One level corresponds to one matching error.
[0115] See also Fig. 9 As shown, Fig. 9 A schematic diagram of a sub-process of step S500 in the single target template matching method provided by some embodiments of the present invention is shown. In some embodiments, the integral graph is used to calculate the matching error for each sliding window layer by layer, specifically including but not limited to the following steps S510-S530:
[0116] S510: Calculate the integral image of the image to be searched.
[0117] Specifically, after graying the image to be searched to obtain the grayed image to be searched, the integral image of the grayed image to be searched can be calculated based on the concept of integral image, wherein the integral image of the grayed image to be searched includes the integral value of each pixel in the grayed image to be searched.
[0118] S520: Obtain the overall grayscale accumulation corresponding to the blocks at each level of the matching template in the current sliding window through the integral image and the grid coordinate calculation.
[0119] For each sliding window, according to the grid coordinates of each sub-block matching template at each level in the current sliding window, find the area corresponding to the grid coordinates of the sub-block matching template at that level in the grayscale image to be searched, and obtain the integral value of the lower right corner pixel in the area, which is the cumulative sum of the pixel grayscales of the area in the grayscale image to be searched (that is, the overall cumulative sum of the grayscales corresponding to the sub-block matching template at that level of the matching template in the current sliding window).
[0120] S530: Compare the grayscale cumulative sum of the blocks in each level of the matching template with the overall grayscale cumulative sum corresponding to the blocks at each level of the matching template in the current sliding window to obtain a matching error, where each level corresponds to a matching error.
[0121] For the matching template, obtain the pixel grayscale cumulative sum of each sub-block matching template of each level recorded in the training step, and based on the integral image of the grayscale image to be searched, obtain the overall grayscale cumulative sum corresponding to the sub-block matching template of the level in the current sliding window.
[0122] Then, the grayscale cumulative sum of the sub-block matching template of the level is compared with the overall grayscale cumulative sum corresponding to the sub-block matching template of the level in the current sliding window to obtain the difference value corresponding to the sub-block matching template of the level, and then the difference value corresponding to the next sub-block matching template of the level is calculated, until the difference values of all sub-block matching templates of the level are calculated, and then the difference values of all sub-block matching templates of the level are added to obtain the matching error corresponding to the level. Among them, one level corresponds to one matching error.
[0123] In some embodiments, the grayscale values of each pixel of the matching template T are as follows:
[0124]
[0125] The grayscale values of each pixel of the grayscale image Y to be searched are as follows:
[0126]
[0127] Among them, since the matching template T must be included in the grayscale image to be searched Y, there are four sliding window positions of the matching template T in the grayscale image to be searched Y, namely:
[0128]
[0129] The corresponding four sliding windows are:
[0130]
[0131] In this embodiment, assuming that the theoretical maximum number of blocks of the matching template is 7, the matching template can be equally divided into the first and second levels to obtain a first sub-block matching template corresponding to the first level and four second sub-block matching templates corresponding to the second level, and the first sub-block matching template and the four second sub-block matching templates are divided into the first level and the second level respectively. The matching template T includes 16 pixels, assuming that the minimum allowable matching error of each pixel is 10 grayscales, so the overall allowable error is set to 16*10=160.
[0132] When the matching template slides to the position of the first sliding window, the cumulative sum of pixel grayscales of a first sub-block matching template of the first level of the matching template is: 20+30+50+70+40+30+60+10+35+75+85+22+56+23+35+12=653, and the cumulative sum of the overall grayscales corresponding to a first sub-block matching template of the first level in the first sliding window is 10+10+10+10+21+30+50+70+41+30+60+10+35+74+85+23=569, then the matching error of the first level is abs(653-569)=116.
[0133] The cumulative pixel grayscale sums of the four second sub-block matching templates of the second level of the matching template are: 20+30+40+30=120, 50+70+60+10=190, 35+75+56+23=189, 85+22+35+12=154, and the cumulative overall grayscale sums corresponding to the four second sub-block matching templates of the second level in the first sliding window are: 10+10+21+30=71, 10+10+50+70=140, 41+30+35+74=180, 60+10+85+23=178, then the matching error of the second level is abs(120-71)+abs(190-140)+abs(189-180)+abs(154-178)=132.
[0134] When the matching template slides to the position of the second sliding window, by the same token, the matching error of the first level is abs(653-502)=151, and the matching error of the second level is abs(120-100)+abs(190-100)+abs(189-249)+abs(154-53)=271.
[0135] When the matching template slides to the position of the third sliding window, by the same token, the matching error of the first level is abs(653-655)=2, and the matching error of the second level is abs(120-122)+abs(190-190)+abs(189-188)+abs(154-153)=4.
[0136] When the matching template slides to the position of the fourth sliding window, by the same token, the matching error of the first level is abs(653-542)=111, and the matching error of the second level is abs(120-170)+abs(190-100)+abs(189-217)+abs(154-55)=267.
[0137] S600: Compare the matching errors in each level with the overall allowable error to perform template matching.
[0138] Specifically, after calculating and obtaining the matching errors of each level of the matching template in each sliding window, the matching errors of each level are compared with the overall allowable error to perform template matching and determine whether the position corresponding to the current sliding window is the best position for template matching.
[0139] See also Fig.10 As shown, Fig.10 A schematic diagram of a sub-process of step S600 in the single target template matching method provided by some embodiments of the present invention is shown. In some embodiments, the matching errors in each level are compared with the overall allowable error to perform template matching, specifically including but not limited to the following steps S610-S630:
[0140] S610: Starting from the first level, the matching error of each level is compared with the overall allowable error to determine whether it is smaller than the overall allowable error.
[0141] Specifically, in any sliding window, starting from the first level of the matching template, the matching errors of each level are compared with the overall allowable error to determine whether the matching errors of each level are less than the overall allowable error. In the above embodiment, the overall allowable error is 160, so it is determined whether the matching errors of each level are less than the overall allowable error of 160.
[0142] S620: When the matching error of a certain level is greater than the overall allowable error, it means that the current sliding window position is not the best matching position, and the sliding window is skipped if the matching fails.
[0143] S630: When the matching errors of all levels are less than the overall allowable error, the minimum matching error and the position of the current sliding window are recorded until all sliding windows are calculated. The position of the sliding window with the minimum matching error is the optimal position.
[0144] Specifically, in any sliding window, if the matching error of any level of the matching template is greater than the overall allowable error, it means that the current sliding window position is not the best position for template matching, the matching fails, the sliding window is skipped, and the matching errors of each level of the matching template in the next sliding window are compared with the overall allowable error to perform template matching and determine whether the position corresponding to the current sliding window is the best position for template matching.
[0145] If the matching errors of all levels of the matching template are less than the overall allowable error, it means that the current sliding window position may be the best position for template matching. The minimum matching error and the current sliding window position are recorded. Then the matching errors of each level of the matching template in the next sliding window are compared with the overall allowable error to perform template matching and determine whether the position corresponding to the current sliding window is the best position for template matching. After all sliding windows are calculated and compared, the sliding window position corresponding to the minimum matching error is the best position for template matching.
[0146] For example, in the above embodiment, the matching error of the first level of the matching template in the first sliding window is 116, and the matching error of the second level is 132, both of which are less than the overall allowable error of 160. Then the minimum matching error of 116 is recorded, and the position of the first sliding window is recorded.
[0147] The matching error of the first level of the matching template in the second sliding window is 151, and the matching error of the second level is 271. The matching error 271 of the second level is greater than the overall allowable error 160, indicating that the current sliding window position is not the best position for template matching, the matching fails, and the sliding window is skipped.
[0148] The matching error of the first level of the matching template in the third sliding window is 2, and the matching error of the second level is 4, both of which are less than the overall allowable error of 160. Then the minimum matching error of 2 is recorded, and the position of the third sliding window is recorded.
[0149] The matching error of the first level of the matching template in the fourth sliding window is 111, and the matching error of the second level is 267. The matching error 267 of the second level is greater than the overall allowable error 160, indicating that the current sliding window position is not the best position for template matching, the matching fails, and the sliding window is skipped.
[0150] At this point, all sliding windows have been calculated and compared, and the sliding window with the smallest matching error is the third sliding window, so the position of the third sliding window is the best position for template matching.
[0151] In some embodiments, after the current sliding window calculation and comparison are completed, the overall allowable error can be updated, and the updated overall allowable error can be used as the error threshold for filtering out sliding windows that are not at the best position, and then the matching errors of each level of the matching template in the next sliding window are compared with the updated overall allowable error to perform template matching and determine whether the position corresponding to the current sliding window is the best position for template matching. That is, after a sliding window calculation is completed, the minimum error at this time is updated, and then the minimum error is continued to be used as the error threshold for early pruning, which can effectively increase the number of sliding windows excluded.
[0152] For example, after the calculation and comparison of the first sliding window is completed, since the matching error of the first level of the matching template in the first sliding window is 116 and the matching error of the second level is 132, both of which are smaller than the overall allowable error 160, the overall allowable error can be updated to the smaller first level matching error 116, and the updated overall allowable error is 116. Then, the matching errors of each level of the matching template in the next sliding window are compared with the updated overall allowable error 116 to perform template matching and determine whether the position corresponding to the current sliding window is the best position for template matching.
[0153] This embodiment further explores the difference between dividing the image into equal blocks and the conventional technology. For example, when a sliding window is divided into four blocks, two of which are 20 grayscale darker than the template, and the other two are 20 grayscale brighter. In the conventional technology, the error of the overall cumulative sum will be relatively small. However, by adopting the method in this embodiment, each block is viewed separately in a block-by-block manner, and it will be found that the cumulative sum error of each block is large, and the total error is relatively large, so as to achieve the purpose of eliminating this sliding window.
[0154] In some embodiments, in order to screen out sliding windows that are not in the optimal position in advance, in any sliding window, when the matching errors of all levels of the matching template are less than the overall allowable error, the matching error of the current sliding window can be calculated pixel by pixel for the matching template, that is, the difference between the grayscale values of the pixels of the matching template and the grayscale image to be searched in the current sliding window.
[0155] See also Fig.11 As shown, Fig.11 Another sub-process diagram of step S600 in the single target template matching method provided by some embodiments of the present invention is shown. In some embodiments, the matching errors in each level are compared with the overall allowable error to perform template matching, and also includes but is not limited to the following steps S640-S660:
[0156] S640: Calculate the matching error of the current sliding window pixel by pixel through the vector instruction set, and determine whether the matching error is greater than the overall allowable error.
[0157] Specifically, in any sliding window, when the matching errors of all levels of the matching template are less than the overall allowable error, the matching error of the current sliding window can be calculated pixel by pixel for the pixels in the matching template through a vector instruction set, that is, the difference between the grayscale values of the pixels of the matching template and the grayscale image to be searched in the current sliding window. After the matching error of the current sliding window is calculated, it is compared with the overall allowable error to determine whether the matching error of the current sliding window is greater than the overall allowable error. Among them, vector instructions refer to an instruction set in a computer processor for performing parallel operations on a set of data. Vector instructions can perform the same operation on multiple data elements at the same time (for example, subtracting the grayscale values of several pixels of the matching template from the grayscale values of the pixels corresponding to the grayscale image to be searched in the current sliding window), thereby processing multiple data in a single instruction cycle. By adopting the vector instruction set, the advantages of parallel computing can be better utilized to improve the speed of calculating the matching error of the current sliding window pixel by pixel, thereby improving the matching speed.
[0158] For example, in the above embodiment, the matching error of the first level of the matching template in the first sliding window is 116, and the matching error of the second level is 132, both of which are less than the overall allowable error of 160. Then, the matching error of the first sliding window is calculated pixel by pixel for the matching template through the vector instruction set. In the embodiment of the present invention, the vector instruction set is used to adopt the simd (Single Instruction, Multiple Data) method to calculate the difference between the grayscale values of the matching template and the 8 pixels in the first sliding window at one time. In the first calculation, the grayscale values of the 8 pixels of the matching template are: 20, 30, 50, 70, 40, 30, 60, 10, respectively, and the grayscale values of the 8 pixels of the first sliding window are: 10, 10, 10, 10, 21, 30, 50, 70, respectively. The grayscale values of the 8 pixels of the matching template are subtracted from the corresponding grayscale values of the 8 pixels of the first sliding window, and the difference values are: abs(20-10)+abs(30-10)+abs(50-10)+ abs(70-10)+abs(40-21)+abs(30-30)+abs(60-50)+abs(10-70)=219. It should be understood that the SIMD (Single Instruction, Multiple Data) method is a parallel computing method that allows a single vector instruction to process multiple data elements simultaneously. The SIMD method organizes data into vectors or arrays, and then operates the entire vector through a single instruction to achieve parallel operations on multiple data elements in a single instruction cycle. Parallel operations may include addition, multiplication, and bit operations.
[0159] Theoretical analysis of the multiple acceleration of the matching error calculation of each sliding window using the vector instruction set. When the vector instruction set is not used, it is necessary to traverse the matching template and the corresponding pixel of the current sliding window pixel by pixel, subtract them, and then take the absolute value. Assuming that the total number of pixels is N, it can be seen that N subtractions and N absolute values, as well as N additions are required. The complexity of the absolute value calculation can be ignored, that is, the complexity of 2N additions is required, and subtraction is regarded as addition. We know that the pixel representation of an image is generally represented by one byte, because the grayscale value of a pixel is generally between 0 and 255. Using SSE128-bit registers for acceleration, theoretically one register can store the grayscale value of 16 pixels and then operate 16 pixels at a time, but because we need to pay attention to the overflow of subtraction, we cannot use one byte to represent the grayscale value of a pixel. We need to use 2 bytes upward so that the grayscale value of the pixel can retain the positive and negative signs after subtraction, so that the absolute value can be taken correctly. Therefore, one register can only process 8 pixels at a time. At this time, we take the 8 pixels corresponding to the matching template and the current sliding window at a time, subtract and accumulate them, that is, after a serial subtraction and addition, it is easy to know that the processing of a sliding window at this time requires the complexity of N / 4 addition operations, which is a theoretical speedup of 8 times.
[0160] S650: When it is greater than, it means that the current sliding window position is not the best matching position, and the sliding window is skipped if the matching fails.
[0161] When the matching error of the current sliding window is greater than the overall allowable error, it means that the position of the current sliding window is not the best matching position, the matching fails, the sliding window is skipped, and the matching errors of each level of the matching template in the next sliding window are compared with the overall allowable error to perform template matching and determine whether the position corresponding to the current sliding window is the best position for template matching.
[0162] For example, in the above embodiment, when the matching error of the first sliding window is calculated pixel by pixel, the difference value 219 obtained by the first calculation is greater than the overall allowable error 160, indicating that the position of the current sliding window is not the best matching position, the matching fails, the sliding window is skipped, and the matching errors of each level of the matching template in the next sliding window are compared with the overall allowable error to perform template matching and determine whether the position corresponding to the current sliding window is the best position for template matching.
[0163] S660: When it is not greater than, the matching error is saved and incorporated into all matching errors after all sliding windows are calculated. The position with the smallest matching error is the best position.
[0164] When the matching error of the current sliding window calculated pixel by pixel by pixel through the vector instruction set is not greater than the overall allowable error, it means that the current sliding window position may be the best position for template matching, and the matching error is saved. After all sliding windows are calculated and compared, the matching error is incorporated into all the matching errors recorded, and the minimum matching error is selected from all the matching errors. The sliding window position corresponding to the minimum matching error is the best position for template matching.
[0165] In summary, the single-target template matching method provided by an embodiment of the present invention is applied to an electronic device, and the method includes: a training step: graying the template image to obtain a matching template; dividing the matching template into blocks according to complexity requirements into corresponding levels, and recording the grayscale and corresponding grid coordinates of each block after division; a matching step: setting an overall allowable error; sliding a window in the image to be searched through the divided matching template; using an integral map to calculate the matching error for each sliding window level by level; and comparing the matching error in each level with the overall allowable error to perform template matching.
[0166] Since it is a single target matching, we only need to examine the position of the minimum matching error. Therefore, we do not need to fully calculate each sliding window when sliding the window. Instead, if the accumulated error in the calculation process of a certain sliding window has exceeded the minimum matching error recorded at this time, the calculation will be stopped at that position. It is definitely not the optimal target position. This method can greatly speed up the process for a single target.
[0167] It can be seen that one of the ideas of this application is to eliminate a sliding window in advance through some methods, which can greatly reduce the amount of calculation. This also leads to the core idea of this application - early pruning based on block integration.
[0168] We can see a problem from the above. If there is a way to know in advance which sliding window is closer to the target position, so as to obtain a smaller minimum error and exclude a large number of sliding windows, there will be a chance to continue to accelerate the algorithm.
[0169] Under normal conditions, it is impossible to know which sliding window is closer to the target. Fortunately, in most actual scenarios, the target is more likely to appear near the center. Therefore, we can match the sliding window near the center first, so as to find a smaller minimum error more quickly for early pruning of the sliding window.
[0170] Finally, the sliding window position corresponding to the minimum error is returned to obtain the matching result.
[0171] The single-target template matching method provided by the embodiment of the present invention divides the matching template into blocks, uses the integral map to calculate the matching error of the matching template for each sliding window layer by layer, compares the matching error of each level of the matching template with the overall allowable error, performs early pruning of the sliding window, completes template matching quickly and accurately, reduces the calculation amount of template matching, and improves the matching speed.
[0172] An embodiment of the present invention provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are called by a processor, the processor executes any single-target template matching method provided by the embodiment of the present invention, or steps in any possible implementation of any single-target template matching method provided by the embodiment of the present invention.
[0173] In some embodiments, the storage medium may be a flash memory, a hard disk, an optical disk, a register, a magnetic surface storage, a removable disk, a CD-ROM, a random access memory (RAM), a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM or other memory, or any other form of storage medium known in the technical field, or may be various devices including one or any combination of the above storage media.
[0174] In some embodiments, computer program instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0175] As an example, computer program instructions may, but need not, correspond to a file in a file system, may be stored as part of a file storing other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0176] As an example, the computer program instructions may be deployed to be executed on a computing device (including devices such as smart terminals and servers), or on multiple computing devices located at one location, or on multiple computing devices distributed at multiple locations and interconnected by a communication network. It is easy to understand that all or part of the steps of the method described in the embodiments provided by the present invention above can be directly implemented using electronic hardware or processor executable computer program instructions, or a combination of the two.
[0177] The technicians can understand that the embodiments provided by the present invention are only illustrative, and the writing order of each step in the method of the embodiment does not mean a strict execution order and does not constitute any limitation on the implementation process. The order can be adjusted, merged and deleted according to actual needs. The modules or sub-modules, units or sub-units in the device or system of the embodiment can be merged, divided and deleted according to actual needs. For example, the division of units is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed.
[0178] It should be noted that the above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with this technology to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the scope of protection of the present invention. Ordinary technicians in this field can understand that all or part of the processes of implementing the above embodiments, and the equivalent changes and modifications made according to the claims of the present invention should all fall within the scope of the claims of the present invention.
Claims
1. A single target template matching method, applied to electronic equipment, It is characterized in that The method comprises: Training steps: Grayscale the template image to obtain a matching template; Divide the matching template into blocks according to the complexity requirements into corresponding levels, and record the grayscale and corresponding grid coordinates of each block after the division, respectively, wherein the grayscale and the grid coordinates are used to calculate the matching error of each level in each sliding window; Matching steps: Set the overall tolerance; Sliding a window in the image to be searched by using the divided matching template, wherein sliding a window is preferentially performed near the center of the image to be searched; According to the grayscale of each block after division and the corresponding grid coordinates, the matching error is calculated layer by layer for each sliding window using the integral image, and each layer corresponds to a matching error; The matching errors in each level are respectively compared with the overall allowable error to perform template matching, wherein, when there is a first matching error less than or equal to the overall allowable error among the matching errors corresponding to each level of the current sliding window, the overall allowable error is updated to the minimum value of the first matching errors.
2. The single target template matching method according to claim 1, It is characterized in that The complexity requirements include: When the complexity of sliding window matching after block integration exceeds the complexity of complete sliding window matching calculation, block division is stopped.
3. The single target template matching method according to claim 2, It is characterized in that The step of dividing the matching template into blocks according to complexity requirements into corresponding levels includes: The theoretical maximum number of blocks of the matching template is calculated according to the complexity requirement; Divide the matching template into blocks, calculate the number of newly added blocks after the blocks are divided, and add a level; Determine whether the total number of blocks combined with the number of newly added blocks exceeds the theoretical maximum number of blocks; If it is not exceeded, continue to divide into blocks and increase the level until the theoretical maximum number of blocks is reached; When it exceeds the limit, the current block is exited and the level is the level of the previous block.
4. The single target template matching method according to claim 1, It is characterized in that The matching template also includes the number of pixels, and the setting of the overall allowable error includes: Determine the minimum allowable matching error based on empirical values; An overall allowable error is set based on the minimum allowable matching error and the number of pixels.
5. The single target template matching method according to any one of claims 1 to 4, It is characterized in that The use of the integral graph to calculate the matching error level by level in each sliding window includes: Calculate the integral image of the image to be searched; The overall grayscale accumulation corresponding to the blocks at each level of the matching template in the current sliding window is obtained through the integral image and the grid coordinate calculation; The grayscale cumulative sum of the blocks in each level of the matching template is compared with the overall grayscale cumulative sum corresponding to the blocks at each level of the matching template in the current sliding window to obtain the matching error.
6. The single target template matching method according to claim 1, It is characterized in that The step of respectively comparing the matching errors in each level with the overall allowable error to perform template matching includes: Starting from the first level, the matching error of each level is compared with the overall allowable error to determine whether it is less than the overall allowable error; When the matching error of a certain level is greater than the overall allowable error, it means that the current sliding window position is not the best matching position, and the sliding window is skipped if the matching fails; When the matching errors of all levels are less than the overall allowable error, the position with the smallest matching error is recorded until all sliding windows are calculated. The position with the smallest matching error is the best position.
7. The single target template matching method according to claim 6, It is characterized in that When the matching errors of all levels are less than the overall allowable error, the method further includes: Calculating the matching error of the current sliding window pixel by pixel through a vector instruction set, and determining whether the matching error is greater than the overall allowable error; If it is greater than , it means that the current sliding window position is not the best matching position, and the sliding window will be skipped if the matching fails; When it is not greater than, the matching error is saved and incorporated into all matching errors after all sliding windows are calculated. The position with the smallest matching error is the best position.
8. An electronic device, It is characterized in that include: A processor, and a memory communicatively connected to the processor; The memory stores computer program instructions executable by the processor, and when the computer program instructions are called by the processor, the processor executes the single-target template matching method according to any one of claims 1 to 7.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer program instructions, and when the computer program instructions are called by a processor, the processor executes the single-target template matching method according to any one of claims 1 to 7.
