A machine vision matching method with custom weights
Through a machine vision matching method with customized weights, the template image is obtained and edge extraction and compression are performed. The feature points are classified according to the selection range box input by the user, and a binary weight mask is generated for layer-by-layer matching. This solves the problem of inaccurate matching of traditional template matching when the image is deformed, and achieves more precise feature matching.
Patent Information
- Application Number
- CN202510638193.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2045-05-19
AI Technical Summary
When the target image is partially deformed, the key features of the user's interest are not accurately matched or misplaced in traditional template matching methods, resulting in poor template matching results.
Through a machine vision matching method with customized weights, the template image is obtained and edge extraction is performed to determine the set of feature points. The feature points are classified according to the selection range box input by the user. The template image is compressed using a number of compression levels to generate a binary weighted mask for weighted feature matching. Strict matching is performed layer by layer to improve matching accuracy.
The matching precision and accuracy of the template's interesting features and the target image are improved, ensuring that key features can still be accurately matched even when the image is deformed.
Smart Images

Figure CN120182643B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of machine vision matching, and more specifically, to a machine vision matching method with customized weights. Background Art
[0002] Machine vision is widely used in industry, and template matching is one of its key technologies. Because it can quickly and accurately determine the position and pose of a target object in an image, template matching has been widely used in defect detection, machining positioning, and image alignment. However, traditional template matching can only match the entire template. When the target image is partially deformed, key features of interest to the user are often inaccurately matched or even misaligned. Therefore, existing technologies have drawbacks and urgently need improvement. Summary of the Invention
[0003] In view of the above problems, the purpose of the present invention is to provide a machine vision matching method with customized weights, which supports users to add customized key features of interest to the template, and by increasing the weight of the features of interest, the features of interest in the template are matched more closely with the target image.
[0004] A first aspect of the present invention provides a machine vision matching method with custom weights, comprising:
[0005] Get the template image;
[0006] Performing edge extraction on the template image to determine a set of feature points;
[0007] Classify the feature points in the feature point set according to the selection range entered by the user to determine the weighted point set and the common point set;
[0008] Compress the template image according to the compression level n set by the user to obtain a set of template compressed images;
[0009] Compression is performed based on a binary weight mask of the template image, and a binary weight mask of each compression level is determined; wherein each compression level includes a 0th compression level and at least one i-th compression level, 0 <i≤n-1;
[0010] Determine the feature point set of the i-th compression level by analyzing the feature point set of the i-th compression level and the binary weight mask;
[0011] Get the search image;
[0012] Compressing the search image according to the number of compression levels n, and determining a set of search images at each compression level;
[0013] Performing weighted feature loose matching on the feature point set of the n-1th compression layer and the search image set to determine the matching position set of the n-1th compression layer;
[0014] Starting from the n-2th layer, strict matching of weight features is performed layer by layer until strict matching of the 0th layer is completed and weight matching is completed.
[0015] In this solution, performing edge extraction on the template image to determine a set of feature points includes:
[0016] Performing Gaussian blur processing on the template image to obtain a preprocessed image;
[0017] Extracting edge feature points of the preprocessed image;
[0018] Calculating the edge length of each edge of the preprocessed image, and removing edge feature points corresponding to edges whose edge length is less than a preset edge length threshold t0;
[0019] Add the remaining edge feature points to the feature point set P.
[0020] In this solution, the feature points in the feature point set are classified according to the selection range box input by the user to determine the weighted point set and the common point set, including:
[0021] Get the selection range box entered by the user;
[0022] Determine the image area within the frame selection range as the frame selection area;
[0023] The feature points in the feature point set P are classified according to the framed area, the edge feature points in the framed area are determined as weight points, and all weight points are classified as a weight point set; the edge feature points outside the framed area are determined as ordinary points, and all ordinary points are classified as an ordinary point set.
[0024] In this solution, the template image is compressed according to the compression level n set by the user to obtain a template compressed image set, including:
[0025] Get the compression level n entered by the user;
[0026] Determine the template image as the template compressed image corresponding to the 0th compression level;
[0027] Compressing the template compressed image of the i-1th compression level to determine the template compressed image of the i-th compression level;
[0028] After each compression is completed, determining whether either the image width or the image height of the compressed template compressed image is less than a preset pixel length threshold;
[0029] If yes, the compression is terminated in advance, and the number of compression levels n is updated according to the actual number of compression levels;
[0030] If not, continue compression according to the number of compression levels n;
[0031] When compression is completed, the template compressed images corresponding to all compression levels are added to the template compressed image set T.
[0032] This plan also includes:
[0033] Performing edge extraction on the template compressed image of the i-th compression level to determine feature points of the compressed template image of the i-th compression level;
[0034] Integrate the feature points of the compressed template image at the i-th compression level to determine the feature point set P corresponding to the i-th compression level i .
[0035] In this solution, the binary weighted mask based on the template image is compressed to determine the binary weighted mask of each compression level, including:
[0036] Generate a binary weighted mask according to the framed area to obtain a binary weighted mask of the 0th compression level;
[0037] For the i-th compression level, the size of the binary weight mask of the i-th compression level is set to half the size of the binary weight mask of the i-1-th compression level, and the binary weight mask of the i-th compression level is interpolated by the binary weight mask of the i-1-th compression level using the nearest neighbor interpolation method; the compression interpolation operation is continuously repeated until the generation of the binary weight mask of the n-1-th compression level is completed;
[0038] The binary weighted masks of all compression levels are added to the binary weighted mask set M.
[0039] In this solution, classifying the feature points in the feature point set of the i-th compression level according to the binary weight mask of the i-th compression level includes:
[0040] The feature point set P of the i-th compression level i and binary weight mask M i Perform analysis and traverse the feature point set P in turn i When the pixel position of the feature point is in the binary weight mask M i When the feature point is valid, the feature point is determined as a weighted point; otherwise, the feature point is determined as an ordinary point.
[0041] In this solution, performing weighted feature loose matching based on the feature point set of the n-1th compression level and the search image set to determine the matching position set of the n-1th compression level includes:
[0042] In the n-1th compression level, a sliding window is used to convert the weighted points of the template image corresponding to the n-1th compression level and the common points in the search image S of the n-1th level into the image S of the n-1th level. n-1 Slide with a pixel step size of 1 and calculate the weight score o of weight point i i and the weight score p of common point j j ;
[0043] ;
[0044] ;
[0045] Among them, o is the original score of weight i after gradient measurement, p o is the original score of common point j after gradient measurement, w and z are weight coefficients;
[0046] According to the weight score o of the weight point i i and the weight score p of common point j j Calculate the coordinate position of the current sliding window (x n-1 、y n-1 ) coordinate score s sum ;
[0047] ;
[0048] Calculate the score reduction threshold t2 based on the score threshold t3 input by the user;
[0049] ;
[0050] Where c0 is the reduction constant and n is the number of compression levels;
[0051] Score the coordinates s sum The coordinate positions greater than the score reduction threshold t2 are added to the matching position set R of the n-1th compression level n-1 .
[0052] In this solution, starting from the n-2th layer, the weight feature strict matching is performed layer by layer until the strict matching of the 0th layer is completed, and the weight matching is completed, including:
[0053] The matching position set R of the m+1th compression level m+1 The position coordinates recorded in m+1 、y m+1) is mapped to the mth compression level, and the position coordinates of the mth compression level (x m 、y m );
[0054] ;
[0055] ;
[0056] Where 0≤m <n-1;
[0057] Calculate the position coordinates of the mth compression level (x m 、y m ) coordinate score s sum ;
[0058] Score the coordinates s in the mth compression level sum The position coordinates greater than the score threshold t3 are added to the matching position set R of the mth layer m middle;
[0059] Repeat the strict matching of weighted features until the strict matching of layer 0 is completed, the final position coordinate information of the target in the search image is determined, and the weighted matching is completed.
[0060] The present invention discloses a machine vision matching method with customized weights, comprising: obtaining a template image and performing edge extraction to determine a feature point set; classifying the feature points in the feature point set according to a selection range box; compressing the template image according to a compression level n to obtain a template compressed image set; compressing the template image based on a binary weight mask of the template image, determining a binary weight mask for each compression level, and classifying the feature points in the feature point set of the i-th compression level; obtaining a search image; compressing the search image according to the compression level n to determine a search image set for each compression level; performing loose weight feature matching on the n-1th compression level, and performing strict weight feature matching layer by layer starting from the n-2th level until strict matching is completed at the 0th level, thereby completing weight matching. The present invention increases the weight of the feature of interest to make the template feature of interest more closely matched with the target image. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 A flow chart of a machine vision matching method with customized weights provided by the present invention is shown;
[0062] Figure 2 A flow chart of the method for determining a feature point set provided by the present invention is shown;
[0063] Figure 3 The flowchart of the method for determining a template compressed image set provided by the present invention is shown. DETAILED DESCRIPTION
[0064] In order to more clearly understand the above-mentioned objects, features and advantages of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that, in the absence of conflict, the embodiments of the present application and the features therein can be combined with each other.
[0065] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Therefore, the scope of protection of the present invention is not limited to the specific embodiments disclosed below.
[0066] Figure 1 The flowchart of the machine vision matching method with customized weights provided by the present invention is shown.
[0067] like Figure 1 As shown, the present invention discloses a machine vision matching method with custom weights, comprising:
[0068] S102, obtaining a template image;
[0069] S104, performing edge extraction on the template image to determine a feature point set;
[0070] S106, classifying the feature points in the feature point set according to the selection range entered by the user to determine a weighted point set and a common point set;
[0071] S108, compressing the template image according to the compression level number n set by the user to obtain a set of template compressed images;
[0072] S110, performing compression based on the binary weight mask of the template image, and determining the binary weight mask of each compression level; wherein each compression level includes the 0th compression level and at least one i-th compression level, 0 <i≤n-1;
[0073] S112, classifying the feature points in the feature point set of the i-th compression level according to the binary weight mask of the i-th compression level;
[0074] S114, obtaining a search image;
[0075] S116, compressing the search image according to the number of compression levels n, and determining a set of search images at each compression level;
[0076] S118, performing weighted feature loose matching based on the feature point set of the n-1th compression level and the search image set to determine a matching position set of the n-1th compression level;
[0077] S120 , starting from the n-2th layer, perform strict matching of weight features layer by layer until strict matching of the 0th layer is completed, thereby completing weight matching.
[0078] According to an embodiment of the present invention, an input template image is first analyzed. Edge feature points of the template image are determined through edge feature extraction, and a feature point set for the template image is established. Next, based on a user-entered selection range, edge feature points within the selected area are classified as weighted points, while edge feature points outside the selected area are classified as normal points. The template image is then compressed using the number of compression levels entered by the user, and a compressed template image for each compression level is determined. Compression can be performed using a Gaussian blur followed by even-numbered row deletion. Edge extraction is performed on the compressed template image for each compression level using the edge feature point extraction method for the template image, and a feature point set for each compression level is determined. A binary weighted mask for the 0th compression level is determined using the selected area. The nearest neighbor difference method is used to sequentially determine the binary weighted mask for the next level, until the binary weighted mask for the n-1th level is determined. A determination is then made as to whether the pixel position of a feature point in the i-th level feature point set is valid within the corresponding binary weighted mask. If so, the feature point is determined as a weighted point; otherwise, it is considered a normal point.
[0079] The input search image is then compressed according to the number of compression levels n, and a set S of search images for each compression level is determined. The image at compression level 0 is the original input search image. A loose weighted feature match is performed on the n-1 compression level to determine the approximate location of the target in the search image. Based on the matching position set at the n-1 compression level, a strict weighted feature match is performed on subsequent compression levels to determine the precise location of the target in the search image.
[0080] Figure 2 The flowchart of the method for determining a feature point set provided by the present invention is shown.
[0081] like Figure 2 As shown, according to an embodiment of the present invention, edge extraction is performed on a template image to determine a feature point set, including:
[0082] S202, performing Gaussian blur processing on the template image to obtain a preprocessed image;
[0083] S204, extracting edge feature points of the pre-processed image;
[0084] S206, calculating the edge length of each edge of the pre-processed image, and removing edge feature points corresponding to edges whose edge length is less than a preset edge length threshold t0;
[0085] S208: Add the remaining edge feature points to the feature point set P.
[0086] It should be noted that the input template image is first Gaussian blurred; then the edge feature points of the Gaussian blurred image are extracted and recorded using the edge extraction method; finally, the edge feature points corresponding to the edges whose edge length is less than the preset edge length threshold t0 are removed, and the remaining edge feature points are added to the original feature point set P to determine the feature point set P.
[0087] The preset edge length threshold t0 is set by those skilled in the art according to actual needs.
[0088] According to an embodiment of the present invention, the feature points in the feature point set are classified according to the selection range box input by the user to determine the weighted point set and the common point set, including:
[0089] Get the selection range box entered by the user;
[0090] The image area within the selection range is determined as the selection area;
[0091] The feature points in the feature point set P are classified according to the framed area, the edge feature points within the framed area are determined as weighted points, and all weighted points are classified as a weighted point set; the edge feature points outside the framed area are determined as ordinary points, and all ordinary points are classified as an ordinary point set.
[0092] It should be noted that the user selects the original feature point set P after visualization by selecting a range box on the display interface of the display terminal (such as a computer, mobile phone, etc.), selects the weighted feature points of interest, generates a binary weight mask based on the selected area of the image selected by the user, and classifies the points in the feature point set P into a set of ordinary points (outside the selected area) and a set of weighted points (inside the selected area) according to the selected area.
[0093] Figure 3 The flowchart of the method for determining a template compressed image set provided by the present invention is shown.
[0094] like Figure 3 As shown, according to an embodiment of the present invention, the template image is compressed according to the compression level number n set by the user to obtain a template compressed image set, including:
[0095] S302, obtaining the number of compression levels n input by the user;
[0096] S304, determining the template image as the template compressed image corresponding to the 0th compression level;
[0097] S306, compressing the template compressed image of the i-1th compression level to determine the template compressed image of the i-th compression level;
[0098] S308. After each compression is completed, determine whether either the image width or the image height of the compressed template compressed image is less than a preset pixel length threshold.
[0099] S310. If so, end the compression prematurely and update the compression level number n according to the actual number of compression levels.
[0100] S312. If not, continue the compression according to the compression level number n.
[0101] S314. After the compression is completed, add the template compressed images corresponding to all compression levels to the template compressed image set T.
[0102] It should be noted that first, the input template image is used as the image corresponding to the 0th compression level (i.e., no compression). For the image with the compression level of i (0 < i ≤ n - 1), the i-th layer image is obtained by compressing the (i - 1)-th layer image. The compression is performed by first performing Gaussian blur and then deleting even rows. Continuously compress the template image until the template compressed image of the (n - 1)-th layer is obtained. After each compression is completed, if the width or height of the current compressed image is less than the preset pixel length threshold (such as 100 pixel lengths), then exit the compression process prematurely and update n to the actual number of compression levels. Finally, add the template compressed images corresponding to all compression levels to the template compressed image set T.
[0103] Among them, the initial value of the preset pixel length threshold is 100 pixel lengths, and those skilled in the art can modify it according to actual needs.
[0104] According to an embodiment of the present invention, it further includes:
[0105] Perform edge extraction on the template compressed image of the i-th compression level to determine the feature points of the compressed template image of the i-th compression level.
[0106] Integrate the feature points of the compressed template image of the i-th compression level to determine the feature point set P corresponding to the i-th compression level i .
[0107] It should be noted that for the template compressed image of the i-th (0 < i ≤ n - 1) compression level, the edge extraction method of the template image (i.e., the image corresponding to the 0th compression level) is also used to extract edge feature points, and the extracted edge feature points are used as the feature points of the compressed template image corresponding to the i-th compression level.
[0108] According to an embodiment of the present invention, compression is performed based on the binary weight mask of the template image to determine the binary weight mask of each compression level, including:
[0109] Generate a binary weight mask based on the selected area to obtain the binary weight mask of the 0th compression level;
[0110] For the i-th compression level, set the size of the binary weight mask of the i-th compression level to half of the size of the binary weight mask of the (i - 1)-th compression level, and use the nearest neighbor interpolation method to generate the binary weight mask of the i-th compression level by interpolating the binary weight mask of the (i - 1)-th compression level; continuously loop the operations of compression and interpolation until the generation of the binary weight mask of the (n - 1)-th compression level is completed;
[0111] Add the binary weight masks of all compression levels to the binary weight mask set M.
[0112] It should be noted that a binary weight mask is generated based on the selected area of the user-selected image and compressed as the binary weight mask of the 0th compression level. The nearest neighbor difference method is used to determine the binary weight mask of the next compression level through the binary weight mask of the current compression level. By continuously looping the operations of compression and difference, the binary weight masks of the 1st to (n - 1)-th compression levels are generated in sequence.
[0113] According to an embodiment of the present invention, classifying the feature points in the feature point set of the i-th compression level according to the binary weight mask of the i-th compression level includes:
[0114] For the feature point set P of the i-th compression level i and the binary weight mask M i perform analysis, and sequentially traverse the feature points in the feature point set P i When the pixel position of the feature point is valid in the binary weight mask M i of the i-th compression level, determine the feature point as a weight point; otherwise, determine the feature point as a normal point.
[0115] It should be noted that according to the binary weight mask, the normal points and weight points corresponding to the template image of the i-th (0 < i ≤ n - 1) compression level are calculated. Take the feature points in the feature point set P i corresponding to the i-th compression level and traverse them to determine whether the pixel position of the feature point is valid in the binary weight mask M i of the i-th compression level, so as to determine whether the current feature point is a weight point or a normal point.
[0116] According to an embodiment of the present invention, performing a loose matching of weight features based on the feature point set and the search image set of the (n - 1)-th compression level to determine the matching position set of the (n - 1)-th compression level includes: <00003In the n-1th compression level, a sliding window is used to convert the weighted points of the template image corresponding to the n-1th compression level and the common points in the search image S of the n-1th level into the image S of the n-1th level. n-1 Slide with a pixel step size of 1 and calculate the weight score o of weight point i i and the weight score p of common point j j ;
[0118] ;
[0119] ;
[0120] Among them, o is the original score of weight i after gradient measurement, p o is the original score of common point j after gradient measurement, w and z are weight coefficients;
[0121] According to the weight score o of weight point i i and the weight score p of common point j j Calculate the coordinate position of the current sliding window (x n-1 、y n-1 ) coordinate score s sum ;
[0122] ;
[0123] Calculate the score reduction threshold t2 based on the score threshold t3 input by the user;
[0124] ;
[0125] Where c0 is the reduction constant and n is the number of compression levels;
[0126] Score the coordinates s sum The coordinate positions greater than the score reduction threshold t2 are added to the matching position set R of the n-1th compression level n-1 .
[0127] It should be noted that a weighted loose feature matching is first performed on the search image to determine the approximate location of the target within the search image. The coordinate score is the sum of all weighted point scores and all common point scores. The coordinate score can be calculated using a traditional gradient metric. The weight coefficient w is set by the user based on actual needs. The default value of the weight coefficient z is 1.
[0128] According to an embodiment of the present invention, starting from the n-2th layer, strict matching of weight features is performed layer by layer until strict matching of the 0th layer is completed, thereby completing weight matching, including:
[0129] The matching position set R of the m+1th compression levelm+1 The position coordinates recorded in m+1 、y m+1 ) is mapped to the mth compression level, and the position coordinates of the mth compression level (x m 、y m );
[0130] ;
[0131] ;
[0132] Where 0≤m <n-1;
[0133] Calculate the position coordinates of the mth compression level (x m 、y m ) coordinate score s sum ;
[0134] Score the coordinates s in the mth compression level sum The position coordinates greater than the score threshold t3 are added to the matching position set R of the mth layer m middle;
[0135] Repeat the strict matching of weighted features until the strict matching of layer 0 is completed, the final position coordinate information of the target in the search image is determined, and the weighted matching is completed.
[0136] It should be noted that when determining the matching position set R of the n-1th compression level n-1 Based on the above, strict matching is performed layer by layer starting from the n-2th layer until the strict matching of the 0th layer is completed. Each position coordinate in the matching position set of the m+1th compression level is mapped to the mth compression level, and the position coordinate of the mth compression level is determined. The coordinate score of the position coordinate of the mth compression level is calculated using the same calculation method of the coordinate position in the n-1th compression level. The position coordinates with a coordinate score greater than the user-entered score threshold t3 are recorded and added to the matching position set R of the i-th layer. i Repeat the above steps until the strict matching of the 0th layer is completed, and the final position coordinate information of the target in the search image is obtained, that is, the weighted matching is completed.
[0137] The information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals (including but not limited to signals transmitted between user terminals and other devices, etc.) involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use, and processing of relevant data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the "template image" and "search image" involved in this disclosure are all obtained with full authorization.
[0138] The present invention discloses a machine vision matching method with customized weights, comprising: obtaining a template image and performing edge extraction to determine a feature point set; classifying the feature points in the feature point set according to a selection range box; compressing the template image according to a compression level n to obtain a template compressed image set; compressing the template image based on a binary weight mask of the template image, determining a binary weight mask for each compression level, and classifying the feature points in the feature point set of the i-th compression level; obtaining a search image; compressing the search image according to the compression level n to determine a search image set for each compression level; performing loose weight feature matching on the n-1th compression level, and performing strict weight feature matching layer by layer starting from the n-2th level until strict matching is completed at the 0th level, thereby completing weight matching. The present invention increases the weight of the feature of interest to make the template feature of interest more closely matched with the target image.
[0139] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0140] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed across multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the scheme of this embodiment.
[0141] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0142] Those skilled in the art will appreciate that all or part of the steps of the above-mentioned method embodiments may be implemented by hardware associated with program instructions, and the aforementioned program may be stored in a computer-readable storage medium. When the program is executed, the program executes the steps of the above-mentioned method embodiments. The aforementioned storage medium includes various media that can store program codes, such as mobile storage devices, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.
[0143] Alternatively, if the integrated units described above are implemented as software modules and sold or used as standalone products, they can also be stored on a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present invention, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product, stored on a storage medium, includes instructions for enabling a computer device (such as a personal computer, server, or network device) to execute all or part of the methods described in various embodiments of the present invention. The aforementioned storage media include various media capable of storing program code, such as removable storage devices, ROM, RAM, magnetic disks, or optical disks.
Claims
1. A machine vision matching method with custom weights, characterized in that: include: Get the template image; Performing edge extraction on the template image to determine a set of feature points; Classify the feature points in the feature point set according to the selection range entered by the user to determine the weighted point set and the common point set; Compress the template image according to the compression level n set by the user to obtain a set of template compressed images; Compression is performed based on a binary weight mask of the template image, and a binary weight mask of each compression level is determined; wherein each compression level includes a 0th compression level and at least one i-th compression level, 0 <i≤n-1; Determine the feature point set of the i-th compression level by analyzing the feature point set of the i-th compression level and the binary weight mask; Get the search image; Compressing the search image according to the number of compression levels n, and determining a set of search images at each compression level; According to the feature point set of the n-1th compression level and the search image set, the weighted feature loose matching is performed. In the n-1th compression level, the weighted points of the template image corresponding to the n-1th compression level and the common points in the search image S of the n-1th level are matched in the form of a sliding window. n-1 Slide with a pixel step size of 1 and calculate the weight score o of weight point i i and the weight score p of common point j j ; According to the weight score o of the weight point i i and the weight score p of common point j j Calculate the coordinate position of the current sliding window (x n-1 、y n-1 ) coordinate score s sum ; Calculate the score reduction threshold t2 based on the score threshold t3 input by the user; Set the coordinate score s sum The coordinate positions greater than the score reduction threshold t2 are added to the set of matching positions of the n-1th compression level to determine the set of matching positions of the n-1th compression level; Starting from the n-2th layer, perform strict matching of weight features layer by layer until the strict matching of the 0th layer is completed and the weight matching is completed; The step of classifying the feature points in the feature point set according to the selection range input by the user to determine the weighted point set and the common point set includes: Get the selection range box entered by the user; Determine the image area within the frame selection range as the frame selection area; Classify the feature points in the feature point set P according to the frame selection area, determine the edge feature points within the frame selection area as weight points, and classify all weight points into a weight point set; determine the edge feature points outside the frame selection area as ordinary points, and classify all ordinary points into an ordinary point set; The compression is performed based on the binary weight mask of the template image, and the binary weight mask of each compression level is determined, including: Generate a binary weighted mask according to the framed area to obtain a binary weighted mask of the 0th compression level; For the i-th compression level, the size of the binary weight mask of the i-th compression level is set to half the size of the binary weight mask of the i-1-th compression level, and the binary weight mask of the i-th compression level is interpolated by the binary weight mask of the i-1-th compression level using the nearest neighbor interpolation method; the compression interpolation operation is continuously repeated until the generation of the binary weight mask of the n-1-th compression level is completed; Add the binary weighted masks of all compression levels to the binary weighted mask set M; The classifying the feature points in the feature point set of the i-th compression level according to the binary weight mask of the i-th compression level includes: The feature point set P of the i-th compression level i and binary weight mask M i Perform analysis and traverse the feature point set P in turn i When the pixel position of the feature point is in the binary weight mask M i When the feature point is valid, the feature point is determined as a weighted point; otherwise, the feature point is determined as an ordinary point.
2. The machine vision matching method with custom weights according to claim 1, characterized in that: The performing edge extraction on the template image to determine a feature point set includes: Performing Gaussian blur processing on the template image to obtain a preprocessed image; Extracting edge feature points of the preprocessed image; Calculating the edge length of each edge of the preprocessed image, and removing edge feature points corresponding to edges whose edge length is less than a preset edge length threshold t0; Add the remaining edge feature points to the feature point set P.
3. The machine vision matching method with custom weights according to claim 1, characterized in that: The template image is compressed according to the compression level number n set by the user to obtain a template compressed image set, including: Get the compression level n entered by the user; Determine the template image as the template compressed image corresponding to the 0th compression level; Compressing the template compressed image of the i-1th compression level to determine the template compressed image of the i-th compression level; After each compression is completed, determining whether either the image width or the image height of the compressed template compressed image is less than a preset pixel length threshold; If yes, the compression is terminated in advance, and the number of compression levels n is updated according to the actual number of compression levels; If not, continue compression according to the number of compression levels n; When compression is completed, the template compressed images corresponding to all compression levels are added to the template compressed image set T.
4. The machine vision matching method with custom weights according to claim 1, characterized in that: Also includes: Performing edge extraction on the template compressed image of the i-th compression level to determine feature points of the compressed template image of the i-th compression level; Integrate the feature points of the compressed template image at the i-th compression level to determine the feature point set P corresponding to the i-th compression level i .
5. The machine vision matching method with customized weights according to claim 1, characterized in that: The performing weighted feature loose matching based on the feature point set of the n-1th compression level and the search image set to determine the matching position set of the n-1th compression level includes: In the n-1th compression level, a sliding window is used to convert the weighted points of the template image corresponding to the n-1th compression level and the common points in the search image S of the n-1th level into the image S of the n-1th level. n-1 Slide with a pixel step size of 1 and calculate the weight score o of weight point i i and the weight score p of common point j j ; ; ; Among them, o is the original score of weight i after gradient measurement, p o is the original score of common point j after gradient measurement, w and z are weight coefficients; According to the weight score o of the weight point i i and the weight score p of common point j j Calculate the coordinate position of the current sliding window (x n-1 、y n-1 ) coordinate score s sum ; ; Calculate the score reduction threshold t2 based on the score threshold t3 input by the user; ; Where c0 is the reduction constant and n is the number of compression levels; Score the coordinates s sum The coordinate positions greater than the score reduction threshold t2 are added to the matching position set R of the n-1th compression level n-1 .
6. The machine vision matching method with customized weights according to claim 5, characterized in that: The weight feature strict matching is performed layer by layer starting from the n-2th layer until the strict matching of the 0th layer is completed, and the weight matching is completed, including: The matching position set R of the m+1th compression level m+1 The position coordinates recorded in m+1 、y m+1 ) is mapped to the mth compression level, and the position coordinates of the mth compression level (x m 、y m ); ; ; Where 0≤m <n-1; Calculate the position coordinates of the mth compression level (x m 、y m ) coordinate score s sum ; Score the coordinates s in the mth compression level sum The position coordinates greater than the score threshold t3 are added to the matching position set R of the mth layer m middle; Repeat the strict matching of weighted features until the strict matching of layer 0 is completed, the final position coordinate information of the target in the search image is determined, and the weighted matching is completed.
Citation Information
Patent Citations
Template matching method and device, electronic equipment and storage medium
CN112085033A