A template matching method based on edge features

Through the template matching method based on edge features, the efficiency and accuracy problems of traditional template matching in processing images with rotation or size changes are solved, and high-precision and efficient visual positioning is achieved, which is suitable for the field of automation.

CN114119644BActive Publication Date: 2024-09-13JUNENG FUTURE SOFTWARE DEVELOPMENT (XIAN) CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202111516108.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-06
Publication Date
2024-09-13
Estimated Expiration
2041-12-06

AI Technical Summary

Technical Problem

Traditional template matching methods cannot effectively handle the rotation or size changes of targets in images, resulting in low positioning accuracy and efficiency.

Method used

The template matching method based on edge features is used to extract the edge features of the part through the Sobel operator, and a rough template and a fine template are produced. The calibration parameter matrix is ​​used to match the rotation angle and coordinates, and the LabVIEW development platform is used to compile the human-computer interaction software.

Benefits of technology

It achieves high-precision, strong anti-interference ability and universal template matching, can calculate image coordinates and rotation angles, meets the visual positioning needs in the automation field, and has a high success rate and calculation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114119644B
    Figure CN114119644B
Patent Text Reader

Abstract

The present invention provides a template matching method based on edge features. In the process of making a template, the edge features of the parts are extracted by an edge extraction algorithm. In the matching process, the edge features of the entire image are highlighted by the edge extraction algorithm. The original template is compared pixel by pixel and angle by angle using a template optimization algorithm to find the most suitable matching point and angle, and then the position is multiplied by a calibration parameter matrix to obtain the coordinates in the robot coordinate system. The visual measurement system built by self-processing and procurement in this method is relatively cheap and has the advantages of non-contact, high speed, and high precision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computing technology, and in particular to a template matching method based on edge features. Background Art

[0002] Template matching is a common method for 2D visual positioning. It is a process of finding approximate module matches in the search image based on known modules. It is a simple, effective and widely used image processing method.

[0003] Traditional template matching has its own limitations, mainly in that it can only move in parallel. If the matching target in the original image rotates or changes in size, the algorithm will be invalid. Famous domestic and foreign software packages such as Cognex's Patmax, Matron's MILGMF, MVtec's HALCON HMatchlt, EURESYS's eVisonasyFind, Adept's AdeptSight and DALSA's Sapera have developed geometric template matching algorithms with good performance, but due to commercial confidentiality, the core technologies used are rarely disclosed. Summary of the invention

[0004] The present invention is to solve the problem of template matching and provide a template matching method based on edge features: in the process of making templates, the edge features of parts are extracted by edge extraction algorithm, and in the matching process, the edge features of the whole image are highlighted by edge extraction algorithm, and the original template is compared pixel by pixel and angle by angle using template optimization algorithm to find the most suitable matching point and angle, and then the position is multiplied by calibration parameter matrix to obtain the coordinates in robot coordinate system. The visual measurement system built by self-processing and procurement is relatively cheap and has the advantages of non-contact, fast speed and high precision.

[0005] The present invention provides a template matching method based on edge features, comprising the following steps:

[0006] S1. Extract template: Use edge feature algorithm to process photos that highlight part features, determine feature areas, and then manually mask unnecessary edge features to obtain a preliminary template;

[0007] S2, training template: use template optimization algorithm to extract representative feature points in the preliminary template, and make it into coarse template and fine template, and obtain edge features and array index through training;

[0008] S3, image preprocessing: use edge feature algorithm to process the image to be tested, obtain an image with edge features, and reduce the resolution of the image with edge features to obtain a coarse image;

[0009] S4, coarse positioning: match the coarse template with the coarse image point by point to obtain the score value of each pixel position, and the position with the highest score is the position obtained by coarse positioning;

[0010] S5. Fine positioning: According to the position obtained by coarse positioning, the fine template is matched with the coarse image to obtain the score of each pixel position in the fine template area. The position with the highest score is the position obtained by fine positioning. The position obtained by fine positioning is then multiplied by the calibration parameter matrix to obtain the coordinates of the image to be measured in the robot coordinates.

