Shape matching method and system based on NCC template matching, electronic equipment and storage medium

By preprocessing the target image, extracting and superimposing shapes and contours, combining the NCC matching method and superimposition enhancement algorithm, the failure problem of template matching in the prior art under complex conditions is solved, and higher matching accuracy and system stability are achieved.

CN120070926AActive Publication Date: 2025-05-30SHENZHEN SEICHITECH TECHN CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510541551.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-28
Publication Date
2025-05-30
Estimated Expiration
2045-04-28

AI Technical Summary

Technical Problem

The existing NCC template matching method can easily cause NCC value distortion when processing blur, occlusion or lighting changes in the image, and thus cannot accurately determine the position of the template, resulting in matching failure.

Method used

By preprocessing the target image, the shape outline is extracted and superimposed on the target image, an NCC matching method is used. If the initial match is less than the preset standard, use the overlay enhancement algorithm to re-overlay the shape profile and repeat the matching process until the match reaches the preset standard.

Benefits of technology

It improves the accuracy and success rate of template matching, enhances the stability and reliability of the system in complex environments, and reduces misjudgment and misjudgment caused by matching failure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120070926A_ABST
    Figure CN120070926A_ABST
Patent Text Reader

Abstract

The invention discloses a shape matching method and system based on NCC template matching, electronic equipment and a storage medium, which are used for improving the accuracy of NCC template matching. The shape matching method based on NCC template matching comprises the following steps: preprocessing a target image to obtain a preprocessed image; extracting the shape contour of the preprocessed image according to an edge detection algorithm and an edge enhancement algorithm; superposing the shape contour to the target image to obtain a to-be-detected image; further performing NCC matching on the to-be-detected image and a preset template to obtain a matching degree; if the matching degree is smaller than a preset standard, according to a superposition enhancement algorithm, the shape contour is superposed to the target image again, and NCC matching is carried out again; and repeatedly executing the step of overlapping the shape contour to the target image again according to the overlapping enhancement algorithm, and performing NCC matching again until the matching degree is greater than or equal to a preset standard.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the technical field of image matching, and in particular, to a shape matching method, system, electronic device, and storage medium based on NCC template matching. Background Art

[0002] In the rapidly developing fields of computer vision, image processing, and pattern recognition today, template matching, as a key research direction, plays an important role. Its core lies in accurately locating a specific pattern in an image and comparing and matching it with a pre-set template. This technology is widely used in many key fields. For example, in the field of target detection, it can be used to identify specific people or objects in security monitoring; in object recognition, it helps to accurately identify and classify components on industrial production lines; and in the field of robot navigation, it enables robots to identify specific landmarks or obstacles in the surrounding environment, thus achieving autonomous navigation. Many application scenarios fully demonstrate the important value and wide applicability of template matching technology.

[0003] Currently, there are already various methods for template matching. Among them, the template matching method based on NCC (Normalized Cross-Correlation) is relatively common. This method divides the image to be matched into several small regions, calculates the NCC values between these small regions and the template one by one, and then determines the position of the template in the image to be matched according to the position where the maximum NCC value is located. When dealing with high-definition images, this method can relatively effectively achieve accurate matching and obtain good results. However, when the target shape in the image is blurred, partially occluded, or affected by changes in light intensity and angle, etc., the calculated NCC values are extremely prone to distortion, resulting in the inability to accurately judge the true position of the template, and ultimately leading to matching failure, making it difficult to meet the complex and changeable actual application requirements. Summary of the Invention

[0004] The present application discloses a shape matching method, system, electronic device, and storage medium based on NCC template matching, which is used to improve the accuracy of NCC template matching.

[0005] The first aspect of the present application discloses a shape matching method based on NCC template matching, including: Preprocess the target image to obtain a preprocessed image; Extract the shape contour of the preprocessed image according to the edge detection algorithm and the edge enhancement algorithm; Superimpose the shape contour on the target image to obtain a to-be-detected image; Perform NCC matching on the to-be-detected image and a pre-set template to obtain a matching degree; If the matching degree is less than the preset standard, then according to the superposition enhancement algorithm, the shape contour is superimposed on the target image again, and the NCC matching is performed again; Repeat the step of superimposing the shape contour on the target image again according to the superposition enhancement algorithm and performing the NCC matching again until the matching degree is greater than or equal to the preset standard.

[0006] Optionally, the extracting the shape contour of the preprocessed image according to the edge detection algorithm and the edge enhancement algorithm includes: Calculating the first-order derivative of the target image according to the Sobel operator to obtain the convolution result D in the x direction x and the convolution result D in the y direction y ; Combining the convolution result D in the x direction x and the convolution result D in the y direction y to obtain a combined result; Normalizing the combined result to a preset range to obtain a normalized result, where the preset range is preset according to the number of bits of the target image; Setting to zero the part of the normalized result that is less than the preset threshold according to the preset threshold to obtain a zero-setting result; Enhancing the zero-setting result according to the edge enhancement algorithm to obtain a shape contour.

