Complex background image contour matching method based on physical contour feature point template
By generating contour feature point templates based on gradient information, combining nonmaximum suppression and grid statistics, and employing sliding window matching, the problem of high-precision image matching under complex backgrounds was solved, enabling accurate positioning and detection of parts.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XIAN AEROSPACE MECHATRONICS & INTELLIGENT MANUFACTURING CO LTD
- Filing Date
- 2026-02-24
- Publication Date
- 2026-05-19
AI Technical Summary
Existing image matching methods perform poorly in complex backgrounds, especially when contours are unclear, making it difficult to achieve robust and accurate matching and positioning, thus failing to meet the needs of industrial inspection.
Contour feature point templates are generated based on gradient information in the image. Through gradient direction matching technology, combined with nonmaximum suppression and grid statistics methods, multi-angle and multi-scale contour feature point templates are generated. The coordinates of the contour matching center point are calculated by using a sliding window matching method.
Achieving high-precision contour matching in complex backgrounds improves the accuracy and speed of matching, enabling precise location and positioning of parts in industrial scenarios and meeting the needs of industrial inspection.
Smart Images

Figure CN122066985A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, specifically to a method for contour matching of complex background images based on physical contour feature point templates. Background Technology
[0002] Image matching methods are widely used across various industries. They aim to use template images to find similar regions in an image to be detected, enabling functions such as counting and locating similar objects. Common image matching methods include grayscale matching, feature matching, and contour matching.
[0003] Gray-level matching is based on the gray-level distribution of the template image and the image to be detected, and determines whether the match is successful through a certain gray-level similarity evaluation method. Because it highly depends on the gray-level information of the image, its matching effect is poor and its matching speed is slow in complex environments. Feature matching, on the other hand, performs similarity matching based on feature points in the template image and the image to be matched. It is suitable for images with obvious feature points, but its matching effect is also limited for complex images with indistinct features. Contour matching methods compare the contour data of the template image and the image to be matched, making it suitable for images with clear contours, but its performance is poor in complex backgrounds or when the contours are unclear.
[0004] In contrast, gradient information in images is more robust to changes in illumination. Gradient-direction-based matching methods extract image gradient information for contour feature point template matching, effectively overcoming the interference of complex backgrounds on contour matching. Summary of the Invention
[0005] The technical problem this invention aims to solve is to provide a method for contour matching of complex background images based on physical contour feature point templates. This method generates image contour feature point templates based on gradient information in the image and combines this with gradient direction matching technology to achieve highly robust and high-precision image matching and positioning against complex backgrounds. This not only improves matching accuracy but also feeds the matching results back to the physical coordinate system, enabling precise location and positioning of parts and components, thus meeting the practical needs of industrial inspection.
[0006] To address the aforementioned technical problems, embodiments of the present invention provide the following technical solution: a method for contour matching of complex background images based on physical contour feature point templates, comprising the following steps: Based on the image pixel equivalent, the physical contour data is converted into contour image coordinate data; Generate a contour feature point template image based on the contour image coordinate data; Gradient information is extracted and calculated from the contour feature point template image, and contour feature points are extracted. Candidate point set is obtained by screening the contour feature points based on nonmaximum suppression, and uniform sampling is performed on the candidate point set based on grid statistics method; Based on the preset contour feature point template parameters, the uniformly sampled candidate point set is rotated or scaled to generate multiple contour feature point templates with different angles and scales. Based on the contour feature point template and the image to be matched, multi-template traversal matching is performed to obtain the contour matching result; Based on the contour matching results, calculate the coordinates of the contour matching center point.
[0007] Further, a contour feature point template image is generated based on the contour image coordinate data, specifically as follows: Based on the maximum and minimum coordinate values of the contour image coordinate data, calculate the contour cropping size and the contour center point, and perform boundary augmentation on the contour image cropped according to the cropping size; Align the center of the contour with the center of the amplified contour image, and fill the contour according to the aligned contour coordinates to generate a contour feature point template image.
[0008] Further, gradient information is extracted and calculated from the contour feature point template image, and contour feature points are extracted, specifically as follows: Image pyramid models of different levels are created, and gradient information is extracted from the contour feature point template image based on the Scharr filter at different pyramid levels. The extracted gradient information includes the horizontal gradient and the vertical gradient. Calculate the gradient magnitude and gradient direction angle of each pixel based on the horizontal and vertical gradients. Non-maximum suppression is performed based on the gradient magnitude, and a gradient direction angle threshold is set. Neighborhood consistency is judged for the current pixel: if the number of pixels with the same gradient direction in the neighborhood of the current pixel exceeds a preset number, the current pixel is retained as a contour feature point.
[0009] Furthermore, the step of filtering the contour feature points based on nonmaximum suppression to obtain a candidate point set specifically involves: The gradient magnitude map corresponding to the contour feature point template image is dilated using a rectangular structuring element of a preset size to obtain the dilated gradient magnitude map. Compare the values of corresponding contour feature points in the gradient magnitude map of the original image and the dilated gradient magnitude map. If they are equal, the corresponding contour feature point is determined to be a local maximum in the neighborhood. Simultaneously, determine whether the gradient direction angle of the corresponding contour feature point is greater than zero. If both the local maximum condition and the gradient direction angle being greater than zero are satisfied, then add the corresponding contour feature point to the candidate point set.
[0010] Furthermore, the uniform sampling of the candidate point set based on the grid statistical method specifically involves: The expanded gradient magnitude map is divided into row and column grids, with a fixed number of horizontal grids and a dynamically adjusted number of vertical grids based on the size of the gradient magnitude map. Calculate the index of each candidate point in the candidate point set in the row and column grid, and count the number of candidate points in each grid to form a density matrix; The density matrix is normalized to its maximum value to obtain the normalized density value for each grid cell. The basic distance threshold is calculated based on the expected number of feature points and the total number of candidate points. The adaptive distance threshold for each grid cell is then calculated by combining the normalized density value and the preset density influence coefficient. Candidate points are sorted from largest to smallest according to their gradient magnitude, and it is determined in turn whether the distance between each candidate point and all points in the selected point set is greater than the adaptive distance threshold corresponding to the grid. If so, the corresponding candidate point is added to the selected point set. This process continues until the number of selected points reaches the desired number of feature points or all candidate points have been traversed, thus completing uniform sampling.
[0011] Furthermore, the process of rotating or scaling the uniformly sampled candidate point set to generate multiple contour feature point templates with different angles and scales specifically involves: Calculate the center point of the uniformly sampled contour feature point set; Each point in the contour feature point set is translated to a coordinate system with the center point as the origin to obtain the translated feature point set. According to the preset contour feature point template parameters, the points in the translated feature point set are scaled and rotated in sequence to generate multiple new feature point sets, where each set of transformations corresponds to a specific rotation angle and scaling factor; the preset contour feature point template parameters include starting angle, ending angle, angle step, starting scaling factor, ending scaling factor, and scaling factor step. Each new set of feature points is saved as an independent contour feature point template, forming a multi-angle, multi-scale contour feature point template set.
[0012] Furthermore, the step of performing multi-template traversal matching based on the contour feature point template and the image to be matched to obtain the contour matching result is specifically as follows: For the matching image, gradient magnitude maps at different levels are generated according to the pyramid hierarchy; Traverse the set of contour feature point templates with multiple angles and scales. For each template, transform the template feature points to a coordinate system with the upper left corner of the template as the origin according to the template size. The sliding window method is used to slide the contour feature point template on the image to be matched to find similar regions, calculate similarity scores, output and update the similarity matrix; The maximum matching score and its position are found in the similarity matrix. If the maximum score exceeds a preset score threshold, the final matching position is calculated to obtain the contour matching result.
[0013] Furthermore, the sliding window method involves sliding the contour feature point template across the image to be matched to find similar regions, calculating similarity scores, outputting and updating the similarity matrix, where the template sliding range is span_x = WW. t span_y=HH t W t H t Let W be the template size, and H be the gradient magnitude map sizes corresponding to the matched image; define the output similarity matrix as D, then the similarity matrix update formula is: Where D[j] represents the value at position j in the similarity matrix D, L Pi [j] represents template feature point P i The value of j at the corresponding position.
[0014] Further, the maximum matching score and its position are found in the similarity matrix. If the maximum score exceeds a preset score threshold, the final matching position is calculated to obtain the matching result, specifically: Find the maximum matching score and its corresponding position in the similarity matrix D. The matching score is calculated as follows: Where D[c, r] represents the value of the similarity matrix at position [c, r], B is the normalized value, and score[c, r] represents the matching score calculated at [c, r], with a value between 0 and 1; Calculate the maximum score (best_score) in the matching scores and its corresponding position (best_r, best_c). If the maximum score (best_score) is greater than the set score threshold (score_threshold), then perform the final matching position calculation, using the following formula: in,( , () represents the final matching position coordinates, T represents the current pyramid level, and offset represents the offset calculated as follows: .
[0015] Further, based on the contour matching result, the coordinates of the contour matching center point are calculated, specifically as follows: The location information of the contour matching is obtained through similarity calculation. , Based on the template dimensions Wt and Ht, calculate the initial coordinates of the matching center point: , ; Calculate the center point of all rotating contour feature point template feature points. Coordinates of the center point of the first contour feature point template feature point offset ; The offset The coordinates of the center point of the initial matching point are compensated to obtain the final corrected coordinates of the center point of the matching contour, specifically as follows: The coordinates of the horizontal center point of the final matched contour in the image to be matched are given as the template of the i-th contour feature point. The coordinates of the vertical center point of the final matched contour in the image to be matched are obtained by using the template of the i-th contour feature point. When matching the i-th template with the image to be matched, the horizontal coordinate of the top left corner of the matching region. When matching the i-th template with the image to be matched, the vertical coordinate of the top left corner of the matching region The horizontal width of the template for the i-th contour feature point; Let be the horizontal height of the template for the i-th contour feature point; This represents the total horizontal offset compensation for the i-th template. This represents the total offset compensation amount of the i-th template in the vertical direction.
[0016] The beneficial effects of the above-mentioned technical solution of the present invention are as follows: This invention solves the problem of image matching and localization in industrial scenarios that rely on raw physical contour data. The method achieves high-precision contour matching in complex background environments. It generates multiple contour templates from an initial contour and employs a uniform downsampling strategy for feature points, effectively reducing the number of feature points while ensuring the integrity of feature information, thereby improving the computational efficiency of subsequent matching. The sliding window-based matching method ensures accurate and fast contour template matching. Furthermore, to address the center point offset problem caused by irregular contour rotation, a center offset compensation method is used between the original template and the first template feature point, significantly improving the accuracy of matching different contours. Attached Figure Description
[0017] Figure 1 This is a schematic diagram illustrating the conversion of the physical contour into image coordinates according to the present invention.
[0018] Figure 2 The template image generated for contour filling in this invention.
[0019] Figure 3 This is a schematic diagram of the distribution of contour feature points after downsampling according to the present invention.
[0020] Figure 4 This is a schematic diagram of the multi-angle contour feature point template of the present invention.
[0021] Figure 5 This is a diagram showing the results of the physical contour template image matching based on the present invention.
[0022] Figure 6 This is a flowchart of the complex background image contour matching method based on physical contour feature point templates according to the present invention. Detailed Implementation
[0023] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.
[0024] like Figure 6 As shown, this invention proposes a method for contour matching of complex background images based on physical contour feature point templates, including the following steps: S1. Based on the image pixel equivalent, convert the physical contour data into contour image coordinate data so that the physical contour scale is consistent with the scale of the image to be detected. S2. Generate a contour feature point template image based on the contour image coordinate data; S3. Extract and calculate gradient information from the contour feature point template image, and extract contour feature points; S4. Based on nonmaximum suppression, the contour feature points are screened to obtain a candidate point set. The candidate point set is uniformly sampled based on the grid statistical method to ensure that the feature points are evenly distributed and do not affect the effective features. The feature point data is reduced, thereby improving the matching efficiency. S5. Based on the preset contour feature point template parameters, rotate or scale the uniformly sampled candidate point set to generate multiple contour feature point templates with different angles and scales. S6. Based on the contour feature point template and the image to be matched, perform multi-template traversal matching to obtain the contour matching result; S7. Based on the contour matching results, calculate the coordinates of the contour matching center point to solve the problem of center point offset when the irregular contour is at different angles, and ensure that the contour center point calculation is accurate and reliable.
[0025] The following details the implementation method and principle of the above steps: S1. Based on the image pixel equivalent, convert the physical contour data into contour image coordinate data.
[0026] Because the template generated directly using physical contour data is not at the same scale as the object contour data captured in the actual image, it is necessary to transform the physical coordinate scale to the image coordinate scale. Step S1 achieves the transformation from physical scale to image scale based on pixel equivalents, and the formula is as follows: Where p w For physical coordinates, p i The coordinates are the image coordinates, and the pixel is the pixel equivalent, representing the actual physical size corresponding to a pixel value in the image. Figure 1 The diagram shows the conversion of physical contours into image coordinates.
[0027] S2. Generate a contour feature point template image based on the contour image coordinate data.
[0028] Based on the contour image coordinate information, contour cropping is performed first. The contour dimensions and center point are calculated from the contour data. min_x, min_y, max_x, and max_y represent the minimum and maximum coordinate values in the contour data, respectively. The contour dimensions are expressed as width = max_x - min_x and height = max_y - min_y. Therefore, the x-coordinate of the center point is... =center((min_x + max_x) / 2, where the y-axis is... =(min_y + max_y) / 2).
[0029] To prevent the loss of outermost contour edge information during filling, the contour size is padded based on the trim size, resulting in a final contour template size of [size missing]. , Then, align the center of the outline with the center of the outline template size. , .in, The coordinates of the contour feature points in the new coordinate system with the center of the template as the reference after coordinate transformation; The coordinates of the contour feature points in the vertical direction in a new coordinate system with the center of the template as the reference after coordinate transformation; The original horizontal coordinates of the contour feature points in the original image coordinate system; The coordinates of the contour feature points are the original coordinates in the vertical direction of the original image coordinate system. Finally, contour filling is performed based on the cropped contour image data to generate a contour template binary image. Figure 2 The image shown is a template image generated based on contour data filling.
[0030] S3. Extract and calculate gradient information from the contour feature point template image, and extract contour feature points.
[0031] First, image pyramid models with different levels are created. Then, gradient information of contour feature point template images is extracted based on the Scharr filter at different pyramid levels, where Gx represents the horizontal gradient. Gy is the gradient in the vertical direction. .
[0032] Then, based on the horizontal and vertical gradients described above, the gradient magnitude and gradient direction angle of each pixel are calculated. Let Mag represent the gradient magnitude. Then, based on the gradient information in the horizontal and vertical directions, the gradient direction angle Angle is calculated. Next, non-maximum suppression is performed based on the gradient magnitude. A threshold for filtering gradient direction angles is set. If the gradient direction angle Angle(i) of the current pixel coordinate is greater than the threshold, then the 8-neighbor pixel statistics of the current pixel coordinate are performed. If the number of pixels with the same gradient direction in the neighborhood exceeds the preset number (e.g., greater than 5), then the angle direction corresponding to the pixel coordinate is retained, thereby filtering out those pixels with larger gradient magnitudes and consistent direction neighborhoods, enhancing the stability and accuracy of the edges.
[0033] S4. Based on nonmaximum suppression, the contour feature points are screened to obtain a candidate point set. The candidate point set is uniformly sampled based on the grid statistical method. Since the number of extracted template feature points is relatively large, it will affect the subsequent matching calculation speed. The more feature points there are, the more calculations are required during matching, which increases the matching speed. Therefore, it is necessary to screen the feature points using nonmaximum suppression and resample the feature point distribution to ensure that the feature point distribution is uniform and does not affect the effective features. In addition, the number of feature points is reduced, thereby improving the matching efficiency.
[0034] (1) The candidate point set is obtained by screening the contour feature points based on nonmaximum suppression. First, a rectangular structuring element of preset size is used to dilate the gradient magnitude map corresponding to the contour feature point template image. This dilation operation performs non-maximum suppression filtering on the gradient magnitude map, replacing each gradient magnitude point in the image with its neighborhood maximum. Thus, in the dilated image, the value of each gradient magnitude point represents the maximum response in its neighborhood. Then, by comparing the gradient magnitude in the original image with the corresponding value in the dilated image, if they are equal, it indicates that the point is the neighborhood maximum, i.e., a local maximum. Simultaneously, if the gradient angle value of the point is greater than 0, the point is added to the candidate point set. Specifically, a 3x3 rectangular structuring element is constructed to dilate the gradient magnitude map. Then, the gradient magnitude score of each pixel p(c, r) excluding the boundary is extracted, and the gradient angle is checked for validity (greater than 0). If the condition is met, the point is added to the candidate point set. This method is efficient and robust, suitable for gradient-based feature point detection and template matching tasks, and effectively avoids duplicate detection and interference from invalid points.
[0035] (2) Uniform sampling of candidate point set based on grid statistical method Downsampling of the candidate point set, based on grid statistical methods, can effectively achieve uniform sampling of the candidate point set, avoiding the problem of local feature loss caused by setting a fixed distance for screening.
[0036] First, the gradient magnitude map is divided into grids. The gradient magnitude map size is WxH, and the grid size is set to RxC. To better divide the grid cells, a fixed number of horizontal grid cells R (i.e., the number of grid rows) is set, and the number of vertical grid cells C = RxW / H. That is, the number of grid columns is dynamically adjusted according to the aspect ratio of the gradient magnitude map to ensure that the grid distribution fits the size of the gradient magnitude map more closely. For each candidate point... Calculate the index of the grid cell in which it is located: , Statistical density matrix This formula represents constructing a matrix D (i.e., a density matrix) of size R rows and C columns, and assigning a value to the grid cell containing each candidate feature point (row index). Column index ) Perform count accumulation: for each candidate feature point detected falling into a grid cell ( , Within ) the matrix value D corresponding to that unit. , Adding 1, each element of the final matrix D represents the number of candidate feature points in the corresponding grid, intuitively reflecting the distribution density of feature points.
[0037] Secondly, density normalization is performed. Maximum value normalization ensures that the density value remains within the range [0, 1], facilitating subsequent calculations. The maximum density value is then calculated. Normalized density: To prevent division by zero if D max If it is extremely small, set it to 1.
[0038] Then, feature point data N is selected based on the expectation. f and the number of candidate feature points N c Calculate the base distance threshold: By combining the base distance threshold and local density, an adaptive distance threshold is calculated: Where α is the density influence coefficient, ρ local The density is locally normalized, so that the higher the density, the larger the distance threshold, thus avoiding overly dense point selection in dense areas.
[0039] Finally, the candidate point set is sorted in descending order of gradient magnitude to ensure that feature points with strong responses are selected first. An empty set is initialized. For each candidate point p i Determine if the distance to the selected point is greater than the adaptive threshold: If the condition is met, add the point to S; otherwise, discard the point, until... Or iterate through all candidate points. Figure 3 The diagram shows the distribution of contour feature points after feature point downsampling.
[0040] S5. Based on the preset contour feature point template parameters, rotate or scale the uniformly sampled candidate point set to generate multiple contour feature point templates with different angles and scales.
[0041] Since the objects in the target image may be placed at different angles or have similar contours but different sizes during contour matching, it is necessary to generate a set of contour templates with multiple angles and scales based on the extracted contour feature points.
[0042] First, for the contour feature point set Calculate its center point, and then transform the contour feature points to the image origin based on the center point to obtain Q. Set the parameters for generating the contour template: starting angle: angle_start, ending angle: angle_extent, angle step: angle_step, starting scaling factor: scale_start, ending scaling factor: scale_extent, and scaling factor step: scale_step.
[0043] Finally, the feature point set Q is scaled using a scaling factor s, resulting in the scaled point set. And create a rotation matrix by rotating the angle θ. This yields a new set of feature points after rotation and scaling. Thus, based on the scaling factor and rotation angle, contour feature point templates of different angles and scales are generated from the extracted feature point data. Figure 4 The image shown is a schematic diagram of a multi-angle contour feature point template.
[0044] S6. Based on the contour feature point template and the image to be matched, perform multi-template traversal matching to obtain the contour matching result.
[0045] For the image A to be matched, gradient magnitude maps at different levels are generated according to the pyramid hierarchy. The feature point templates are traversed. For the current template feature point, the feature point is transformed to the upper left corner of the template according to the template size. For the feature point set... The coordinates of the top left point of the template are p. l The transformed set of feature points Under the same pyramid level, the template size width W t Height H t The gradient magnitude map corresponding to the matching image is defined by its width W and height H. Then, using a sliding window method, the template is slid across the image to be matched to find similar regions and calculate a similarity score. The template sliding range is span_x = W / H. t span_y=HH t If the output similarity matrix is D, then the formula for updating the similarity matrix is: Where D[j] represents the value at position j in the similarity matrix D, L Pi [j] represents template feature point P i The value of j at the corresponding position.
[0046] Find the maximum matching score and its corresponding position in the similarity matrix D. The matching score is calculated as follows: Where D[c, r] represents the value of the similarity matrix at position [c, r], B is the normalized value, and score[c, r] represents the matching score calculated at [c, r], with a value between 0 and 1. The maximum matching score, best_score, and its corresponding position (best_r, best_c) are calculated. If the maximum score, best_score, is greater than the set score_threshold, the final matching position is calculated using the following formula: in,( , () represents the final matching position coordinates, T represents the current pyramid level, and offset represents the offset calculated as follows: .
[0047] To find a suitable center offset at different layers T, coarse matching at the high level of the pyramid and fine matching at the low level of the pyramid are used. Since the number of generated templates is relatively large, it would be time-consuming to perform matching directly at the original image size. Therefore, coarse matching is first performed in the low-resolution image. If the matching score is greater than the score_threshold, then fine matching is performed at the high-resolution level based on the rough position information obtained from the coarse matching to obtain the positioning information. If the score is less than the similarity threshold, the template matching is skipped.
[0048] S7. Calculate the coordinates of the contour matching center point based on the contour matching result.
[0049] Step S6 uses similarity calculation to find the location information of the contour match. , This calculates the coordinates of the top-left corner of the matched shape. In practice, it's often necessary to obtain the center point of the matched contour. Since the template size W is known... t H t The location of the matching center point is calculated as follows: , For relatively regular contour structures, this center point calculation method can usually find the accurate center point. However, for irregular contours, such as teardrop shapes, the calculated center point may shift when rotated by a certain angle, affecting the judgment based on center point positioning. Therefore, the original template offset calculation is added. Since the original contour template is rotated around the origin, the center point of all rotating template feature points is calculated. This represents the coordinates of the center point of the i-th template feature point. Then, the coordinates of the center point of the i-th template feature point are calculated. offset The final matching center point result is: , .in: The coordinates of the horizontal center point of the final matched contour in the image to be matched are given as the template of the i-th contour feature point. The coordinates of the vertical center point of the final matched contour in the image to be matched are obtained by using the template of the i-th contour feature point. When matching the i-th template with the image to be matched, the horizontal coordinate of the top left corner of the matching region. When matching the i-th template with the image to be matched, the vertical coordinate of the top left corner of the matching region The horizontal width of the template for the i-th contour feature point; Let be the horizontal height of the template for the i-th contour feature point; This represents the total horizontal offset compensation for the i-th template. This represents the total offset compensation amount of the i-th template in the vertical direction.
[0050] The matching results based on the physical contour template image are as follows: Figure 5 As shown, it can achieve accurate matching under different angles and scaling conditions.
[0051] This invention presents a contour template matching method based on physical contour data, solving the problem of image matching and localization in industrial scenarios that relies on raw physical contour data. This method achieves high-precision contour matching even in complex background environments. It generates multiple contour templates from an initial contour and employs a uniform downsampling strategy for feature points, effectively reducing the number of feature points while ensuring the integrity of feature information, thereby improving the computational efficiency of subsequent matching. The sliding window-based matching method ensures accurate contour template matching with a fast matching speed. Furthermore, to address the center point offset problem caused by irregular contour rotation, a center offset compensation method is used between the original template and the first template feature point, significantly improving the accuracy of matching different contours.
[0052] This invention is applicable to various industrial and scientific research fields and has broad application value. Specific application scenarios include, but are not limited to: The grafting module in a 3D printing system enables precise identification and positioning of the part's contour during the printing process, ensuring high-precision registration of the grafted components and improving printing quality and efficiency.
[0053] Physical contour-based parts finding and automatic sorting: On automated production lines, contour matching is used to quickly identify and locate different types of parts, enabling efficient automatic sorting and classification.
[0054] Industrial robot vision guidance: Provides robots with accurate visual positioning information to assist them in completing tasks such as assembly, welding, and handling, thereby improving automation levels and operational accuracy.
[0055] Quality inspection and defect identification: By matching the product contour in real time, deformation, defects or deviations generated during the manufacturing process are detected to ensure product quality.
[0056] In summary, this invention, with its efficient and accurate contour matching capabilities, can meet the needs of multiple fields for image matching and localization, and promote the intelligent and automated development of related industries.
[0057] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for contour matching of complex background images based on physical contour feature point templates, characterized in that, Includes the following steps: Based on the image pixel equivalent, the physical contour data is converted into contour image coordinate data; Generate a contour feature point template image based on the contour image coordinate data; Gradient information is extracted and calculated from the contour feature point template image, and contour feature points are extracted. Candidate point set is obtained by screening the contour feature points based on nonmaximum suppression, and uniform sampling is performed on the candidate point set based on grid statistics method; Based on the preset contour feature point template parameters, the uniformly sampled candidate point set is rotated or scaled to generate multiple contour feature point templates with different angles and scales. Based on the contour feature point template and the image to be matched, multi-template traversal matching is performed to obtain the contour matching result; Based on the contour matching results, calculate the coordinates of the contour matching center point.
2. The method for contour matching of complex background images based on physical contour feature point templates according to claim 1, characterized in that, Generate a contour feature point template image based on the contour image coordinate data, specifically as follows: Based on the maximum and minimum coordinate values of the contour image coordinate data, calculate the contour cropping size and the contour center point, and perform boundary augmentation on the contour image cropped according to the cropping size; Align the center of the contour with the center of the amplified contour image, and fill the contour according to the aligned contour coordinates to generate a contour feature point template image.
3. The method for contour matching of complex background images based on physical contour feature point templates according to claim 1, characterized in that, Gradient information is extracted and calculated from the contour feature point template image, and contour feature points are extracted, specifically as follows: Image pyramid models of different levels are created, and gradient information is extracted from the contour feature point template image based on the Scharr filter at different pyramid levels. The extracted gradient information includes the horizontal gradient and the vertical gradient. Calculate the gradient magnitude and gradient direction angle of each pixel based on the horizontal and vertical gradients. Non-maximum suppression is performed based on the gradient magnitude, and a gradient direction angle threshold is set. Neighborhood consistency is judged for the current pixel: if the number of pixels with the same gradient direction in the neighborhood of the current pixel exceeds a preset number, the current pixel is retained as a contour feature point.
4. The method for contour matching of complex background images based on physical contour feature point templates according to claim 1, characterized in that, The process of filtering the contour feature points based on nonmaximum suppression to obtain a candidate point set is as follows: The gradient magnitude map corresponding to the contour feature point template image is dilated using a rectangular structuring element of a preset size to obtain the dilated gradient magnitude map. Compare the values of corresponding contour feature points in the gradient magnitude map of the original image and the dilated gradient magnitude map. If they are equal, the corresponding contour feature point is determined to be a local maximum in the neighborhood. Simultaneously, determine whether the gradient direction angle of the corresponding contour feature point is greater than zero. If both the local maximum condition and the gradient direction angle being greater than zero are satisfied, then add the corresponding contour feature point to the candidate point set.
5. The method for contour matching of complex background images based on physical contour feature point templates according to claim 4, characterized in that, The uniform sampling of the candidate point set based on the grid statistical method is specifically as follows: The expanded gradient magnitude map is divided into row and column grids, with a fixed number of horizontal grids and a dynamically adjusted number of vertical grids based on the size of the gradient magnitude map. Calculate the index of each candidate point in the candidate point set in the row and column grid, and count the number of candidate points in each grid to form a density matrix; The density matrix is normalized to its maximum value to obtain the normalized density value for each grid cell. The basic distance threshold is calculated based on the expected number of feature points and the total number of candidate points. The adaptive distance threshold for each grid cell is then calculated by combining the normalized density value and the preset density influence coefficient. Candidate points are sorted from largest to smallest according to their gradient magnitude, and it is determined in turn whether the distance between each candidate point and all points in the selected point set is greater than the adaptive distance threshold corresponding to the grid. If so, the corresponding candidate point is added to the selected point set. This process continues until the number of selected points reaches the desired number of feature points or all candidate points have been traversed, thus completing uniform sampling.
6. The method for contour matching of complex background images based on physical contour feature point templates according to claim 1, characterized in that, The process of rotating or scaling the uniformly sampled candidate point set to generate multiple contour feature point templates with different angles and scales is as follows: Calculate the center point of the uniformly sampled contour feature point set; Each point in the contour feature point set is translated to a coordinate system with the center point as the origin to obtain the translated feature point set. According to the preset contour feature point template parameters, the points in the translated feature point set are scaled and rotated in sequence to generate multiple new feature point sets, where each set of transformations corresponds to a specific rotation angle and scaling factor; the preset contour feature point template parameters include starting angle, ending angle, angle step, starting scaling factor, ending scaling factor, and scaling factor step. Each new set of feature points is saved as an independent contour feature point template, forming a multi-angle, multi-scale contour feature point template set.
7. The method for contour matching of complex background images based on physical contour feature point templates according to claim 6, characterized in that, Based on the contour feature point template and the image to be matched, multi-template traversal matching is performed to obtain the contour matching result, specifically: For the matching image, gradient magnitude maps at different levels are generated according to the pyramid hierarchy; Traverse the set of contour feature point templates with multiple angles and scales. For each template, transform the template feature points to a coordinate system with the upper left corner of the template as the origin according to the template size. The sliding window method is used to slide the contour feature point template on the image to be matched to find similar regions, calculate similarity scores, output and update the similarity matrix; The maximum matching score and its position are found in the similarity matrix. If the maximum score exceeds a preset score threshold, the final matching position is calculated to obtain the contour matching result.
8. The method for contour matching of complex background images based on physical contour feature point templates according to claim 7, characterized in that, The sliding window method involves sliding a contour feature point template across the image to be matched to find similar regions, calculate similarity scores, output and update the similarity matrix, where the template sliding range is span_x = WW. t span_y=HH t W t H t Let W be the template size, and H be the gradient magnitude map sizes corresponding to the matched image; define the output similarity matrix as D, then the similarity matrix update formula is: Where D[j] represents the value at position j in the similarity matrix D, L Pi [j] represents template feature point P i The value of j at the corresponding position.
9. The method for contour matching of complex background images based on physical contour feature point templates according to claim 8, characterized in that, The maximum matching score and its position are found in the similarity matrix. If the maximum score exceeds a preset score threshold, the final matching position is calculated to obtain the matching result, specifically: Find the maximum matching score and its corresponding position in the similarity matrix D. The matching score is calculated as follows: Where D[c, r] represents the value of the similarity matrix at position [c, r], B is the normalized value, and score[c, r] represents the matching score calculated at [c, r], with a value between 0 and 1; Calculate the maximum score (best_score) and its corresponding position (best_r, best_c) in the matching scores. If the maximum score (best_score) is greater than the set score threshold (score_threshold), then perform the final matching position calculation using the following formula: in,( , () represents the final matching position coordinates, T represents the current pyramid level, and offset represents the offset calculated as follows: .
10. The method for contour matching of complex background images based on physical contour feature point templates according to claim 9, characterized in that, Based on the contour matching results, the coordinates of the contour matching center point are calculated as follows: The location information of the contour matching is obtained through similarity calculation. , Based on the template dimensions Wt and Ht, calculate the initial coordinates of the matching center point: , ; Calculate the center point of all rotating contour feature point template feature points. The center point coordinates of the first contour feature point template feature point offset ; The offset The coordinates of the center point of the initial matching point are compensated to obtain the final corrected coordinates of the center point of the matching contour, specifically as follows: The coordinates of the horizontal center point of the final matched contour in the image to be matched are given as the template of the i-th contour feature point. The coordinates of the vertical center point of the final matched contour in the image to be matched are obtained by using the template of the i-th contour feature point. When matching the i-th template with the image to be matched, the horizontal coordinate of the top left corner of the matching region. When matching the i-th template with the image to be matched, the vertical coordinate of the top left corner of the matching region The horizontal width of the template for the i-th contour feature point; Let be the horizontal height of the template for the i-th contour feature point; This represents the total offset compensation amount of the i-th template in the horizontal direction; This represents the total offset compensation amount of the i-th template in the vertical direction.