[0011] The template matching method based on edge features described in the present invention is preferably used in steps S1 and S3 to extract the edge features of the photo using the Sobel operator, where the Sobel operator is:

[0012] Gx=[f(x+1,y-1)+2*f(x+1,y)+f(x+1,y+1)]-[f(x-1,y-1)+2*f(x-1,y)+f(x-1,y+1)];

[0013] Gy=[f(x-1,y-1)+2*f(x,y-1)+f(x+1,y-1)]-[f(x-1,y+1)+2*f(x,y+1)+f(x+1,y+1)];

[0014]

[0015] Among them, f(x, y) is the grayscale value of the image point (x, y), Gx is the image grayscale value of horizontal edge detection, Gy is the image grayscale value of vertical edge detection, and G is the comprehensive image grayscale value of edge detection.

[0016] The template matching method based on edge features described in the present invention, as a preferred embodiment, step S1 comprises the following steps:

[0017] S11. Load photos with better part features;

[0018] S12, using the Sobel operator of the edge feature algorithm to extract the ROI area of ​​the edge feature of the photo;

[0019] S13. Manually mask unnecessary edge features and set the grayscale value to 0 to obtain a preliminary template.

[0020] The template matching method based on edge features described in the present invention, as a preferred embodiment, step S2 comprises the following steps:

[0021] S21, use Sobel operator to process the grayscale image in the ROI area, and the grayscale value is proportional to the change gradient;

[0022] S22, binarizing the grayscale image with a threshold value, filtering out pixels with small gradient changes;

[0023] S23, simplifying the pixel points with a mask, extracting representative feature points using a template optimization algorithm, and making a coarse template and a fine template;

[0024] S24. Save the feature points in a text file in the form of a two-dimensional array to obtain edge features and array indexes.

[0025] The template matching method based on edge features described in the present invention is preferably implemented in step S2, wherein the template optimization algorithm includes the following contents:

[0026] For every k rows and columns of the binary image array with a resolution of M*N, extract an array A with k rows and columns. i , we get M / k*N / k k*k arrays. When they cannot be divided evenly, the remainder is cut off according to M%k or N%k.

[0027] Extract array A i The index value of the pixel in the middle is 1, and it is sorted according to the size of the row, and the median index is extracted;

[0028] Set the index median as the feature point, put it back into the image, and continue to extract the index median of other arrays until the index value extraction of all arrays is completed.

[0029] The template matching method based on edge features described in the present invention is preferably a method in which the coarse template, the fine template and the coarse image are matched by:

[0030] Assume that after the coarse template or fine template is rotated by angle θ, the width*height of the coarse template or fine template = n*m, and the matrix of the coarse template or fine template is:

[0031]

[0032] When the template matrix starts at the source matrix (X i , Y j ) point, the extracted matrix to be compared

[0033] In the A1 matrix, the feature point is 1, and the others are 0. In the B1 matrix, when the pixel value is 255, the corresponding matrix value is 1, otherwise it is 0.

[0034] Construct a new matrix C1, which is an n*m matrix. Each value in the matrix is ​​the value in the A1 matrix and the B1 matrix, and obtain the score value of each pixel position.

[0035] The template matching method based on edge features described in the present invention is, as a preferred method, the software for verifying the matching effect includes the following functions: image loading function, parameter adjustment function, ROI area adding function, result display function and fast image loading function.

[0036] The template matching method based on edge features described in the present invention is, as a preferred method, a parameter adjustment function for adjusting any one of the following parameters: photographing environment, part characteristics, binarization threshold after Sobel operator, score threshold and expansion multiple.

[0037] The template matching method based on edge features described in the present invention is, as a preferred embodiment, a result display function for displaying the rough matching, the fine matching and the total time used for matching; the result display function for displaying the search coordinates, the coordinates including the horizontal coordinate, the vertical coordinate and the rotation angle.

[0038] The edge feature-based template matching method described in the present invention is, as a preferred embodiment, a fast picture loading function is used to load a picture and trigger a template matching function at the same time to find the position of the feature in the image.