[0007] Optionally, the combining the convolution result D in the x direction x and the convolution result D in the y direction y , to obtain a combined result includes: Obtaining a combining formula, the combining formula is as follows: ; where I is the combined result, D x is the convolution result in the x direction, D y is the convolution result in the y direction; Calculating the combined result according to the combining formula.

[0008] Optionally, the enhancing the zero-setting result according to the edge enhancement algorithm to obtain a shape contour includes: Obtaining an edge enhancement formula, the edge enhancement formula is as follows: ; where (x, y) is the coordinate of the pixel point to be enhanced in the zero-setting result, G (x,y) is the enhancement result of the pixel point to be enhanced (x, y), I (x,y) is the combined result corresponding to the pixel point to be enhanced (x, y), S 1 is the first enhancement coefficient, O1 is the first enhancement offset; Calculate the enhancement result of each pixel to be enhanced in the zeroing result according to the edge enhancement formula, and multiple enhancement results constitute a shape contour.

[0009] Optionally, the step of superimposing the shape contour on the target image to obtain a to-be-detected image includes: When the mean value of the shape contour is greater than the background mean value of the target image, calculate according to the first superimposition formula to obtain the to-be-detected image, and the first superimposition formula is: , where G is the to-be-detected image, G1 is the target image, and G2 is the shape contour; When the mean value of the shape contour is less than the background mean value of the target image, calculate according to the second superimposition formula to obtain the to-be-detected image, and the second superimposition formula is: , where G is the to-be-detected image, G1 is the target image, and G2 is the shape contour.

[0010] Optionally, the step of re-superimposing the shape contour on the target image according to the superimposition enhancement algorithm includes: When the mean value of the shape contour is greater than the background mean value of the target image, calculate according to the third superimposition formula to obtain the to-be-detected image, and the third superimposition formula is: , where G is the to-be-detected image, G1 is the target image, G2 is the shape contour, S 2 is the second enhancement coefficient, O 2 is the second enhancement offset; When the mean value of the shape contour is less than the background mean value of the target image, calculate according to the fourth superimposition formula to obtain the to-be-detected image, and the fourth superimposition formula is: , where G is the to-be-detected image, G1 is the target image, G2 is the shape contour, S 3 is the third enhancement coefficient, O 3 is the third enhancement offset.

[0011] Optionally, the preprocessing includes at least one of the following: mean filter noise reduction processing, median filter noise reduction processing, and Gaussian filter noise reduction processing.

[0012] The second aspect of the present application discloses a shape matching system based on NCC template matching, including: A preprocessing unit for preprocessing a target image to obtain a preprocessed image; A shape contour unit for extracting the shape contour of the preprocessed image according to an edge detection algorithm and an edge enhancement algorithm; An image unit to be detected, configured to superimpose the shape contour on the target image to obtain an image to be detected; A matching unit, configured to perform NCC matching on the image to be detected and a preset template to obtain a matching degree; A re - execution unit, configured to, if the matching degree is less than a preset standard, re - superimpose the shape contour on the target image according to a superposition enhancement algorithm and perform NCC matching again; A repeating unit, configured to repeatedly execute the step of re - superimposing the shape contour on the target image according to the superposition enhancement algorithm and performing NCC matching again until the matching degree is greater than or equal to the preset standard.

[0013] A third aspect of the present application provides an electronic device, including: A processor, a memory, an input / output unit, and a bus; The processor is connected to the memory, the input / output unit, and the bus; The memory stores a program, and the processor calls the program to execute the shape matching method based on NCC template matching as described in the first aspect and any optional aspect of the first aspect.

[0014] A fourth aspect of the present application provides a computer - readable storage medium, on which a program is stored. When the program is executed on a computer, it executes the shape matching method based on NCC template matching as described in the first aspect and any optional aspect of the first aspect.

