A Shape Feature Matching Method and Apparatus Based on Subpixel-Level Positioning
By employing preprocessing techniques such as Gaussian difference denoising and Canny edge detection, and subpixel-level contour extraction using the Zernike moment algorithm, combined with least squares fitting, the problem of insufficient positioning accuracy caused by noise interference in traditional methods is solved, achieving high-precision subpixel-level shape feature matching.
Patent Information
- Application Number
- CN202611611784.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-19
- Publication Date
- 2026-11-17
AI Technical Summary
In high-precision positioning scenarios such as semiconductor packaging, PCB alignment, and LCD panel inspection, existing technologies are prone to noise interference, making it impossible to achieve sub-pixel-level positioning, resulting in insufficient positioning accuracy and a high mismatch rate.
Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation and small area noise filtering are used, combined with Zernike moment algorithm and least squares method to perform sub-pixel level contour extraction and fitting, calculate the similarity between Zernike moment and Hu moment, and generate matching confidence.
It improves the accuracy and efficiency of image shape feature matching, ensures the accuracy and stability of sub-pixel level positioning, and reduces the false matching rate.
Smart Images

Figure CN123118630A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, specifically to a shape feature matching method and apparatus based on sub-pixel level positioning. Background Technology
[0002] In automated manufacturing scenarios with extremely high positioning accuracy requirements, such as semiconductor packaging, PCB alignment, and LCD panel inspection, Mark points (reference points) serve as visual positioning reference marks. Their detection accuracy, stability, and anti-interference capabilities directly determine the alignment accuracy and production yield of the entire equipment.
[0003] Traditional shape matching methods based on contours and Hu invariant moments typically use the Canny operator to extract pixel-level contours and then calculate shape similarity using Hu moments. However, such methods have significant drawbacks in practical industrial applications: First, without noise filtering and contour optimization, common interferences in the field, such as low contrast, image noise, and blurred edges, can easily lead to broken or redundant contour extraction, causing matching failures or large positioning errors. Second, traditional contour matching remains at the pixel-level accuracy, which cannot meet the sub-pixel-level positioning requirements of high-end manufacturing scenarios. Third, relying solely on Hu moments results in low similarity, a high mismatch rate, and sensitivity to local contour deformation. Finally, existing methods lack sub-pixel-level fitting optimization for contour edges, making it difficult to accurately extract the sub-pixel coordinates of the center point of the Mark shape.
[0004] In summary, there is an urgent need for a shape feature matching method based on sub-pixel level localization, which can improve the accuracy and efficiency of image shape feature matching. Summary of the Invention
[0005] To address the problems in the prior art, this application provides a shape feature matching method and apparatus based on sub-pixel level positioning, which can improve the accuracy and efficiency of image shape feature matching.
[0006] To solve at least one of the above problems, this application provides the following technical solution: Firstly, this application provides a shape feature matching method based on sub-pixel level positioning, including: The image to be detected is acquired, and image preprocessing operations are performed on the image to be detected to determine the corresponding initial pixel-level contour. The image preprocessing operations include sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation contour simplification, and small area noise contour filtering. The initial pixel-level contour is normalized in coordinates. According to the set Zernike moment algorithm, the initial pixel-level contour after coordinate normalization is extracted at the sub-pixel level to determine the corresponding Zernike moment feature vector. The Zernike moment feature vector contains the geometric shape features of the contour. Based on the Zernike moment feature vector, the least squares method is used to perform sub-pixel level fitting on the contour edge and solve the fitting coefficient to determine the corresponding sub-pixel level contour coordinates. Calculate the Zernike moment similarity and weighted Hu moment similarity between the subpixel contour coordinates and the subpixel contour of the preset template image. Perform weighted fusion on the Zernike moment similarity and the weighted Hu moment similarity to determine the corresponding shape feature similarity. Convert the shape feature similarity into a matching confidence score. Based on the subpixel contour coordinates with the highest matching confidence score, determine the corresponding detection image center point coordinates to complete image shape feature matching.
[0007] Furthermore, the Gaussian difference denoising and the Canny edge detection include: The Gaussian difference denoising method includes: performing convolution operations on the image to be detected using two Gaussian kernel functions of different scales, subtracting the convolution results output by the two Gaussian kernel functions of different scales, in order to extract high-frequency edge information in the image and determine the corresponding denoised image; The Canny edge detection includes: calculating the gradient magnitude and gradient direction of each pixel in the denoised image, determining the corresponding gradient image, removing non-edge pixels of the gradient image according to a preset non-maximum suppression algorithm, determining the corresponding gradient edge, performing double thresholding hysteresis thresholding on the gradient edge to complete edge connection, and determining the corresponding binary edge image.
[0008] Furthermore, the morphological closing operation contour repair, the polygon approximation contour simplification, and the small-area noise contour filtering include: The morphological closing operation contour repair includes: performing dilation and erosion operations sequentially on the binary edge image to determine the corresponding edge contour closing region, wherein the kernel size of the dilation operation is 2×2 pixels and the kernel size of the erosion operation is 2×2 pixels, which are used to fill the edge break gaps and connect adjacent edge segments through the closing operation. The polygon approximation contour simplification includes: performing polygon fitting on the closed region of the edge contour according to a preset Douglas-Peucker algorithm, removing redundant contour vertices of the closed region of the edge contour based on a preset approximation accuracy threshold, and determining the corresponding simplified contour point set. The small-area noise contour filtering includes: calculating the area of each simplified contour for the simplified contour point set, identifying contours with an area smaller than a preset threshold as noise contours and removing them, and determining the corresponding initial pixel-level contours.
[0009] Further, the step of extracting sub-pixel-level contours from the initial pixel-level contours after coordinate normalization according to the set Zernike moment algorithm, and determining the corresponding Zernike moment feature vectors, includes: Using an 8th-order Zernike orthogonal polynomial as the basis function, the initial pixel-level contour after coordinate normalization is orthogonally decomposed, and the Zernike moment values corresponding to each order are calculated respectively. All calculated Zernike moment values are combined in order of order to determine the corresponding Zernike moment feature vector, which is used to characterize the geometric features of the contour.
[0010] Further, the step of performing sub-pixel-level fitting of the contour edge using the least squares method based on the Zernike moment feature vector, and solving for the fitting coefficients to determine the corresponding sub-pixel-level contour coordinates includes: Obtain all contour points on the initial pixel-level contour described by the Zernike moment feature vector, and extract the contour parameters of each contour point as data points to be fitted. Construct a quadratic polynomial fitting model to characterize the curve shape of the contour edge; Construct a least squares optimization objective function, which aims to minimize the sum of squares of the differences between the measured values of the ordinates of all data points to be fitted and the predicted values of the quadratic polynomial fitting model. Solve the least squares optimization objective function to determine the corresponding subpixel-level contour fitting curve, and calculate the subpixel-level contour coordinates of any point on the contour based on the fitting curve.
[0011] Further, the calculation of the Zernike moment similarity and weighted Hu moment similarity between the subpixel-level contour coordinates and the subpixel contours of the preset template image includes: Extract the Zernike moment feature vector of the subpixel contour coordinates as the first set of feature vectors. At the same time, extract the Zernike moment feature vector of the subpixel contour of the preset template image as the second set of feature vectors. Perform a normalized dot product operation on the first set of feature vectors and the second set of feature vectors to determine the corresponding Zernike moment similarity. Extract the 7th order Hu moment feature vector of the subpixel contour coordinates, and simultaneously extract the 7th order Hu moment feature vector of the subpixel contour of the preset template image. For each order Hu moment feature vector, calculate the difference ratio between the subpixel contour coordinates and the subpixel contour of the template image, and then sum the difference ratios according to preset weight coefficients to determine the corresponding weighted Hu moment similarity.
[0012] Further, the step of weightedly fusing the Zernike moment similarity and the weighted Hu moment similarity to determine the corresponding shape feature similarity, converting the shape feature similarity into a matching confidence score, and determining the corresponding detection image center point coordinates based on the sub-pixel level contour coordinates with the highest matching confidence score includes: The Zernike moment similarity and the weighted Hu moment similarity are weighted and fused according to the preset fusion weight coefficient to determine the corresponding shape feature similarity. The fusion weight coefficient is used to balance the ability of Zernike moments to describe subtle contour features with the advantage of weighted Hu moments in representing the geometric invariance of contours. The shape feature similarity is transformed to a preset confidence interval through a nonlinear mapping function to determine the corresponding matching confidence. Based on the coordinates of the sub-pixel contour with the highest matching confidence among multiple candidate sub-pixel contours, the coordinates of the corresponding detection image center point are determined.
[0013] Secondly, this application provides a shape feature matching device based on sub-pixel level positioning, comprising: The image preprocessing module is used to acquire the image to be detected, perform image preprocessing operations on the image to be detected, and determine the corresponding initial pixel-level contour. The image preprocessing operations include sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation contour simplification, and small area noise contour filtering. The sub-pixel contour extraction module is used to normalize the coordinates of the initial pixel-level contour, extract the sub-pixel contour of the initial pixel-level contour after coordinate normalization according to the set Zernike moment algorithm, determine the corresponding Zernike moment feature vector, the Zernike moment feature vector contains the contour geometric shape features, and based on the Zernike moment feature vector, the least squares method is used to perform sub-pixel level fitting on the contour edge, and the fitting coefficient is solved to determine the corresponding sub-pixel level contour coordinates. The subpixel similarity calculation module is used to calculate the Zernike moment similarity and weighted Hu moment similarity between the subpixel-level contour coordinates and the subpixel contours of the preset template image, perform weighted fusion on the Zernike moment similarity and the weighted Hu moment similarity to determine the corresponding shape feature similarity, convert the shape feature similarity into a matching confidence score, and determine the corresponding detection image center point coordinates based on the subpixel-level contour coordinates with the highest matching confidence score to complete the image shape feature matching.
[0014] Thirdly, this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the shape feature matching method based on sub-pixel level positioning.
[0015] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the shape feature matching method based on sub-pixel level positioning.
[0016] Fifthly, this application provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the shape feature matching method based on sub-pixel level positioning.
[0017] As can be seen from the above technical solution, this application provides a shape feature matching method and apparatus based on sub-pixel level localization. The method involves sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation, and small-area noise filtering on the image to be detected to obtain an initial pixel-level contour. Sub-pixel level extraction is then performed on the initial contour based on the Zernike moment algorithm, and the contour edges are fitted at the sub-pixel level using the least squares method to generate sub-pixel level contour coordinates. The Hu moment similarity and Zernike moment similarity between the sub-pixel contour and the template sub-pixel contour are calculated, and the weighted average is mapped to the matching confidence score. Finally, the center point of the corresponding detection rectangle is determined based on the candidate sub-pixel level contour coordinates with the highest matching confidence score. This improves the accuracy and efficiency of image shape feature matching. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1This is a flowchart illustrating the shape feature matching method based on sub-pixel level positioning in an embodiment of this application. Figure 2 This is a structural diagram of the shape feature matching device based on sub-pixel level positioning in the embodiments of this application. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0021] The acquisition, storage, use, and processing of data in this application comply with relevant laws and regulations.
[0022] In semiconductor packaging and LCD panel inspection fields where high image positioning accuracy is required, image mark point positioning based on contours and Hu invariant moments faces problems such as noise interference, insufficient accuracy, and low precision. This application provides a shape feature matching method and apparatus based on sub-pixel level positioning. The method involves sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation, and small-area noise filtering on the image to be detected to obtain an initial pixel-level contour. Sub-pixel level extraction is then performed on the initial contour using the Zernike moment algorithm, and the contour edges are fitted at the sub-pixel level using the least squares method to generate sub-pixel level contour coordinates. The Hu moment similarity and Zernike moment similarity between the sub-pixel contour and the template sub-pixel contour are calculated, and the weighted sum is mapped to a matching confidence score. Finally, the center point of the corresponding detection rectangle is determined based on the candidate sub-pixel level contour coordinates with the highest matching confidence score. This improves the accuracy and efficiency of image shape feature matching.
[0023] To improve the accuracy and efficiency of image shape feature matching, this application provides an embodiment of a shape feature matching method based on sub-pixel level positioning, see [link to embodiment]. Figure 1 The shape feature matching method based on sub-pixel level positioning specifically includes the following: Step S101: Obtain the image to be detected, perform image preprocessing operations on the image to be detected, and determine the corresponding initial pixel-level contour. The image preprocessing operations include sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation contour simplification, and small area noise contour filtering. Optionally, in this embodiment, after acquiring the original image to be detected, Gaussian difference denoising is first performed. Two Gaussian kernels of different scales are used to convolve the image respectively, and then the two convolution results are subtracted, thereby highlighting the edge regions with drastic gray-level changes in the image, while effectively suppressing random noise and low-frequency uneven illumination interference, providing a high signal-to-noise ratio image basis for subsequent edge detection.
[0024] Next, Canny edge detection is performed. The gradient magnitude and direction of each pixel in the image are calculated. The non-maximum suppression algorithm is used to retain the pixels with the largest local gradients and remove non-edge responses. Then, double threshold hysteresis processing is used to complete edge connection and output a binarized initial edge image.
[0025] Since edge detection results may contain breaks or holes, morphological closure operations are required for contour restoration. This operation first dilates the binary edge image to fill edge gaps and connect adjacent broken segments, and then performs an erosion operation to restore the over-expanded areas to reasonable boundaries, thereby forming a continuous, closed, and complete contour region.
[0026] After obtaining the closed contour, polygon approximation is used to simplify the contour. Using a fixed proportion of the contour perimeter as the approximation accuracy threshold, redundant intermediate vertices are removed while preserving the overall geometry of the contour, and a simplified contour composed of several key vertices is output, which greatly reduces the amount of data for subsequent processing.
[0027] Finally, small-area noise contour filtering is performed. The system calculates the pixel area enclosed by each simplified contour, identifies contours with an area smaller than a preset threshold as interference noise and removes them, retains only the target contours with the required area, and finally outputs clear, complete and simplified initial pixel-level contours.
[0028] This step enables the stable extraction of high-quality target contours from industrial site images that are subject to noise interference, blurred edges, and unsatisfactory contrast, providing a reliable data foundation for subsequent sub-pixel-level precise positioning.
[0029] Step S102: Normalize the coordinates of the initial pixel-level contour, extract the sub-pixel-level contour of the initial pixel-level contour after coordinate normalization according to the set Zernike moment algorithm, determine the corresponding Zernike moment feature vector, the Zernike moment feature vector contains the contour geometric shape features, and based on the Zernike moment feature vector, perform sub-pixel-level fitting on the contour edge using the least squares method, solve the fitting coefficient, and determine the corresponding sub-pixel-level contour coordinates. Optionally, in this embodiment, after the initial pixel-level contour is extracted, the initial pixel-level contour is first subjected to coordinate normalization processing.
[0030] The core purpose of coordinate normalization is to transform contour points from the original image pixel coordinate system to a standardized scale space. This typically involves mapping the coordinates of all contour points to the unit circle, ensuring that the radial distance is less than or equal to 1. This satisfies the input data requirements of the Zernike moment algorithm. In practice, the geometric center of the contour point set in the original image coordinate system is first calculated. Then, using this center as a reference point, the coordinates of each contour point are translated to a coordinate system centered at the origin. Finally, the coordinates are scaled according to the overall size of the contour, ensuring that the distance from the farthest contour point to the center is exactly 1. This normalization process ensures the mathematical rigor of subsequent Zernike moment calculations and the accuracy of feature representation.
[0031] Optionally, in this embodiment, after coordinate normalization, sub-pixel level contour extraction is performed on the normalized contour according to the set Zernike moment algorithm. This embodiment sets the 8th order Zernike moment to be used. The choice of this order fully takes into account the fineness of contour feature description and computational efficiency. The 8th order moment can effectively capture high-frequency detail information of the contour, while avoiding computational redundancy caused by excessively high order moments.
[0032] Zernike moments map a normalized contour onto a set of orthogonal basis functions for projection decomposition. Each Zernike moment component corresponds to the contour's morphological features at different radial and angular frequencies. By calculating Zernike moments of various orders, a Zernike moment feature vector can be constructed. This feature vector mathematically and comprehensively characterizes the contour's geometric shape, including its overall shape, concavity / convexity, symmetry, and edge curvature variations. Compared to traditional pixel-level contour description methods, Zernike moment feature vectors possess rotation invariance, scale invariance, and robustness to slight noise, enabling stable representation of the contour's essential geometric features at the sub-pixel level.
[0033] Optionally, in this embodiment, based on the calculated Zernike moment eigenvectors, the least squares method is then used to perform sub-pixel-level fitting of the contour edges. The basic idea of the least squares method is to find an optimal fitting curve that minimizes the sum of the squared distances from all contour points to the curve.
[0034] This embodiment chooses a quadratic polynomial as the functional form of the fitted curve because a quadratic curve has sufficient degrees of freedom to approximate the contour shape of most industrial mark points, while avoiding the overfitting problem that may be caused by higher-order polynomials. During the fitting process, the sub-pixel coordinates of the contour points are used as input data to establish a system of equations with the fitting coefficients as unknowns. Solving this system of equations yields the optimal fitting coefficients. This solution process requires constructing three linear equations about a, b, and c, resembling an equation relating the sum of the powers of the coordinates to the sum of the products of the coordinates. Then, a unique solution for the fitting coefficients is obtained using mathematical methods such as Cramer's rule or matrix inversion.
[0035] Substituting the obtained fitting coefficients into the quadratic polynomial generates a continuous sub-pixel contour curve. This curve is no longer limited by the discretization of the original pixel grid, and coordinate values can be output at any position on the curve with coordinate precision retained to one decimal place. Compared to the initial pixel-level contour, the sub-pixel-level contour completely eliminates the jagged effect, and the contour edges become smooth and continuous, effectively correcting the step-like distortion originally caused by pixel discretization. The final determined sub-pixel-level contour coordinates include both the integer part of the contour and the decimal part accurate to one decimal place, truly achieving sub-pixel-level positioning accuracy and providing a high-quality contour data foundation for subsequent similarity calculations and Mark center point determination.
[0036] Step S103: Calculate the Zernike moment similarity and weighted Hu moment similarity between the subpixel contour coordinates and the subpixel contour of the preset template image. Perform weighted fusion on the Zernike moment similarity and the weighted Hu moment similarity to determine the corresponding shape feature similarity. Convert the shape feature similarity into a matching confidence score. Based on the subpixel contour coordinates with the highest matching confidence score, determine the corresponding detection image center point coordinates to complete the image shape feature matching.
[0037] Optionally, in this embodiment, after extracting subpixel-level contour coordinates, the shape feature matching stage begins. First, the subpixel-level contour coordinates extracted from the current image to be detected are compared with the subpixel contours of a pre-stored template image. Two complementary shape feature similarities are calculated in parallel: one is Zernike moment similarity, and the other is weighted Hu moment similarity.
[0038] Zernike moment similarity is based on the integral properties of orthogonal polynomials within the unit circle. It can accurately describe the global geometry of a contour and has good rotation invariance and noise resistance. The system calculates the Zernike moment feature vectors of the contour to be detected and the template contour respectively, and measures the similarity between the two by normalized cross-correlation, obtaining a similarity score between 0 and 1.
[0039] Simultaneously, weighted Hu moment similarity is calculated. Hu moments are constructed based on the normalized central moments of the contour and possess translation, rotation, and scale invariance. The system extracts seven Hu moment components from the contour to be detected and the template contour, and assigns differentiated weights to each order of moments based on the geometric priors of different industrial mark points, highlighting the key distinguishing features of the contour. After weighted fusion, another similarity score is obtained.
[0040] Subsequently, the two similarities are weighted and fused. Zernike moment similarity is given a higher weight to fully leverage its sub-pixel-level contour description advantage; weighted Hu moment similarity serves as an auxiliary discriminant, enhancing the constraint on the overall geometric structure of the contour. Through linear weighted combination, a comprehensive shape feature similarity index is generated. This comprehensive similarity is then mapped to a matching confidence score, also ranging from 0 to 1. The closer the confidence score is to 1, the more consistent the current contour to be detected is with the template contour in terms of shape features.
[0041] The above calculation process is repeated for all candidate contours, and the sub-pixel level contour coordinates with the highest matching confidence are selected as the final matching result. Based on the optimal contour coordinates, the system further solves for its geometric center, and the output is the center point coordinates of the detected image.
[0042] This example demonstrates how, based on pixel-level shape extraction, this embodiment employs the Zernike moment subpixel contour extraction algorithm and least squares edge fitting to achieve subpixel-level contour localization, and combines weighted Hu moment matching to achieve subpixel-level shape feature matching.
[0043] As described above, the shape feature matching method based on sub-pixel level localization provided in this application can obtain an initial pixel-level contour by sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation, and small area noise filtering on the image to be detected; extract the initial contour at the sub-pixel level based on the Zernike moment algorithm, and perform sub-pixel level fitting on the contour edges using the least squares method to generate sub-pixel level contour coordinates; calculate the Hu moment similarity and Zernike moment similarity between the sub-pixel contour and the template sub-pixel contour, and weight them to map to the matching confidence; finally, determine the center point of the corresponding detection rectangle based on the candidate sub-pixel level contour coordinates with the highest matching confidence, thereby improving the accuracy and efficiency of image shape feature matching.
[0044] In one embodiment of the shape feature matching method based on sub-pixel level positioning in this application, it may further include the following: Step S201: The Gaussian difference denoising includes: performing convolution operations on the image to be detected using two Gaussian kernel functions of different scales, subtracting the convolution results output by the two Gaussian kernel functions of different scales, in order to extract high-frequency edge information in the image and determine the corresponding denoised image; Step S202: The Canny edge detection includes: for the denoised image, calculating the gradient magnitude and gradient direction of each pixel in the image, determining the corresponding gradient image, removing non-edge pixels of the gradient image according to a preset non-maximum suppression algorithm, determining the corresponding gradient edge, performing double threshold hysteresis thresholding on the gradient edge to complete edge connection, and determining the corresponding binary edge image.
[0045] Optionally, in this embodiment, Gaussian difference denoising is used.
[0046] First, the original image to be detected is received, and then convolved with two Gaussian kernel functions of different scales, either in parallel or sequentially. The Gaussian kernel function is a smoothing filter whose "scale" is determined by the standard deviation parameter. The first, smaller-scale Gaussian kernel can suppress random noise in the image to some extent, while preserving subtle edge details; the second, larger-scale Gaussian kernel produces a stronger smoothing effect, significantly filtering out noise, but it may also blur or even erase some real edge information.
[0047] After performing two independent convolutions, the system subtracts the two convolution results pixel by pixel. The core principle of this subtraction is that similar low-frequency components in the two images (such as large-scale uniform lighting or slowly changing backgrounds) will cancel each other out; while high-frequency information representing geometric abrupt changes such as Mark point edges and corners will be effectively extracted and enhanced because they are lost to different degrees in the two smoothing processes. The final output "denoised image" is actually a difference image that eliminates uneven lighting and random noise interference and only highlights the edge features of objects.
[0048] Optionally, in this embodiment, Canny edge detection receives the denoised image generated in the previous step and begins to perform multi-stage processing to extract accurate pixel-level contours.
[0049] First, the gradient magnitude and gradient direction of each pixel in the denoised image are calculated using operators such as Sobel, generating a "gradient image". The gradient magnitude represents the degree of gray-level change at that point (i.e., edge intensity), while the gradient direction points in the direction of the fastest gray-level change.
[0050] Subsequently, a non-maximum suppression algorithm is applied to traverse each pixel in the gradient image and compare its gradient magnitude with the gradient magnitudes of its two adjacent pixels along the gradient direction. If the magnitude of the current pixel is not a local maximum in that direction, it is set to zero (determined to be non-edge). This process refines the edges, shrinking the originally coarse "wide edges" into precise "edge lines" of single-pixel width, thus obtaining a clear "gradient edge" image.
[0051] Finally, a "dual-threshold hysteresis thresholding" process is performed. A high threshold and a low threshold are preset (the low threshold is typically half the high threshold). Any pixel with a gradient magnitude higher than the high threshold is immediately marked as a strong edge; pixels with a gradient magnitude lower than the low threshold are discarded; pixels in between are marked as weak edges. The system then examines weak edge pixels: if they are adjacent to a strong edge pixel, the weak edge is connected and preserved; if they are isolated without adjacent strong edges, they are determined to be noise or false edges and removed.
[0052] Through step S202, this embodiment effectively suppresses noise response while ensuring the continuity of real edges, and finally outputs a complete, single-pixel connected "binary edge image" as the basis for subsequent contour processing.
[0053] In one embodiment of the shape feature matching method based on sub-pixel level positioning in this application, it may further include the following: Step S301: The morphological closing operation contour repair includes: performing dilation and erosion operations sequentially on the binary edge image to determine the corresponding edge contour closing region, wherein the kernel size of the dilation operation is 2×2 pixels and the kernel size of the erosion operation is 2×2 pixels, which are used to fill the edge break gaps and connect adjacent edge segments through the closing operation. Step S302: The polygon approximation contour simplification includes: performing polygon fitting on the closed region of the edge contour according to the preset Douglas-Peucker algorithm, removing redundant contour vertices of the closed region of the edge contour based on the preset approximation accuracy threshold, and determining the corresponding simplified contour point set. Step S303: The small-area noise contour filtering includes: calculating the area of each simplified contour for the simplified contour point set, identifying contours with an area smaller than a preset threshold as noise contours and removing them, and determining the corresponding initial pixel-level contours.
[0054] Optionally, in this embodiment, the binary edge image generated after Canny edge detection is applied.
[0055] During edge detection, due to factors such as uneven lighting, complex target surface texture, or low contrast, the detected edge lines often exhibit discontinuous break regions, and even a lack of connection between adjacent edge segments. Morphological closing operations are designed to solve this problem.
[0056] Closing is a combination of dilation and erosion operations. The dilation operation uses a 2×2 pixel kernel as its structuring element, sliding across the binary image to fill in edge pixels within the kernel's coverage area, thus expanding the edge lines outwards, filling gaps, and connecting closely spaced but unconnected edge segments. The subsequent erosion operation uses the same 2×2 kernel to shrink the over-expanded edge regions inwards, restoring the original edge thickness while maintaining the overall connected structure. This provides a complete target boundary for subsequent contour simplification, avoiding misjudgment or feature extraction failure due to edge breaks.
[0057] Optionally, in this embodiment, after the closing operation repair, the boundary of the contour closure region is composed of a large number of dense pixels, including many collinear or redundant vertices. These redundant points do not increase the geometric information of the contour, but instead increase the time cost of subsequent matching calculations and may introduce unnecessary noise. The purpose of polygon approximation is to represent the contour with as few vertices as possible while maintaining the basic shape of the contour.
[0058] The Douglas-Peucker algorithm is used to approximate polygons. The core logic of the algorithm is as follows: A straight line is drawn between the starting and ending points of the contour. The perpendicular distance from all intermediate points to this line is calculated, and the maximum distance is found. If this distance is less than a preset approximation accuracy threshold, all intermediate points between the two endpoints of the line are discarded, and the line segment becomes the approximation of that contour segment. If there are points with distances greater than the threshold, the contour is divided into two segments using this point as the dividing point, and the above process is recursively executed for each segment. The approximation accuracy threshold is set to 0.01 times the contour perimeter, allowing the approximation degree to adaptively adjust according to the actual size of the contour.
[0059] This step significantly reduces the number of contour vertices while ensuring the geometric fidelity of the contour, eliminating redundant points that are collinear or nearly collinear. The simplified contour point set output retains key information about the target's geometric features and reduces the amount of data required for subsequent sub-pixel contour extraction and similarity calculation, thereby improving the algorithm's efficiency.
[0060] Optionally, in this embodiment, after polygon approximation simplification, some small contour regions may still exist in the image. These regions are not the contours of the target Mark points, but rather pseudo-contours generated by image noise, minor impurities, or edge responses of non-target structures. If not filtered, these noisy contours will interfere with the subsequent matching process and may even lead to mismatches.
[0061] This step calculates the area of the region enclosed by each simplified contour point set. The contour area is calculated based on the polygon area formula, obtained by summing the cross-coordinates of the contour vertices and taking half the absolute value of the difference. After calculation, the area of each contour is compared with a preset threshold, which is set to 5 pixels. When the contour area is less than 5 pixels, it is determined to be a noise contour and is directly discarded; only when the contour area is greater than or equal to 5 pixels is it retained as a valid initial pixel-level contour for subsequent sub-pixel-level extraction. Through area threshold quantization screening, the interference of small noise contours on subsequent matching is effectively eliminated, retaining only candidate contours with sufficient geometric dimensions.
[0062] Through step S303, this embodiment successfully eliminates contour noise interference by morphological closing operation contour repair, polygon approximation contour simplification, and small-area noise contour filtering, resulting in a clean initial pixel-level contour and reducing the mismatch rate.
[0063] In one embodiment of the shape feature matching method based on sub-pixel level positioning in this application, it may further include the following: Step S401: Using an 8th-order Zernike orthogonal polynomial as the basis function, orthogonally decompose the initial pixel-level contour after coordinate normalization, and calculate the Zernike moment value corresponding to each order respectively. Step S402: Combine all the calculated Zernike moment values in order of order to determine the corresponding Zernike moment feature vector, which is used to characterize the geometric features of the contour.
[0064] Optionally, in this embodiment, a Zernike moment subpixel contour extraction algorithm is used. Leveraging the orthogonality of Zernike moments, the subpixel-level coordinates of the contour are accurately extracted. This lays the foundation for subsequent noise reduction through least-squares fitting.
[0065] Specifically, the principle of Zernike moment subpixel contour extraction is as follows: Zernike moments are a set of orthogonal polynomial moments within a unit circle, possessing rotation invariance, scale invariance, and noise resistance. Their core advantage is their ability to accurately describe the subtle features of a contour, unaffected by contour rotation, scale changes, or minor noise. They can fit subpixel-level contour coordinates onto pixel-level contours. The definition of Zernike moments is based on a polar coordinate system, which better matches the geometric features of the contour, facilitating subpixel-level fitting.
[0066] Based on the principle of Zernike moments, we normalize the original coordinates and map them into the unit circle to satisfy the domain requirement of the Zernike polynomial.
[0067] The mathematical formula for Zernike moments is as follows: Let the polar coordinates of the image contour region be represented as ,in, (Unit circle normalization) Then the nth order m degree Zernike polynomial Defined as:
[0068] Where, n: the order of the Zernike moment (in this embodiment, n=8 is selected to balance accuracy and computational efficiency). m: the degree of the Zernike moment, satisfying ,and It is a non-negative even number; : Radial polynomial, its expression is:
[0069] : Angular polynomial, where j is the imaginary unit.
[0070] Based on the above Zernike moment polynomial The nth-order m-th Zernike moments of the image contour Defined as:
[0071] in, for The conjugate of complex numbers, This is a function of the grayscale values of the image contour region. Let be the area element of the double integral.
[0072] Understandably, Zernike polynomials consist of radial and angular polynomials, possessing orthogonality and completeness, enabling redundancy-free and leak-free eigenvalue decomposition of any two-dimensional function within the unit circle. In actual computation, the system traverses the polar coordinates of each pixel within the contour region, calculating each set of Zernike moments from order 0 to 8 that satisfy the parity constraints of order and degree. Each set of moments corresponds to a specific geometric pattern; lower-order moments describe the overall shape features of the contour, while higher-order moments characterize the detailed variations and edge textures. Through orthogonal decomposition, the geometric information of the contour is mapped to a feature space spanned by a set of orthogonal basis functions, with moments of different orders being independent and uncorrelated.
[0073] After calculating the Zernike moments of each order, these moments are arranged in ascending order, and within the same order, in ascending order of degree, forming a one-dimensional eigenvector. Each component of this eigenvector corresponds to a specific Zernike moment, preserving the geometric response information of the profile at different radial and angular frequencies. Because the Zernike polynomial itself is rotationally invariant, this eigenvector undergoes only a phase change when the profile rotates, while the magnitude remains unchanged, thus achieving a rotationally invariant profile description.
[0074] For example, calculate multiple Zernike moments of different orders and form an eigenvector, as shown in Table 1 below: Table 1: Calculation results of eigenvectors of Zernike moments of different orders
[0075] This vector [125.6, -8.3+15.2j, -42.3, 88.1, ...] is the Zernike moment eigenvector, which mathematically describes the edge features of this small region.
[0076] Through step S402, this embodiment successfully compresses the originally complex and high-dimensional set of contour pixels into a set of low-dimensional, compact numerical feature vectors with clear physical meaning. Compared with using the original pixel coordinates directly for matching, the Zernike moment feature vector significantly reduces the data dimension and enhances the ability to resist deformation interference, providing reliable feature input for calculating the weighted Hu moment similarity, matching confidence and solving the Mark center point coordinates in subsequent steps.
[0077] In one embodiment of the shape feature matching method based on sub-pixel level positioning in this application, it may further include the following: Step S501: Obtain all contour points on the initial pixel-level contour described by the Zernike moment feature vector, and extract the contour parameters of each contour point as the data points to be fitted. Step S502: Construct a quadratic polynomial fitting model to characterize the curve shape of the contour edge; Step S503: Construct a least squares optimization objective function, wherein the least squares optimization objective function aims to minimize the sum of squares of the differences between the measured values of the ordinates of all data points to be fitted and the predicted values of the quadratic polynomial fitting model. Step S504: Solve the least squares optimization objective function, determine the corresponding sub-pixel level contour fitting curve, and calculate the sub-pixel level contour coordinates of any point on the contour based on the fitting curve.
[0078] Optionally, in this embodiment, after obtaining the feature parameters of the contour through Zernike moments in this step, the least squares method is used to perform sub-pixel-level fitting on the contour edge to eliminate the influence of noise on contour positioning and improve sub-pixel positioning accuracy.
[0079] Specifically, the contour parameters of the initial pixel-level contour after Zernike moment feature extraction are obtained, and the Zernike moment features and pixel-level integer coordinates on the contour are traversed as parameters of the data points to be fitted.
[0080] Meanwhile, we have an ideal step edge model (a straight edge that passes through a pixel region), which has the following edge parameters: : The vertical distance from the center of the window to the edge (0 ≤ l ≤ 1, normalized to the unit circle); : The normal angle of the edge (the perpendicular direction of the edge tangent).
[0081] The edge parameters are solved by solving a system of simultaneous equations based on Zernike moment characteristics and an ideal step edge model. , The distance and normal parameters obtained from the solution are appended to each pixel-level integer coordinate we extracted to obtain the sub-pixel edge point coordinates. .
[0082] For example, suppose the pixel-level integer coordinates are (0,0), and the offset distance along the normal direction is... =0.35, normal angle =0, then the subpixel edge coordinates are (0.35, 0).
[0083] Establish a quadratic polynomial function model (quadratic polynomial fitting, adaptable to most industrial Mark point contour features), and set the sub-pixel coordinates of the contour edge as follows: ( (where N is the number of contour points), the fitted contour edge curve equation is:
[0084] Construct a least-squares optimization objective function. The goal of the least-squares method is to minimize the sum of squared fitting errors, i.e.:
[0085] The essence of this function is to measure the degree of deviation between the fitted curve and the actual contour points: for each data point to be fitted, the system calculates the difference between its true ordinate and the ordinate predicted by the quadratic polynomial model at that point's abscissa, squares this difference, and sums it over all contour points. The purpose of squaring is to eliminate the mutual cancellation of positive and negative deviations, while amplifying the penalty weight for large deviations. The optimization objective is to minimize this sum of squares, thereby ensuring that the fitted curve, overall, best approximates the distribution trend of the original contour points.
[0086] By taking the partial derivatives of a, b, and c and setting them equal to 0, the fitting coefficients a, b, and c are obtained, and then the sub-pixel level contour curve is obtained. The sub-pixel coordinates of any point on the contour can be accurately obtained through this curve.
[0087] The specific solution process is as follows: Take the partial derivatives of the sum of squared objective errors with respect to a, b, and c, and set the partial derivatives equal to 0 to obtain a system of three linear equations in three variables:
[0088] By solving the linear equations using Cramer's rule or matrix methods, a unique solution for the fitting coefficients a, b, and c can be obtained, ensuring that the fitting curve can accurately fit the sub-pixel contour edge and further improve the sub-pixel positioning accuracy.
[0089] Through step S504, this embodiment successfully performed sub-pixel-level fitting of the contour edge using the least squares method, obtaining a complete expression for the sub-pixel-level contour fitting curve. Based on this expression, the ordinate value corresponding to any abscissa on the contour can be calculated, and the calculation result can be retained to one decimal place, breaking through the limitation of the original integer pixel grid. The final output sub-pixel-level contour coordinates eliminate the stepped jagged effect of the pixel-level contour, making the contour edge present a continuous and smooth curve shape, laying a data foundation for the subsequent high-precision solution of the Mark shape center point.
[0090] In one embodiment of the shape feature matching method based on sub-pixel level positioning in this application, it may further include the following: Step S601: Extract the Zernike moment feature vector of the subpixel contour coordinates as the first set of feature vectors, and at the same time extract the Zernike moment feature vector of the subpixel contour of the preset template image as the second set of feature vectors. Perform normalized dot product operation on the first set of feature vectors and the second set of feature vectors to determine the corresponding Zernike moment similarity. Step S602: Extract the 7th order Hu moment feature vector of the sub-pixel contour coordinates, and simultaneously extract the 7th order Hu moment feature vector of the sub-pixel contour of the preset template image. For each order Hu moment feature vector, calculate the difference ratio between the sub-pixel contour coordinates and the sub-pixel contour of the template image, and sum the difference ratios according to preset weight coefficients to determine the corresponding weighted Hu moment similarity.
[0091] Optionally, in this embodiment, this step calculates the Zernike moment feature similarity and the weighted Hu moment feature similarity.
[0092] Specifically, Zernike moment similarity The expression for calculating the Zernike moment features using normalized methods is as follows:
[0093] in, Zernike moments for the subpixel contours of the target to be detected; Zernike moments for the template subpixel contour.
[0094] Leveraging Zernike moments' ability to provide a detailed description of sub-pixel contours, this method enables a quantitative assessment of the shape similarity between target and template contours. It is robust to contour rotation, scaling, and minor noise interference within the image. Furthermore, based on sub-pixel coordinate input, the similarity calculation results are more accurate and smoother than traditional pixel-level methods, providing high-confidence foundational data for subsequent multi-feature fusion.
[0095] Specifically, the weighted Hu moment similarity The expression is calculated by the difference ratio between the eigenvectors of the 7th order Hu moment:
[0096] in, , These are the k-th Hu moments (k=1~7) of the target and the template, respectively. The weights are the k-th Hu moments. The weight coefficients can be pre-adjusted according to the geometric type of the Mark point (such as symmetrical or slender). For example, increase the weight of lower-order moments for symmetrical shapes and increase the weight of higher-order moments for asymmetrical shapes.
[0097] This step utilizes the geometric invariance of Hu moments to measure the degree of matching between the target and the template at the overall shape level. A weighted mechanism is used to enhance the contribution of key-order features to similarity judgment, improving the targeting and accuracy of shape matching. Simultaneously, since the input is a sub-pixel contour, the similarity calculation results are more refined and stable than those for pixel-level contours, effectively reducing the risk of false matching caused by blurred edges or low contrast, and providing a reliable basis for generating the final matching confidence score.
[0098] Through step S602, this embodiment successfully calculated the Zernike moment feature similarity and the weighted Hu moment feature similarity, providing a reliable basis for the subsequent generation of matching confidence.
[0099] In one embodiment of the shape feature matching method based on sub-pixel level positioning in this application, it may further include the following: Step S701: The Zernike moment similarity and the weighted Hu moment similarity are weighted and fused according to the preset fusion weight coefficient to determine the corresponding shape feature similarity. The fusion weight coefficient is used to balance the ability of Zernike moments to describe the subtle features of the contour with the advantage of weighted Hu moments in representing the geometric invariance of the contour. Step S702: The shape feature similarity is transformed into a preset confidence interval through a nonlinear mapping function to determine the corresponding matching confidence. Based on the coordinates of the sub-pixel contour with the highest matching confidence among multiple candidate sub-pixel contours, the coordinates of the corresponding detection image center point are determined.
[0100] Optionally, in this embodiment, the shape feature similarity between the sub-pixel level contour and the template sub-pixel level contour is calculated by combining Zernike moment features and weighted Hu moment features. The calculation formula is as follows:
[0101] in, Zernike moment similarity; Weighted Hu moment similarity; These are the weighting coefficients.
[0102] In this embodiment, the weighting coefficient is set. This highlights the sub-pixel feature advantage of Zernike moments.
[0103] Understandably, Zernike moments possess high sensitivity to subtle geometric features of the contour and sub-pixel accuracy, enabling them to finely depict local changes in the contour; while weighted Hu moments exhibit translation, rotation, and scale invariance, stably describing the overall geometric structure of the contour. By adjusting the weighting coefficients, this step can dynamically balance the contribution of the two features based on the geometric type of different Mark points (such as symmetrical or elongated) or the emphasis of the industrial scenario (such as a greater focus on detail accuracy or greater focus on resistance to deformation), thereby obtaining more robust and accurate similarity evaluation results than a single measurement method.
[0104] After obtaining the shape feature similarity, the similarity value is usually still within an unnormalized continuous numerical range and cannot be directly used as a threshold for judging the effectiveness of the match. Therefore, this step applies a non-linear mapping function to the similarity, compressing and normalizing it to a preset confidence interval (usually between 0 and 1). The matching confidence obtained after mapping expresses the reliability of the matching between the current sub-pixel contour and the template contour in terms of shape features; the closer the value is to 1, the more reliable the match. In the actual detection process, the system calculates the matching confidence of multiple candidate sub-pixel contours extracted from the same image one by one, and then selects the contour with the highest confidence. Finally, based on the coordinate data of this contour, the center point coordinates of the target Mark point in the detection image are accurately calculated as the final detection output result.
[0105] Through step S702, this embodiment successfully dynamically balances the contribution of the two features and improves the discriminativeness and stability of the matching decision through nonlinear mapping, avoiding misjudgment due to small fluctuations in similarity, and achieving shape feature matching.
[0106] To improve the accuracy and efficiency of image shape feature matching, this application provides an embodiment of a shape feature matching device based on subpixel-level positioning for implementing all or part of the aforementioned shape feature matching method based on subpixel-level positioning. See [link to embodiment]. Figure 2 The shape feature matching device based on sub-pixel level positioning specifically includes the following components: Image preprocessing module 10 is used to acquire the image to be detected, perform image preprocessing operations on the image to be detected, and determine the corresponding initial pixel-level contour. The image preprocessing operations include sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation contour simplification, and small area noise contour filtering. The sub-pixel contour extraction module 20 is used to normalize the coordinates of the initial pixel-level contour, extract the sub-pixel contour of the initial pixel-level contour after coordinate normalization according to the set Zernike moment algorithm, determine the corresponding Zernike moment feature vector, the Zernike moment feature vector contains the contour geometric shape features, and based on the Zernike moment feature vector, the least squares method is used to perform sub-pixel level fitting on the contour edge, and the fitting coefficient is solved to determine the corresponding sub-pixel level contour coordinates. The subpixel similarity calculation module 30 is used to calculate the Zernike moment similarity and weighted Hu moment similarity between the subpixel-level contour coordinates and the subpixel contour of the preset template image, perform weighted fusion on the Zernike moment similarity and the weighted Hu moment similarity to determine the corresponding shape feature similarity, convert the shape feature similarity into a matching confidence score, and determine the corresponding detection image center point coordinates based on the subpixel-level contour coordinates with the highest matching confidence score to complete the image shape feature matching.
[0107] As described above, the shape feature matching device based on subpixel-level localization provided in this application can obtain an initial pixel-level contour by sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation, and small area noise filtering on the image to be detected; extract the initial contour at the subpixel level based on the Zernike moment algorithm, and perform subpixel-level fitting on the contour edges using the least squares method to generate subpixel-level contour coordinates; calculate the Hu moment similarity and Zernike moment similarity between the subpixel contour and the template subpixel contour, and weight them to map to the matching confidence; finally, determine the center point of the corresponding detection rectangle based on the candidate subpixel-level contour coordinates with the highest matching confidence, thereby improving the accuracy and efficiency of image shape feature matching.
[0108] To further illustrate this solution, this application also provides a specific application example of using the above-mentioned shape feature matching device based on sub-pixel level positioning to implement the shape feature matching method based on sub-pixel level positioning, which specifically includes the following: The overall implementation steps of this embodiment are as follows: Image preprocessing: First, Gaussian difference filtering is used to remove image noise, with the filter kernel size set to 3×3; Canny edge detection is used to extract pixel-level initial contours, and appropriate high and low thresholds are set (which can be adjusted through the configuration file) to avoid edge breakage; morphological closing operation (kernel size of 2×2) is used to repair broken contours, polygon approximation (approximation accuracy of 0.01×contour perimeter) is used to simplify redundant contour points, small-area noise contours are filtered, small noise contours with an area of less than 5 pixels are filtered, and the complete pixel-level contour of the target is preserved. Subpixel-level contour extraction: The cv::findContoursSubPix function of OpenCV is called, and the Zernike moment features of the pixel-level contour are calculated by combining the 8th order Zernike moment formula of this embodiment. The pixel-level contour is then fitted with the least squares fitting formula to obtain the subpixel-level contour coordinates (x, y, with 1 decimal place), thereby eliminating the jagged effect of the pixel-level contour and accurately describing the subtle features of the contour. Subpixel-level similarity matching and center point determination: Finally, the similarity between the subpixel-level contour and the template contour is calculated using the subpixel-level similarity formula (Zernike moment similarity and weighted Hu moment similarity fusion), and converted to a confidence level of 0~1. Based on the subpixel-level contour with the highest confidence level, the center point coordinates of the Mark shape (i.e., the center point coordinates of the detection rectangle) are accurately calculated, achieving subpixel-level high-precision shape matching. While resisting scale, rotation, and noise interference, it significantly improves the positioning accuracy of the Mark center point.
[0109] This invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor performs the above-described shape feature matching method based on sub-pixel level positioning.
[0110] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described shape feature matching method based on sub-pixel level positioning.
[0111] This invention also provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described shape feature matching method based on sub-pixel level positioning.
[0112] In this embodiment of the invention, an initial pixel-level contour can be obtained by sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation, and small area noise filtering on the image to be detected. Sub-pixel-level extraction of the initial contour is then performed based on the Zernike moment algorithm, and sub-pixel-level fitting of the contour edges is combined with the least squares method to generate sub-pixel-level contour coordinates. The Hu moment similarity and Zernike moment similarity between the sub-pixel contour and the template sub-pixel contour are calculated, and the weighted average is mapped to the matching confidence score. Finally, the center point of the corresponding detection rectangle is determined based on the candidate sub-pixel-level contour coordinates with the highest matching confidence score. This improves the accuracy and efficiency of image shape feature matching.
[0113] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0114] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0115] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0116] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0117] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A shape feature matching method based on sub-pixel level localization, characterized in that, The method includes: The image to be detected is acquired, and image preprocessing operations are performed on the image to be detected to determine the corresponding initial pixel-level contour. The image preprocessing operations include sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation contour simplification, and small area noise contour filtering. The initial pixel-level contour is normalized in coordinates. According to the set Zernike moment algorithm, the initial pixel-level contour after coordinate normalization is extracted at the sub-pixel level to determine the corresponding Zernike moment feature vector. The Zernike moment feature vector contains the geometric shape features of the contour. Based on the Zernike moment feature vector, the least squares method is used to perform sub-pixel level fitting on the contour edge and solve the fitting coefficient to determine the corresponding sub-pixel level contour coordinates. Calculate the Zernike moment similarity and weighted Hu moment similarity between the subpixel contour coordinates and the subpixel contour of the preset template image. Perform weighted fusion on the Zernike moment similarity and the weighted Hu moment similarity to determine the corresponding shape feature similarity. Convert the shape feature similarity into a matching confidence score. Based on the subpixel contour coordinates with the highest matching confidence score, determine the corresponding detection image center point coordinates to complete image shape feature matching.
2. The shape feature matching method based on sub-pixel level positioning according to claim 1, characterized in that, The Gaussian difference denoising and the Canny edge detection include: The Gaussian difference denoising method includes: performing convolution operations on the image to be detected using two Gaussian kernel functions of different scales, subtracting the convolution results output by the two Gaussian kernel functions of different scales, in order to extract high-frequency edge information in the image and determine the corresponding denoised image; The Canny edge detection includes: calculating the gradient magnitude and gradient direction of each pixel in the denoised image, determining the corresponding gradient image, removing non-edge pixels of the gradient image according to a preset non-maximum suppression algorithm, determining the corresponding gradient edge, performing double thresholding hysteresis thresholding on the gradient edge to complete edge connection, and determining the corresponding binary edge image.
3. The shape feature matching method based on sub-pixel level positioning according to claim 2, characterized in that, The morphological closing operation contour repair, the polygon approximation contour simplification, and the small-area noise contour filtering include: The morphological closing operation contour repair includes: performing dilation and erosion operations sequentially on the binary edge image to determine the corresponding edge contour closing region, wherein the kernel size of the dilation operation is 2×2 pixels and the kernel size of the erosion operation is 2×2 pixels, which are used to fill the edge break gaps and connect adjacent edge segments through the closing operation. The polygon approximation contour simplification includes: performing polygon fitting on the closed region of the edge contour according to a preset Douglas-Peucker algorithm, removing redundant contour vertices of the closed region of the edge contour based on a preset approximation accuracy threshold, and determining the corresponding simplified contour point set. The small-area noise contour filtering includes: calculating the area of each simplified contour for the simplified contour point set, identifying contours with an area smaller than a preset threshold as noise contours and removing them, and determining the corresponding initial pixel-level contours.
4. The shape feature matching method based on sub-pixel level positioning according to claim 1, characterized in that, The step of extracting sub-pixel-level contours from the initial pixel-level contours after coordinate normalization according to the set Zernike moment algorithm, and determining the corresponding Zernike moment feature vectors, includes: Using an 8th-order Zernike orthogonal polynomial as the basis function, the initial pixel-level contour after coordinate normalization is orthogonally decomposed, and the Zernike moment values corresponding to each order are calculated respectively. All calculated Zernike moment values are combined in order of order to determine the corresponding Zernike moment feature vector, which is used to characterize the geometric features of the contour.
5. The shape feature matching method based on sub-pixel level positioning according to claim 1, characterized in that, The process of fitting the contour edges at the sub-pixel level using the least squares method based on the Zernike moment feature vector, and solving for the fitting coefficients to determine the corresponding sub-pixel level contour coordinates includes: Obtain all contour points on the initial pixel-level contour described by the Zernike moment feature vector, and extract the contour parameters of each contour point as data points to be fitted. Construct a quadratic polynomial fitting model to characterize the curve shape of the contour edge; Construct a least squares optimization objective function, which aims to minimize the sum of squares of the differences between the measured values of the ordinates of all data points to be fitted and the predicted values of the quadratic polynomial fitting model. Solve the least squares optimization objective function to determine the corresponding subpixel-level contour fitting curve, and calculate the subpixel-level contour coordinates of any point on the contour based on the fitting curve.
6. The shape feature matching method based on sub-pixel level positioning according to claim 1, characterized in that, The calculation of the Zernike moment similarity and weighted Hu moment similarity between the subpixel-level contour coordinates and the subpixel contours of the preset template image includes: Extract the Zernike moment feature vector of the subpixel contour coordinates as the first set of feature vectors. At the same time, extract the Zernike moment feature vector of the subpixel contour of the preset template image as the second set of feature vectors. Perform a normalized dot product operation on the first set of feature vectors and the second set of feature vectors to determine the corresponding Zernike moment similarity. Extract the 7th order Hu moment feature vector of the subpixel contour coordinates, and simultaneously extract the 7th order Hu moment feature vector of the subpixel contour of the preset template image. For each order Hu moment feature vector, calculate the difference ratio between the subpixel contour coordinates and the subpixel contour of the template image, and then sum the difference ratios according to preset weight coefficients to determine the corresponding weighted Hu moment similarity.
7. The shape feature matching method based on sub-pixel level positioning according to claim 1, characterized in that, The step of weightedly fusing the Zernike moment similarity and the weighted Hu moment similarity to determine the corresponding shape feature similarity, converting the shape feature similarity into a matching confidence score, and determining the corresponding detection image center point coordinates based on the sub-pixel level contour coordinates with the highest matching confidence score includes: The Zernike moment similarity and the weighted Hu moment similarity are weighted and fused according to the preset fusion weight coefficient to determine the corresponding shape feature similarity. The fusion weight coefficient is used to balance the ability of Zernike moments to describe subtle contour features with the advantage of weighted Hu moments in representing the geometric invariance of contours. The shape feature similarity is transformed to a preset confidence interval through a nonlinear mapping function to determine the corresponding matching confidence. Based on the coordinates of the sub-pixel contour with the highest matching confidence among multiple candidate sub-pixel contours, the coordinates of the corresponding detection image center point are determined.
8. A shape feature matching device based on sub-pixel level positioning, characterized in that, The device includes: The image preprocessing module is used to acquire the image to be detected, perform image preprocessing operations on the image to be detected, and determine the corresponding initial pixel-level contour. The image preprocessing operations include sequentially performing Gaussian difference denoising, Canny edge detection, morphological closing operation contour repair, polygon approximation contour simplification, and small area noise contour filtering. The sub-pixel contour extraction module is used to normalize the coordinates of the initial pixel-level contour, extract the sub-pixel contour of the initial pixel-level contour after coordinate normalization according to the set Zernike moment algorithm, determine the corresponding Zernike moment feature vector, the Zernike moment feature vector contains the contour geometric shape features, and based on the Zernike moment feature vector, the least squares method is used to perform sub-pixel level fitting on the contour edge, and the fitting coefficient is solved to determine the corresponding sub-pixel level contour coordinates. The subpixel similarity calculation module is used to calculate the Zernike moment similarity and weighted Hu moment similarity between the subpixel-level contour coordinates and the subpixel contours of the preset template image, perform weighted fusion on the Zernike moment similarity and the weighted Hu moment similarity to determine the corresponding shape feature similarity, convert the shape feature similarity into a matching confidence score, and determine the corresponding detection image center point coordinates based on the subpixel-level contour coordinates with the highest matching confidence score to complete the image shape feature matching.