[0039] The present invention uses LabVIEW as a development platform, studies a template matching method based on edge features, and compiles template making algorithms, matching algorithms, scoring algorithms, etc. Finally, by comparing the Patmax algorithm of Congex, it is concluded that the algorithm can meet the requirements of the automation field in visual positioning, not only locates plane coordinates, but also calculates the rotation angle of parts, and has the characteristics of high success rate, high precision, and strong versatility.

[0040] The specific plan is:

[0041] Extract template: Process the photos with better part features with the Sobel operator to determine the feature area and manually mask unnecessary edge features;

[0042] Training template: Since there are many feature points in the template, which will affect the subsequent calculation speed, the template optimization algorithm is used to extract "representative" feature points, and two templates are made at the same time, a coarse template for global search and a fine template for fine search;

[0043] Image preprocessing: Use the Sobel operator to process the image to be tested to obtain an image with edge features; at the same time, reduce the resolution of the image to obtain a coarse image for subsequent coarse matching.

[0044] Coarse positioning: Match the coarse template with the coarse image point by point to obtain the score value of each pixel position. The position with the highest score is the position obtained by coarse positioning.

[0045] Fine positioning: According to the position obtained by coarse positioning, the fine template is matched with the preprocessed image in a certain area to obtain the score of each pixel position in the area. The position with the highest score is the position obtained by fine positioning.

[0046] First of all, the program must be human-computer interactive, so according to the operation classification, it will be divided into two demos: template making demo and matching verification demo.

[0047] Demo is used to make a template, mask the non-edge positions of the standard image, extract edge feature points, and record these points in text format for subsequent calculations.

[0048] The process of making a template is divided into the following steps:

[0049] 1. Load a standard picture to make a template.

[0050] 2. Extract the ROI area of ​​the edge feature and shield other interference (the grayscale value of other areas is set to 0).

[0051] The Sobel operator is used to process the grayscale image in the ROI area, and the grayscale value is proportional to the gradient change.

[0052] 3. Binarize the image with a certain threshold and filter out pixels with small gradient changes.

[0053] 4. Simplify the pixels with a certain mask size, that is, extract "representative" pixels and reduce the number of feature points to improve the calculation speed during template matching.

[0054] 5. Save these points in a text file in the form of a two-dimensional array to complete the template training.

[0055] The matching verification demo is used to verify the matching effect, which can be divided into the following functions:

[0056] Load picture function. Click "Select Folder" in the interface and select the base path of the material picture to load the picture into the one-dimensional array storing the picture and display it directly below.

[0057] Parameter adjustment function. Adjust according to the shooting environment and part characteristics, such as the rotation angle range of the part. If the angle search range is reduced, the accuracy and search speed can be improved; the binarization threshold after the Sobel operator can be adjusted to improve the recognition success rate; the score threshold can be adjusted to filter out the search results that do not meet the score range; the expansion multiple can be adjusted to enlarge the original image.

[0058] In this way, the search can be indexed to the position where the row and column are less than 0, which means that the part can be found even if it runs out of part of the image.

[0059] Add ROI region function. Add a rectangular region of interest and crop the image before loading it, keeping only the image within the ROI region.

[0060] Result display function: The rough match, fine match and total time used for matching can be displayed above the image; the search coordinates (X, Y, θ) can be displayed in the image.

[0061] Quick image loading function. Sort the images in the folder by name, click the previous or next image to load the image, and trigger the template matching function to find the location of the feature in the image.

[0062] 0.1 Algorithm Library

[0063] Sobel operator

[0064] The Sobel operator can extract edge features (see Figure 4 for a before and after comparison), namely:

[0065] Gx=[f(x+1,y-1)+2*f(x+1,y)+f(x+1,y+1)]-[f(x-1,y-1)+2*f(x-1,y)+f(x-1,y+1)];

[0066] Gy=[f(x-1,y-1)+2*f(x,y-1)+f(x+1,y-1)]-[f(x-1,y+1)+2*f(x,y+1)+f(x+1,y+1)];

[0067]

[0068] Where:

[0069] f(x, y) — the gray value of the image point (x, y);

[0070] Gx—image grayscale value for horizontal edge detection;

[0071] Gy—image gray value for longitudinal edge detection;

[0072] G—The comprehensive image gray value of edge detection.

[0073] “Representative” feature point extraction

[0074] Too many feature points not only do not help improve the accuracy, but also increase the amount of calculation and reduce the efficiency of operation. Therefore, the following method is proposed to extract more "representative" feature points:

[0075] 1. For the binary image array with a resolution of M*N, extract an array A with k rows and k columns for every k rows and k columns. i, this will result in M / k*N / k k*k arrays. When it cannot be divided evenly, the remaining part is intercepted according to M%k or N%k;

[0076] 2. A i The index value of the pixel with a value of 1 is extracted, and the values ​​are sorted according to the size of the row to extract the median value of the index;

[0077] 3. Consider the median as a "representative" point and put it back into the new image, and so on.

[0078] All A i Array processing, there are 1781 pixels before extraction and only 136 after extraction.

[0079] Template Matching

[0080] The matching operation between the template image and the current image is divided into the following steps:

[0081] 1 Suppose that after the template is rotated by angle θ, the width*height of template A1=n*m, and the matrix of A1 is

[0082]

[0083] 2 When the template matrix starting point is at the source matrix (X i , Y j ) point, the extracted matrix to be compared

[0084] In the 3A1 matrix, the feature point is 1, and the others are 0. In the B1 matrix, if the pixel value is 255, the corresponding matrix value is 1, otherwise it is 0.

[0085] Construct a new matrix C1, which is an n*m matrix. Each value in the matrix is ​​the value in the A1 matrix and the B1 matrix. Count the number of 1s in the C1 matrix and divide it by the number of 1s in the A1 matrix to get the recognition rate.

[0086] The present invention has the following advantages:

[0087] (1) The present invention proposes a template matching method based on edge features. Compared with the traditional algorithm, this algorithm can not only calculate the image coordinates, but also calculate the angle, and has the characteristics of high precision, strong anti-interference ability and strong versatility.

[0088] (2) At the same time, based on the angular algorithm, the present invention uses Lab VIEW as the development platform to compile human-computer interaction software and verify the feasibility of the algorithm.

[0089] (3) The present invention experimentally compares the calculation results of the authoritative algorithm Congex's Patmax with the algorithm, and draws the conclusion that the average error in the Y direction is 2.64 (pixels), the average error in the Y direction is 2.83 (pixels), and the angle error is 0.234 (degrees), which meets the normal error of 3-5 pixel differences. BRIEF DESCRIPTION OF THE DRAWINGS

[0090] Figure 1 It is a flow chart of a template matching method based on edge features;

[0091] Figure 2 A schematic diagram of shielding external interference by a template matching method based on edge features;

[0092] Figure 3a A schematic diagram of edge features extracted by a template matching method based on edge features;

[0093] Figure 3b It is an array index of each pixel point in a template matching method based on edge features;

[0094] Figure 4a This is a schematic diagram of an edge feature-based template matching method before image preprocessing;

[0095] Figure 4b It is a schematic diagram of image preprocessing of a template matching method based on edge features;

[0096] Figure 5 A schematic diagram of rough positioning of a template matching method based on edge features;

[0097] Figure 6a A schematic diagram of the template matching method based on edge features for accurate positioning.

[0098] Figure 6b A schematic diagram of a template matching method based on edge features after precise positioning;

[0099] Figure 7 A schematic diagram of a template training demo for a template matching method based on edge features;

[0100] Figure 8 This is a demo for verifying the template matching method based on edge features.

[0101] Fig. 9 A flow chart of representative feature point extraction for a template matching method based on edge features;

[0102] Fig.10 Schematic diagram of template matching based on edge features. DETAILED DESCRIPTION

[0103] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.

[0104] Example 1

[0105] like Figure 1 As shown, a template matching method based on edge features includes the following steps:

[0106] S1. Extract template: Use edge feature algorithm to process photos that highlight part features, determine feature areas, and then manually mask unnecessary edge features to obtain a preliminary template;