[0015] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages: The shape matching method based on NCC template matching provided by this application first preprocesses the target image to obtain a preprocessed image; then extracts the shape contour of the preprocessed image according to the edge detection algorithm and the edge enhancement algorithm; then superimposes the shape contour on the target image to obtain an image to be detected; further performs NCC matching between the image to be detected and a preset template to obtain a matching degree; if the matching degree is less than the preset standard, then according to the superimposition enhancement algorithm, the shape contour is superimposed on the target image again, and NCC matching is performed again; repeat the steps of superimposing the shape contour on the target image again according to the superimposition enhancement algorithm and performing NCC matching again until the matching degree is greater than or equal to the preset standard and then end. This shape matching method extracts and superimposes the shape contour through the edge detection algorithm and the edge enhancement algorithm, which can highlight the key shape features of the target object, so that when performing NCC matching, even if the target object has a certain degree of blur or occlusion, the area similar to the template can be found more accurately. When the matching degree of the first NCC matching is less than the preset standard, the superimposition enhancement algorithm is introduced, and the steps of shape contour superimposition and re-matching are repeated until a satisfactory matching effect is achieved, greatly improving the success rate and accuracy of template matching, thereby enhancing the stability and reliability of the entire system in a complex environment, and reducing misjudgment and missed judgment caused by matching failure. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the embodiments of this application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the following drawings are only some embodiments of this application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0017] Figure 1 Schematic diagram of an embodiment of the shape matching method based on NCC template matching of this application; Figure 2 Schematic diagram of an embodiment of the method for extracting the shape contour of the preprocessed image of this application; Figure 3 Schematic diagram of another embodiment of the shape matching method based on NCC template matching of this application; Figure 4 Schematic diagram of another embodiment of the shape matching method based on NCC template matching of this application; Figure 5 Schematic diagram of an embodiment of the shape matching system based on NCC template matching of this application; Figure 6 Schematic diagram of an embodiment of the electronic device of this application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0018] In the following description, for the purpose of illustration rather than limitation, specific details such as specific system architectures, technologies, etc. are presented to provide a thorough understanding of the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.

[0019] It should be understood that when used in the specification of the present application, the term "comprising" indicates the presence of the described features, wholes, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.

[0020] It should also be understood that the term "and / or" as used in the specification of the present application refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0021] As used in the specification of the present application, the term "if" can be interpreted as "when" or "once" or "in response to determining" or "in response to detecting" depending on the context. Similarly, the phrases "if determined" or "if [the described condition or event] is detected" can be interpreted as meaning "once determined" or "in response to determining" or "once [the described condition or event] is detected" or "in response to detecting [the described condition or event]" depending on the context.

[0022] In addition, in the description of the specification of the present application, the terms "first", "second", "third", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.

[0023] The reference to "one embodiment" or "some embodiments" or the like described in the specification of the present application means that a specific feature, structure, or characteristic described in connection with that embodiment is included in one or more embodiments of the present application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments", etc. that appear in different places in this specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in another way. The terms "comprising", "including", "having", and their variants all mean "including but not limited to", unless otherwise specifically emphasized in another way.

[0024] In the fields of computer vision technology, image processing technology, and pattern recognition technology, template matching is one of the important research directions. The purpose of template matching is to find a specific pattern in an image and compare and match it with a preset template. This technology has a wide range of applications in fields such as object detection, object recognition, and robot navigation. There are various existing template matching methods, and one common method is the method based on NCC (Normalized Cross-Correlation) template matching. The basic idea of this method is to first divide the image to be matched into several small regions, then calculate the NCC value between each small region and the template, and finally determine the position of the template in the image to be matched through the position of the maximum NCC value. This method has good results when processing images with higher clarity. However, the existing template matching methods based on NCC template matching have certain limitations when processing images in some special cases. For example, when there are situations such as blurred, occluded, or lighting-changed target shapes in the image, the NCC value may be distorted, resulting in matching failure.

[0025] Based on this, the present application discloses a shape matching method, system, electronic device, and storage medium based on NCC template matching, which are used to improve the accuracy of NCC template matching.

[0026] Next, the technical solutions in the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0027] The method of the present application can be applied to servers, devices, terminals, or other devices with logical processing capabilities. In this regard, the present application makes no limitation. For the convenience of description, the following will be described by taking the execution subject as a terminal as an example.

[0028] Please refer to Figure 1 , an embodiment of a shape matching method based on NCC template matching provided by the present application includes: 101, preprocess the target image to obtain a preprocessed image; In this embodiment, in order to improve the image quality, remove noise, adjust brightness and contrast, etc., make the image more suitable for subsequent processing steps, and improve the accuracy of shape contour extraction and template matching, the target image can be preprocessed first. The preprocessing includes at least one of the following: mean filtering noise reduction processing, median filtering noise reduction processing, and Gaussian filtering noise reduction processing. Gaussian filtering noise reduction processing can effectively smooth the image and remove Gaussian noise by performing weighted averaging on each pixel point in the image and the pixel values in its neighborhood, where the weights conform to a Gaussian distribution. Median filtering noise reduction processing is to sort the pixel values in the pixel neighborhood and take the middle value as the new value of the pixel point, which has a good effect on removing salt-and-pepper noise.

[0029] In addition to the above noise reduction processing, the brightness and contrast of the target image can also be adjusted by methods such as linear transformation or histogram equalization. Linear transformation can perform multiplication and addition operations on each pixel value of the image according to the given gain and bias values, changing the overall brightness and contrast of the image. Histogram equalization is to enhance the contrast of the image by redistributing the gray histogram of the image, so that the details in the image are clearer.