[0107] Step S1 includes the following steps:

[0108] S11. Load photos with better part features;

[0109] S12, using the Sobel operator of the edge feature algorithm to extract the ROI area of ​​the edge feature of the photo;

[0110] S13, manually shielding unnecessary edge features, setting the gray value to 0, and obtaining a preliminary template;

[0111] S2, training template: use template optimization algorithm to extract representative feature points in the preliminary template, and make it into coarse template and fine template, and obtain edge features and array index through training;

[0112] Step S2 includes the following steps:

[0113] S21, use Sobel operator to process the grayscale image in the ROI area, and the grayscale value is proportional to the change gradient;

[0114] S22, binarizing the grayscale image with a threshold value, filtering out pixels with small gradient changes;

[0115] S23, simplifying the pixel points with a mask, extracting representative feature points using a template optimization algorithm, and making a coarse template and a fine template;

[0116] S24, saving the feature points in a text file in the form of a two-dimensional array, and obtaining edge features and array indexes;

[0117] S3, image preprocessing: use edge feature algorithm to process the image to be tested, obtain an image with edge features, and reduce the resolution of the image with edge features to obtain a coarse image;

[0118] S4, coarse positioning: match the coarse template with the coarse image point by point to obtain the score value of each pixel position, and the position with the highest score is the position obtained by coarse positioning;

[0119] S5, fine positioning: according to the position obtained by coarse positioning, the fine template is matched with the coarse image to obtain the score of each pixel position in the fine template area. The position with the highest score is the position obtained by fine positioning. Then, the position obtained by fine positioning is multiplied by the calibration parameter matrix to obtain the coordinates of the image to be measured in the robot coordinates;

[0120] In steps S1 and S3, the edge feature algorithm uses the Sobel operator to extract the edge features of the photo. The Sobel operator is:

[0121] Gx=[f(x+1,y-1)+2*f(x+1,y)+f(x+1,y+1)]-[f(x-1,y-1)+2*f(x-1,y)+f(x-1,y+1)];

[0122] Gy=[f(x-1,y-1)+2*f(x,y-1)+f(x+1,y-1)]-[f(x-1,y+1)+2*f(x,y+1)+f(x+1,y+1)];

[0123]

[0124] Wherein, f(x, y) is the gray value of the image point (x, y), Gx is the image gray value of the horizontal edge detection, Gy is the image gray value of the vertical edge detection, and G is the comprehensive image gray value of the edge detection;

[0125] In step S2, the template optimization algorithm includes the following contents:

[0126] For every k rows and columns of the binary image array with a resolution of M*N, extract an array A with k rows and columns. i , we get M / k*N / k k*k arrays. When they cannot be divided evenly, the remainder is cut off according to M%k or N%k.

[0127] Extract array A i The index value of the pixel in the middle is 1, and it is sorted according to the size of the row, and the median index is extracted;

[0128] Set the index median as the feature point, put it back into the image, and continue to extract the index median of other arrays until the index value extraction of all arrays is completed;

[0129] In step S4 and step S5, the method of matching the coarse template, the fine template and the coarse image is:

[0130] Assume that after the coarse template or fine template is rotated by angle θ, the width*height of the coarse template or fine template = n*m, and the matrix of the coarse template or fine template is:

[0131]

[0132] When the template matrix starts at the source matrix (X i , Y j ) point, the extracted matrix to be compared

[0133] In the A1 matrix, the feature point is 1, and the others are 0. In the B1 matrix, when the pixel value is 255, the corresponding matrix value is 1, otherwise it is 0.

[0134] Construct a new matrix C1, which is an n*m matrix. Each value in the matrix is ​​the value in the A1 matrix and the B1 matrix, and obtain the score value of each pixel position;

[0135] The software for verifying the matching effect includes the following functions: loading pictures, adjusting parameters, adding ROI areas, displaying results and quickly loading pictures;

[0136] The parameter adjustment function is used to adjust any of the following parameters: shooting environment, part characteristics, binarization threshold after Sobel operator, score threshold and expansion multiple;

[0137] The result display function is used to display the rough matching, fine matching and the total time used for matching; the result display function is used to display the search coordinates, which include the horizontal coordinate, the vertical coordinate and the rotation angle;

[0138] The quick image loading function is used to load an image and trigger the template matching function at the same time to find the location of the feature in the image.

[0139] Example 2

[0140] like Figure 1 As shown in FIG, a template matching method based on edge features includes the following steps: extracting the template: processing the photo with better part features through the Sobel operator, determining the feature area, and manually shielding the unnecessary edge features, such as Figure 2 As shown:

[0141] Training template: Since there are many feature points in the template, which will affect the subsequent calculation speed, the "representative" feature points are extracted through the template optimization algorithm, and two templates are made at the same time, a coarse template for global search and a fine template for fine search. After training, the array shown in Figure 3 can be obtained. Figure 3a is the extracted edge feature, Figure 3b Array index for each pixel (saved in a text document):

[0142] As shown in FIG4 , image preprocessing: the image to be tested is processed using the Sobel operator to obtain an image with edge features; at the same time, the image resolution is reduced to obtain a coarse image for subsequent coarse matching.

[0143] like Figure 5 As shown, coarse positioning: the coarse template is matched with the coarse image point by point to obtain the score value of each pixel position, and the position with the highest score is the position obtained by coarse positioning.

[0144] Fine positioning: According to the position obtained by coarse positioning, the fine template is matched with the preprocessed image in a certain area to obtain the score of each pixel position in the area. The position with the highest score is the position obtained by fine positioning, as shown in Figure 6. Figure 6a The original image is shown. Figure 6b The image shown is obtained after being processed by the Sobel operator and binarized, and then through precise matching.

[0145] First of all, the program must be human-computer interactive, so according to the operation classification, it will be divided into two demos: template making demo and matching verification demo.

[0146] Demo is used to make a template, mask the non-edge positions of the standard image, extract edge feature points, and record these points in text format for subsequent calculations.

[0147] The process of making a template is divided into the following steps:

[0148] Load a standard image to create a template.

[0149] Extract the ROI area of ​​the edge feature and shield other interference (the gray value of other areas is set to 0).

[0150] The Sobel operator is used to process the grayscale image in the ROI area, and the grayscale value is proportional to the gradient change.

[0151] The image is binarized with a certain threshold value to filter out pixels with small gradient changes.

[0152] The pixels are simplified with a certain mask size, that is, "representative" pixels are extracted to reduce the number of feature points in order to improve the calculation speed during template matching.

[0153] Save these points in a text file in the form of a two-dimensional array to complete the template training.

[0154] Template training demo is as follows Figure 7 As shown:

[0155] The matching verification demo is used to verify the matching effect, which can be divided into the following functions:

[0156] Load picture function. Click "Select Folder" in the interface and select the base path of the material picture to load the picture into the one-dimensional array storing the picture and display it directly below.

[0157] Parameter adjustment function. Adjust according to the shooting environment and part characteristics, such as the rotation angle range of the part. If the angle search range is reduced, the accuracy and search speed can be improved; the binarization threshold after the Sobel operator can be adjusted to improve the recognition success rate; the score threshold can be adjusted to filter out the search results that do not meet the score range; the expansion multiple can be adjusted to enlarge the original image.

[0158] In this way, the search can be indexed to the position where the row and column are less than 0, which means that the part can be found even if it runs out of part of the image.

[0159] Add ROI region function. Add a rectangular region of interest and crop the image before loading it, keeping only the image within the ROI region.

[0160] Result display function: The rough match, fine match and total time used for matching can be displayed above the image; the search coordinates (X, Y, θ) can be displayed in the image.

[0161] Quick image loading function. Sort the images in the folder by name, click the previous or next image to load the image, and trigger the template matching function to find the location of the feature in the image.

[0162] Matching verification Demo Figure 8 As shown:

[0163] Sobel operator

[0164] Sobel operator can extract edge features (see before and after comparison Figure 5 ),Right now:

[0165] Gx=[f(x+1,y-1)+2*f(x+1,y)+f(x+1,y+1)]-[f(x-1,y-1)+2*f(x-1,y)+f(x-1,y+1)];

[0166] Gy=[f(x-1,y-1)+2*f(x,y-1)+f(x+1,y-1)]-[f(x-1,y+1)+2*f(x,y+1)+f(x+1,y+1)];

[0167]

[0168] Where:

[0169] f(x, y) — the gray value of the image point (x, y);

[0170] Gx—image grayscale value for horizontal edge detection;

[0171] Gy—image gray value for longitudinal edge detection;

[0172] G—The comprehensive image gray value of edge detection.

[0173] “Representative” feature point extraction

[0174] Too many feature points not only do not help improve the accuracy, but also increase the amount of calculation and reduce the efficiency of operation. Therefore, the following method is proposed to extract more "representative" feature points:

[0175] For every k rows and columns of the binary image array with a resolution of M*N, extract an array A with k rows and columns. i , this will result in M / k*N / k k*k arrays. When it cannot be divided evenly, the remaining part is intercepted according to M%k or N%k;

[0176] A i The index value of the pixel with a value of 1 is extracted, and the values ​​are sorted according to the size of the row to extract the median value of the index;

[0177] This median is considered a "representative" point and is put back into the new image, and so on.

[0178] All A i Array processing will give Fig. 9 In the result, there are 1781 pixels before extraction and only 136 pixels after extraction.

[0179] Template Matching

[0180] like Fig.10 As shown, the matching operation between the template image and the current image is divided into the following steps:

[0181] Assume that after the template is rotated by angle θ, the width*height of template A1=n*m, and the matrix of A1 is

[0182] When the template matrix starts at the source matrix (X i , Y j ) point, the extracted matrix to be compared

[0183] In the A1 matrix, the feature point is 1, and the others are 0. In the B1 matrix, if the pixel value is 255, the corresponding matrix value is 1, otherwise it is 0.

[0184] Construct a new matrix C1. The C1 matrix is ​​an n*m matrix. Each value in the matrix is ​​the value in the A1 matrix and the B1 matrix. Count the number of 1s in the C1 matrix and divide it by the number of 1s in the A1 matrix to get the recognition rate.

[0185] Using 34 pictures saved in actual projects as materials, Congex's PatMax algorithm is used to search for parts in the pictures. At the same time, the current edge search algorithm is used to search for parts in the pictures, and the search results of the two are compared with the calculation results of the template matching algorithm based on edge features.

[0186] As shown in the table below, Congex's Patmax algorithm is used to search for materials and match templates based on edge features. A 1.3-megapixel camera is used for testing. It can be concluded that the average error in the X direction is 2.64 (pixels), the average error in the Y direction is 2.83 (pixels), and the angle error is 0.234 (degrees). When converted to a 100mm*100mm field of view, the accuracy is 0.258mm / dm^2 in the X direction and 0.221mm / dm^2 in the Y direction.

[0187] Physical location

[0188]

[0189] Recognition results of matching algorithm based on edge features

[0190]

[0191] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.

Claims