[0030] 102. Extract the shape contour of the preprocessed image according to the edge detection algorithm and the edge enhancement algorithm; In this embodiment, in order to highlight the edge information of the target object in the image and provide key feature information for subsequent matching with the template, the shape contour of the preprocessed image obtained in step 101 should be extracted. Among them, the edge detection algorithm can include the Sobel operator and can also include the Canny edge detection algorithm. Using the Sobel operator, by performing convolution calculations on the preprocessed image in the x and y directions respectively, the approximate values of the first-order derivatives (D x and D y ) of the preprocessed image in the two directions are obtained, and then the gradient magnitude and direction are calculated. The positions with larger magnitudes usually correspond to the edges of the image. The Canny edge detection algorithm first performs Gaussian filtering and smoothing on the image, then calculates the gradient magnitude and direction, then performs non-maximum suppression to remove those pixel points that are not local maxima, and finally obtains a clear edge image through double-threshold detection and connecting edges.

[0031] Based on the above edge detection algorithm, the intensity and clarity of the edge are further enhanced. For example, by weighted amplification of the gray values of the edge pixel points or using methods such as the Laplace operator, the edge can be made more prominent, so as to more accurately extract the shape contour of the target object.

[0032] 103. Superimpose the shape contour on the target image to obtain the image to be detected; In this embodiment, an image fusion method can be adopted to superimpose the shape contour onto the target image with a certain transparency or weight. For example, for a binary shape contour image (where the contour pixels are white and the background is black), the gray values of the white contour pixels can be added to the pixel values at the corresponding positions of the target image in a certain proportion, or by setting the transparency of the pixels, the contour can be made to appear more clearly on the target image without affecting other information of the target image, thereby obtaining the image to be detected. In step 103, the extracted shape contour information is incorporated into the target image to make the features of the target object more obvious, which helps to improve the accuracy and success rate of matching in the subsequent NCC matching.

[0033] 104. Perform NCC matching on the image to be detected and a pre-set template to obtain the matching degree. In this embodiment, it should be noted that when the target is clear and the standard image of the target object is easily obtainable, the standard sample image can be directly used as the template; for some cases where there is no ready-made standard image, especially when the image content is relatively complex or a specific target area needs to be detected, the template can be obtained by manual annotation; if there is a database containing a large number of images that have been classified according to certain categories, then representative images can be selected from a specific category as the template. In step 104, first, the image to be detected is divided into several small regions (usually regions of the same size as the pre-set template), and then for each small region, the NCC value between it and the template is calculated. After calculating the NCC values of all small regions, the maximum NCC value and its corresponding position are found. This position is the preliminary matching position of the template in the image to be detected, and the maximum NCC value is the matching degree of this matching.

[0034] It should also be noted that the NCC value in this embodiment can be calculated according to the following formula: ; where m is the sum of the number of pixel points in the image to be detected and the template, (u, v) are the coordinates of the pixel points, S m(u,v) is the NCC value (i.e., the NCC matching degree), is the average gradient value in the x direction, is the average gradient value in the y direction, is the feature value in the x direction of the pixel point (u + x i , v + y i ), is the feature value in the y direction of the pixel point (u + x i , v + y i ).

[0035] 105. If the matching degree is less than the preset standard, then according to the superposition enhancement algorithm, the shape contour is re-superimposed on the target image, and the NCC matching is performed again; In this embodiment, it should be noted that the preset standard is set according to the target image and actual requirements. For a matching operation with higher requirements, the preset standard can be above 0.9 (the value of the matching degree is between 0 and 1). When the result of the first NCC matching is not ideal (the matching degree is less than the preset standard), by further enhancing the feature information of the shape contour in the target image, the matching is tried again to improve the matching degree and achieve more accurate template positioning. Specifically, the contrast of the shape contour can be increased, or the width of the shape contour can be enlarged (by performing a dilation operation on the contour pixels) to make it more prominent in the image. For example, using a morphological dilation operation, the edge of the shape contour is expanded outward by a certain pixel width to make the shape features of the target object more obvious. Then, the enhanced shape contour is re-superimposed on the target image according to the method in step 103 to obtain a new image to be detected, and the NCC matching process in step 104 is performed again to calculate the new matching degree.

[0036] 106. Repeat the steps of re-superimposing the shape contour on the target image according to the superposition enhancement algorithm and performing the NCC matching again until the matching degree is greater than or equal to the preset standard and then end.

[0037] In this embodiment, by continuously iteratively optimizing the superposition of the shape contour and the NCC matching process, the matching degree is continuously improved until a satisfactory matching effect is achieved, ensuring that the template can be accurately positioned in the target image, and high-precision matching can be achieved even in complex situations such as image blur, occlusion, or illumination change. Step 105 is executed cyclically, and each iteration further optimizes the superposition method of the shape contour according to the previous matching result, continuously adjusts the feature information of the target image, and performs the NCC matching again until the calculated matching degree is greater than or equal to the preset standard. At this time, it is considered that the best matching position of the template in the target image has been found, and the entire template matching process is completed.

[0038] The shape matching method based on NCC template matching provided by this application first preprocesses the target image to obtain a preprocessed image; then extracts the shape contour of the preprocessed image according to the edge detection algorithm and the edge enhancement algorithm; then superimposes the shape contour on the target image to obtain an image to be detected; further performs NCC matching on the image to be detected with a preset template to obtain a matching degree; if the matching degree is less than the preset standard, then according to the superimposition enhancement algorithm, the shape contour is superimposed on the target image again, and NCC matching is performed again; repeat the steps of superimposing the shape contour on the target image according to the superimposition enhancement algorithm and performing NCC matching again until the matching degree is greater than or equal to the preset standard and then end. This shape matching method extracts and superimposes the shape contour through the edge detection algorithm and the edge enhancement algorithm, which can highlight the key shape features of the target object, so that when performing NCC matching, even if the target object has a certain degree of blur or occlusion, it can more accurately find the area similar to the template. When the matching degree of the first NCC matching is less than the preset standard, the superimposition enhancement algorithm is introduced, and the steps of shape contour superimposition and re-matching are repeated until a satisfactory matching effect is achieved, greatly improving the success rate and accuracy of template matching, thereby enhancing the stability and reliability of the entire system in a complex environment, and reducing the misjudgment and missed judgment caused by matching failure.

[0039] Please refer to Figure 2 , an embodiment of the method for extracting the shape contour of the preprocessed image provided by this application includes: 201. Calculate the first-order derivative of the target image according to the Sobel operator to obtain the convolution result Dx in the x direction and the convolution result Dy in the y direction; In this embodiment, the Sobel operator is a discrete differential operator for edge detection, which detects edges by calculating the gradient of each pixel point in the image. The Sobel operator contains two convolution kernels, one for detecting edges in the horizontal direction (x direction) and the other for detecting edges in the vertical direction (y direction). According to the x-direction convolution kernel, traverse the entire image and perform convolution operations to obtain the x-direction convolution result D x ; similarly, according to the y-direction convolution kernel, traverse the entire image and perform convolution operations to obtain the y-direction convolution result D y .

[0040] Among them, the x-direction convolution kernel is ; the y-direction convolution kernel is .

[0041] 202. Combine the x-direction convolution result D x and the y-direction convolution result D y to obtain a combined result; In this embodiment, obtain the combination formula, and the combination formula is as follows: ; where I is the merged result, D x is the convolution result in the x direction, D y is the convolution result in the y direction. Then calculate the merged result according to the merging formula. In this way, a result image that combines the information in the x and y directions is obtained, where the value of each pixel reflects the gradient magnitude at that point, and areas with larger gradients usually correspond to the edges of the image.

[0042] 203. Normalize the merged result to a preset range to obtain a normalized result, and the preset range is set in advance according to the number of bits of the target image; In this embodiment, map the value of the merged result to a specific range for subsequent processing and comparison. For example, if the target image is an 8-bit grayscale image (the pixel value range is 0 - 255), the merged result can be normalized to the range of 0 - 255.

[0043] 204. According to a preset threshold, set to zero the part of the normalized result that is less than the preset threshold to obtain a zeroed result; In this embodiment, according to the specific application scenario, a threshold T is set in advance. This threshold can be determined through experiments or experience. For example, by observing the histogram of the image, select a value that can better separate the edge and non-edge regions as the threshold. For the I value in the normalized result image, if I ≤ T, then set the I value to 0, otherwise keep it unchanged. In this way, a zeroed result image is obtained, where the area with a value of 0 is considered a non-edge region, and other non-zero value regions may be edges or regions related to edges.

[0044] 205. Enhance the zeroed result according to an edge enhancement algorithm to obtain a shape contour.

[0045] In this embodiment, obtain an edge enhancement formula, and the edge enhancement formula is as follows: ; where (x, y) is the coordinate of the pixel to be enhanced in the zeroed result, G (x,y) is the enhancement result of the pixel to be enhanced (x, y), I (x,y) is the merged result corresponding to the pixel to be enhanced (x, y), S 1 is the first enhancement coefficient, O 1 is the first enhancement offset. Then calculate the enhancement result of each pixel to be enhanced in the zeroed result according to the edge enhancement formula, and multiple enhancement results form a shape contour.