1. A template matching method based on edge features, characterized in that: The following steps are involved: S1. Extract template: Use edge feature algorithm to process photos that highlight part features, determine feature areas, and then manually mask unnecessary edge features to obtain a preliminary template; S2, training template: using the template optimization algorithm to extract representative feature points in the preliminary template, and making a coarse template and a fine template, and obtaining edge features and array indexes through training; The template optimization algorithm includes the following: For every k rows and columns of the binary image array with a resolution of M*N, extract an array A with k rows and columns. i , we get M / k*N / k k*k arrays. When they cannot be divided evenly, the remainder is cut off according to M%k or N%k. Extract array A i The index value of the pixel in the middle is 1, and sort it according to the size of the row, and extract the median index; The median value of the index is set as the feature point, and is put back into the image, and the median value extraction of the index of other arrays is continued until the index value extraction of all arrays is completed; S3, image preprocessing: using an edge feature algorithm to process the image to be measured, obtaining an image with edge features, and reducing the resolution of the image with edge features to obtain a coarse image; S4, coarse positioning: matching the coarse template with the coarse image point by point to obtain a score value for each pixel position, and the position with the highest score is the position obtained by coarse positioning; S5, fine positioning: according to the position obtained by the coarse positioning, the fine template is matched with the coarse image to obtain the score of each pixel position in the fine template area, the position with the highest score is the position obtained by the fine positioning, and then the position obtained by the fine positioning is multiplied by the calibration parameter matrix to obtain the coordinates of the image to be measured in the robot coordinates; The method for matching the coarse template, the fine template and the coarse image is: Assume that after the rough template or the fine template is rotated by an angle of θ, the width*height of the rough template or the fine template=n*m, and the matrix of the rough template or the fine template is: When the template matrix starts at the source matrix (X i ,Y j ) point, the extracted matrix to be compared In the A1 matrix, the feature point is 1, and the others are 0. In the B1 matrix, when the pixel value is 255, the corresponding matrix value is 1, otherwise it is 0. Construct a new matrix C1, which is an n*m matrix. Each value in the matrix is ​​the value in the A1 matrix and the B1 matrix, and obtain the score value of each pixel position.

2. The template matching method based on edge features according to claim 1, characterized in that: In steps S1 and S3, the edge feature algorithm uses the Sobel operator to extract the edge features of the photo. The Sobel operator is: Gx=[f(x+1,y-1)+2*f(x+1,y)+f(x+1,y+1)]-[f(x-1,y-1) +2*f(x-1,y)+f(x-1,y+1)]; Gy=[f(x-1,y-1)+2*f(x,y-1)+f(x+1,y-1)]-[f(x-1,y+1) +2*f(x,y+1)+f(x+1,y+1)]; Among them, f(x, y) is the grayscale value of the image point (x, y), Gx is the image grayscale value of horizontal edge detection, Gy is the image grayscale value of vertical edge detection, and G is the comprehensive image grayscale value of edge detection.

3. The template matching method based on edge features according to claim 1, characterized in that: Step S1 includes the following steps: S11. Load photos with better part features; S12, using the Sobel operator of the edge feature algorithm to extract the ROI area of ​​the edge feature of the photo; S13, manually shielding unnecessary edge features, setting the gray value to 0, and obtaining the preliminary template.

4. The template matching method based on edge features according to claim 1, characterized in that: Step S2 includes the following steps: S21, use Sobel operator to process the grayscale image in the ROI area, and the grayscale value is proportional to the change gradient; S22, binarizing the grayscale image with a threshold value, filtering out pixels with small gradient changes; S23, simplifying the pixel points with a mask, extracting the representative feature points using a template optimization algorithm, and making the rough template and the fine template; S24. Save the feature points in a text file in the form of a two-dimensional array to obtain the edge features and the array index.

5. The template matching method based on edge features according to claim 1, characterized in that: The software for verifying the matching effect includes the following functions: image loading function, parameter adjustment function, ROI area adding function, result display function and quick image loading function.

6. The template matching method based on edge features according to claim 5, characterized in that: The parameter adjustment function is used to adjust any of the following parameters: photographing environment, part characteristics, binarization threshold after Sobel operator, score threshold and expansion multiple.

7. The template matching method based on edge features according to claim 5, characterized in that: The result display function is used to display the rough match, the fine match and the total time used for the match; the result display function is used to display the search coordinates, and the coordinates include the horizontal coordinate, the vertical coordinate and the rotation angle.

8. The template matching method based on edge features according to claim 5, characterized in that: The quick image loading function is used to load an image and trigger a template matching function at the same time to find the location of the feature in the image.

Citation Information

Patent Citations

  • Robot vision identifying and positioning method oriented on intelligent production line

    CN108876762A

  • A heterogeneous image matching method based on refined feature optimization extraction

    CN109409292A

  • Different-source image matching method based on template matching and twin neural network optimization

    CN112801141A

  • Method for Microscopic Image Acquisition Based on Sequential Section

    US20190012520A1