[0046] Steps 201 to 205 optimize and improve edge detection and shape contour extraction in multiple ways. Their combined effect makes the finally obtained shape contour more accurate, clear, complete, and has good versatility and stability. Thus, it provides more reliable feature information for image processing tasks such as NCC template matching based on the shape contour, improving the effect and efficiency of the entire image processing process.

[0047] Referring to Figure 3 , in step 103, superimposing the shape contour onto the target image to obtain the image to be detected may specifically include, but is not limited to, the following: 301. When the mean value of the shape contour is greater than the background mean value of the target image, calculate according to the first superimposing formula to obtain the image to be detected. The first superimposing formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape contour; In this embodiment, first, it is necessary to calculate the mean value of the shape contour and the background mean value of the target image. When calculating the mean value of the shape contour, all pixel values in the shape contour image can be added together and then divided by the total number of pixels. For the background mean value of the target image, the background area in the target image (for example, the area far from the target object) can be selected, and the mean value of the pixel values in this area is calculated. If the mean value of the shape contour is greater than the background mean value of the target image, it means that the shape contour is relatively prominent compared to the background. At this time, addition superimposition is used. For each corresponding pixel position in the target image G1 and the shape contour G2, the pixel value of the image to be detected G at this position is calculated as follows: . In this way, the shape contour is superimposed onto the target image, making the shape contour of the target object more obvious in the target image, thus enhancing the features of the target object and helping subsequent operations such as template matching to more accurately identify the target. 302. When the mean value of the shape contour is less than the background mean value of the target image, calculate according to the second superimposing formula to obtain the image to be detected. The second superimposing formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape contour.

[0048] In this embodiment, when the mean value of the shape contour is less than the background mean value of the target image, it means that the shape contour is relatively dark or not obvious compared to the background. At this time, subtraction superimposition is used. The calculation process of the second superimposing formula: For each corresponding pixel position in the target image G1 and the shape contour G2, the pixel value of the image to be detected G at this position is calculated as follows: Through this subtraction operation, the difference between the shape contour and the background can be highlighted to a certain extent, making the shape contour relatively more prominent in the target image. Even if the shape contour is originally relatively dark or not obvious, its recognizability in the target image can be enhanced in this way, providing more favorable conditions for subsequent template matching and improving the accuracy and success rate of the matching.

[0049] These two steps adopt different superimposing methods according to the relationship between the mean value of the shape contour and the mean value of the background of the target image, all aiming to better integrate the shape contour information into the target image, enhance the features of the target object, adapt to different image situations, and thus improve the effect and adaptability of the entire image processing process.

[0050] Refer to Figure 4 , specifically, according to the superimposing enhancement algorithm in step 105, re-superimposing the shape contour on the target image may include, but is not limited to, the following: 401. When the mean value of the shape contour is greater than the mean value of the background of the target image, calculate according to the third superimposing formula to obtain the image to be detected. The third superimposing formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape contour, S 2 is the second enhancement coefficient, and O 2 is the second enhancement offset; 402. When the mean value of the shape contour is less than the mean value of the background of the target image, calculate according to the fourth superimposing formula to obtain the image to be detected. The fourth superimposing formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape contour, S 3 is the third enhancement coefficient, and O 3 is the third enhancement offset.

[0051] In this embodiment, similar to steps 301 to 302, according to the magnitudes of the mean of the shape contour and the background mean of the target image, superposition is performed in two cases. How to specifically judge the two cases will not be elaborated here. The prerequisite for executing step 105 is that the matching degree is less than the preset standard. At this time, it indicates that the superposition method in step 103 cannot meet the actual matching requirements, and superposition should be performed again. Different from the superposition in step 103, in steps 401 and 402, two sets of enhancement coefficients and enhancement offsets are introduced to enhance and adjust the superposition effect. By this method of determining the relationship between the mean of the shape contour and the background mean of the target image, using different superposition formulas, and introducing enhancement coefficients S2 and S3, and offsets O2 and O3, the superposition effect of the shape contour on the target image can be adjusted more flexibly to adapt to different image features and processing requirements, further highlighting the shape contour, providing more targeted and optimized image data for subsequent operations such as template matching, and improving the accuracy and effect of image processing. For example, when the shape contour is relatively brighter than the background, the third superposition formula can enhance the shape contour while adjusting the overall brightness and contrast as needed; when the shape contour is relatively darker than the background, the fourth superposition formula can better highlight the shape contour through subtraction and adjustment of the enhancement coefficients and offsets, making it more obvious and easy to identify in the target image.

[0052] The above embodiment illustrates the shape matching method based on NCC template matching provided by the present application. Next, the shape matching system, electronic device, and storage medium based on NCC template matching provided by the present application will be described: Please refer to Figure 5 , an embodiment of a shape matching system based on NCC template matching provided by the present application includes: A preprocessing unit 501, configured to preprocess the target image to obtain a preprocessed image; A shape contour unit 502, configured to extract the shape contour of the preprocessed image according to an edge detection algorithm and an edge enhancement algorithm; A to-be-detected image unit 503, configured to superpose the shape contour on the target image to obtain a to-be-detected image; A matching unit 504, configured to perform NCC matching on the to-be-detected image and a preset template to obtain a matching degree; A re-execution unit 505, configured to, if the matching degree is less than the preset standard, re-superpose the shape contour on the target image according to a superposition enhancement algorithm and re-perform NCC matching; A repetition unit 506, configured to repeatedly execute the steps of re-superposing the shape contour on the target image according to a superposition enhancement algorithm and re-performing NCC matching until the matching degree is greater than or equal to the preset standard and then end.

[0053] Optionally, the shape contour unit 502 is specifically configured to: Calculate the first-order derivative of the target image according to the Sobel operator to obtain the convolution result D in the x direction x and the convolution result D in the y direction y ; Merge the convolution result D in the x direction x and the convolution result D in the y direction y to obtain a merged result; Normalize the merged result to a preset range to obtain a normalized result, and the preset range is preset according to the number of bits of the target image; Set to zero the part of the normalized result that is less than the preset threshold according to the preset threshold to obtain a zeroed result; Enhance the zeroed result according to the edge enhancement algorithm to obtain a shape contour.

[0054] Optionally, the shape contour unit 502 is specifically configured to: Obtain a merging formula, and the merging formula is as follows: ; where I is the merged result, D x is the convolution result in the x direction, and D y is the convolution result in the y direction; Calculate the merged result according to the merging formula.

[0055] Optionally, the shape contour unit 502 is specifically configured to: Obtain an edge enhancement formula, and the edge enhancement formula is as follows: ; where (x, y) is the coordinate of the pixel point to be enhanced in the zeroed result, G (x,y) is the enhancement result of the pixel point (x, y) to be enhanced, I (x,y) is the merged result corresponding to the pixel point (x, y) to be enhanced, S 1 is the first enhancement coefficient, and O 1 is the first enhancement offset; Calculate the enhancement result of each pixel point to be enhanced in the zeroed result according to the edge enhancement formula, and multiple enhancement results form a shape contour.

[0056] Optionally, the image unit 503 to be detected is specifically configured to: When the mean value of the shape contour is greater than the background mean value of the target image, calculate according to the first superposition formula to obtain the image to be detected, and the first superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape contour; When the mean value of the shape contour is less than the background mean value of the target image, calculate according to the second superposition formula to obtain the image to be detected. The second superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape contour.

[0057] Optionally, the re - execution unit 505 is specifically used for: When the mean value of the shape contour is greater than the background mean value of the target image, calculate according to the third superposition formula to obtain the image to be detected. The third superposition formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape contour, S 2 is the second enhancement coefficient, and O 2 is the second enhancement offset; When the mean value of the shape contour is less than the background mean value of the target image, calculate according to the fourth superposition formula to obtain the image to be detected. The fourth superposition formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape contour, S 3 is the third enhancement coefficient, and O 3 is the third enhancement offset.

[0058] Optionally, the pre - processing includes at least one of the following: mean filtering noise reduction processing, median filtering noise reduction processing, and Gaussian filtering noise reduction processing.

[0059] Please refer to Figure 6 , this application provides an electronic device, including: A processor 601, a memory 602, an input / output unit 603, and a bus 604.

[0060] The processor 601 is connected to the memory 602, the input / output unit 603, and the bus 604.

[0061] The memory 602 stores a program, and the processor 601 calls the program to execute the shape matching method based on NCC template matching in any of the Figures 1 to 4 embodiments shown.

[0062] This application provides a computer - readable storage medium, on which a program is stored. When the program is executed on a computer, it executes the shape matching method based on NCC template matching in any of the Figures 1 to 4 embodiments shown.

[0063] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the above - described systems, devices, and units can refer to the corresponding processes in the foregoing method embodiments, and will not be elaborated herein.

[0064] In several embodiments provided in the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces, and the indirect couplings or communication connections of devices or units can be in electrical, mechanical, or other forms.

[0065] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0066] In addition, each functional unit in various embodiments of the present application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.

[0067] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present application. The foregoing storage medium includes: USB flash drives, mobile hard disks, read-only memories (ROM, read-only memory), random access memories (RAM, random access memory), magnetic disks, or optical disks and other various media that can store program codes.

Claims

1. A shape matching method based on NCC template matching, characterized in that: The shape matching method comprises: Preprocessing the target image to obtain a preprocessed image; Extracting the shape contour of the preprocessed image according to an edge detection algorithm and an edge enhancement algorithm; Superimposing the shape outline onto the target image to obtain an image to be detected; Performing NCC matching between the image to be detected and a preset template to obtain a matching degree; If the matching degree is less than a preset standard, the shape outline is re-superimposed on the target image according to the superposition enhancement algorithm, and NCC matching is performed again; Repeat the steps of re-superimposing the shape contour onto the target image according to the superposition enhancement algorithm and re-performing NCC matching until the matching degree is greater than or equal to the preset standard.

2. The shape matching method according to claim 1, characterized in that: Extracting the shape contour of the preprocessed image according to the edge detection algorithm and the edge enhancement algorithm comprises: Calculate the first-order derivative of the target image according to the Sobel operator to obtain the convolution result D in the x direction x And the convolution result D in the y direction y ; Merge the x-direction convolution results D x And the y-direction convolution result D y , get the merged result; Normalizing the merged result to a preset range to obtain a normalized result, wherein the preset range is pre-set according to the number of bits of the target image; According to a preset threshold, a portion of the normalized result that is smaller than the preset threshold is set to zero to obtain a zeroed result; The zeroing result is enhanced according to an edge enhancement algorithm to obtain a shape contour.

3. The shape matching method according to claim 2, characterized in that: The merging of the x-direction convolution results D x And the y-direction convolution result D y , the merged results include: Get the merging formula, which is as follows: ; Among them, I is the merged result, D x is the convolution result in the x direction, D y is the convolution result in the y direction; The merging result is calculated according to the merging formula.

4. The shape matching method according to claim 2, characterized in that: The step of enhancing the zeroing result according to the edge enhancement algorithm to obtain the shape contour comprises: Get the edge enhancement formula, which is as follows: ; Where (x, y) is the coordinate of the pixel to be enhanced in the zeroing result, G (x,y) is the enhancement result of the pixel (x, y) to be enhanced, I (x,y) is the merged result corresponding to the pixel point (x, y) to be enhanced, S1 is the first enhancement coefficient, and O1 is the first enhancement offset; The enhancement result of each pixel to be enhanced in the zeroing result is calculated according to the edge enhancement formula, and a plurality of the enhancement results constitute a shape contour.

5. The shape matching method according to claim 1, characterized in that: The step of superimposing the shape contour onto the target image to obtain the image to be detected comprises: When the mean value of the shape contour is greater than the background mean value of the target image, the image to be detected is obtained by calculation according to the first superposition formula, where the first superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape contour; When the mean value of the shape contour is less than the background mean value of the target image, the image to be detected is obtained by calculation according to the second superposition formula, and the second superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape contour.

6. The shape matching method according to claim 1, characterized in that: The step of re-superimposing the shape contour onto the target image according to the superposition enhancement algorithm comprises: When the mean value of the shape contour is greater than the background mean value of the target image, the image to be detected is obtained by calculation according to the third superposition formula, and the third superposition formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape contour, S2 is the second enhancement coefficient, and O2 is the second enhancement offset; When the mean value of the shape contour is less than the background mean value of the target image, the image to be detected is obtained by calculation according to the fourth superposition formula, and the fourth superposition formula is: , wherein G is the image to be detected, G1 is the target image, G2 is the shape contour, S3 is the third enhancement coefficient, and O3 is the third enhancement offset.

7. The shape matching method according to claim 1, characterized in that: The preprocessing includes at least one of the following: mean filter noise reduction processing, median filter noise reduction processing and Gaussian filter noise reduction processing.

8. A shape matching system based on NCC template matching, characterized in that: The shape matching system comprises: A preprocessing unit, used for preprocessing the target image to obtain a preprocessed image; A shape contour unit, used for extracting the shape contour of the preprocessed image according to an edge detection algorithm and an edge enhancement algorithm; An image to be detected unit, used for superimposing the shape outline onto the target image to obtain an image to be detected; A matching unit, used for performing NCC matching between the image to be detected and a preset template to obtain a matching degree; a re-execution unit, configured to re-superimpose the shape contour onto the target image and re-perform NCC matching according to a superposition enhancement algorithm if the matching degree is less than a preset standard; The repeating unit is used to repeatedly execute the steps of re-superimposing the shape contour onto the target image according to the superposition enhancement algorithm and re-performing NCC matching until the matching degree is greater than or equal to the preset standard.

9. An electronic device, characterized in that: The electronic device comprises: Processor, memory, input-output unit, and bus; The processor is connected to the memory, the input and output unit, and the bus; The memory stores a program, and the processor calls the program to execute the shape matching method based on NCC template matching according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program, and when the program is executed on a computer, the shape matching method based on NCC template matching according to any one of claims 1 to 7 is executed.

Citation Information

Patent Citations

  • Image template matching method and device based on domestic CPU and opencv

    CN116563582A

  • Image time identifier identification method based on template matching

    CN118397239A

  • Panoramic image determination method and apparatus, device, and storage medium

    WO2024139491A1