A blob localization method based on blob learning and matching
Through a method based on Blob learning and matching, spot positioning is used to use the geometric feature parameters of the target template in the image, the development difficulty problems caused by multiple independent algorithm operations in the prior art are solved, and fast and efficient target positioning is achieved.
Patent Information
- Application Number
- CN202110456707.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-26
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2041-04-26
AI Technical Summary
The prior art requires a large number of independent algorithm operations in spot positioning, which makes it difficult to develop the system, especially in complex projects, which increases the difficulty of development.
Using a method based on Blob learning and matching, we can match the target in the test image by learning the geometric feature parameters (area, circularity, rectangle) of the target template in the image to achieve spot positioning.
This method is simple to operate and can quickly locate targets, reducing the difficulty of system development and improving efficiency in complex projects.
Smart Images

Figure CN113240738B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of industrial machine vision, and in particular to a blob positioning method based on blob learning and matching. Background Art
[0002] Spot positioning belongs to the field of industrial machine vision and is one of the commonly used methods for target positioning. The existing technology needs to analyze image features first, and then use a series of independent algorithm operations to achieve spot positioning. Usually, a large number of independent operators are required to achieve a positioning target, which increases the difficulty of system development. Especially for complex projects, the software process will be very lengthy, which increases the development difficulty for project engineers.
[0003] Therefore, a technology is urgently needed to solve this problem. Summary of the invention
[0004] The purpose of the present invention is to overcome the above-mentioned problems of the prior art and provide a blob positioning method based on Blob learning and matching. First, the geometric feature parameters (area, circularity, rectangularity) of the target template in the image are learned, and then the target is matched in the test image according to the template parameters. The method is simple to operate and can quickly locate the target.
[0005] The above objectives are achieved through the following technical solutions:
[0006] A blob location method based on blob learning and matching includes template learning and template matching, wherein:
[0007] The template learning includes the following steps:
[0008] Step (1) draw a rectangular region of interest and parameters in the initial image;
[0009] Step (2) thresholding the image within the rectangular region of interest to obtain a run length code;
[0010] Step (3) performing connectivity segmentation on the run length code in step (2) to obtain at least one template sub-block;
[0011] Step (4) respectively calculating the area, circularity and rectangularity of each of the template sub-blocks;
[0012] Step (5) selects the template sub-block that meets the conditions in step (4) as a template according to the parameters in step (1), and saves its attributes.
[0013] The template matching comprises the following steps:
[0014] Step (6) setting a rectangular search area, a grayscale threshold range and a similarity in the detection image according to the attributes of the template sub-block described in step (5);
[0015] Step (7) thresholding and connectivity segmenting the image within the rectangular search area to obtain at least one sub-block, and calculating the attributes of each sub-block and the similarity of the attributes of the sub-blocks;
[0016] Step (8) compares the sub-block attribute similarity in step (7) with the similarity in step (6). If the sub-block attribute similarity is ≥ the similarity, the template matching is successful; if the sub-block attribute similarity is < the similarity, the template matching fails.
[0017] Furthermore, the parameters in step (1) include threshold, area, circularity and rectangularity, wherein the threshold range is [Thre min ,Thre max ], the area range is [Area min ,Area max ], the range of circularity is [Circularity min ,Circularity max ], the range of the rectangular degree is [Rectangularity min ,Rectangularity max ].
[0018] Furthermore, the thresholding in step (2) is specifically: extracting pixels whose grayscale values are within the threshold in the rectangular region of interest, and the pixel extraction conditions are as follows:
[0019] Thre min ≤ gray ≤ Thre max
[0020] Among them, gray represents the gray value, Thre min Represents the minimum value of the threshold, Thr max represents the maximum value of the threshold, and uses run length coding to express the coordinates of the pixel point. The structure of the run length coding is as follows:
[0021] (x,y,length)
[0022] Among them, x and y represent the starting coordinates of the trip, and length represents the length of the trip.
[0023] Furthermore, in step (3), connectivity segmentation is performed on the run length encoding in step (2), wherein connectivity is used to describe whether pixels are adjacent to each other, and is divided into four-connectivity and eight-connectivity;
[0024] Set r1(x1,y1,length1) and r2(x2,y2,length2) to known run length encoding,
[0025] If x1<(x2+length2) and (x1+length1)>x2, then the trips r1 and r2 are four-connected;
[0026] If x1≤(x2+length2) and (x1+length1)≥x2, then the paths r1 and r2 are octave connected.
[0027] Furthermore, in step (4), the area, circularity and rectangularity of each template sub-block are calculated respectively, specifically:
[0028] Assume the area of the template sub-block is area, then:
[0029] Among them, n and length i are the number of sub-block runs and the length of the i-th run, respectively;
[0030] Assume that the circularity of the template sub-block is circularity, then:
[0031] In the formula, area is the area of the template sub-block, dist is the maximum distance from the sub-block centroid to each point on the sub-block;
[0032] Assume that the rectangularity of the template sub-block is rectangularity, then:
[0033] In the formula, area is the area of the sub-block, area boundingbox is the area of the minimum enclosing rectangle of the sub-block.
[0034] Furthermore, step (5) selects the template sub-block that meets the conditions in step (4) as a template according to the parameters in step (1), and saves its attributes, wherein the attributes include area, rectangularity, circularity and centroid coordinates.
[0035] Furthermore, in step (7), the attributes of the sub-blocks include area A, circularity C and rectangularity R, and the sub-block attribute similarity includes area similarity S area , circularity similarity S cir and rectangle similarity S rect , the formula is as follows:
[0036]
[0037] Among them, min() and max() are functions for finding the minimum and maximum values, and area, circularity, and rectangularity are the corresponding attributes of the template sub-block.
[0038] Furthermore, step (8) is specifically as follows:
[0039] If and only if When , the template sub-block is the target sub-block, and the comprehensive similarity is as follows:
[0040]
[0041] Furthermore, there may be multiple target sub-blocks, all of which may be output, or the target with the highest comprehensive similarity may be output.
[0042] Beneficial Effects
[0043] The blob positioning method based on Blob learning and matching provided by the present invention can realize the rapid learning and matching of the target object, and only needs two operators: Blob template learning and Blob target matching. According to the geometric characteristics of the target to be learned, appropriate threshold, area, rectangularity and circularity parameters are set to obtain a learning template as a benchmark for target matching; in the entire program, template learning only needs to be performed once; Blob matching only needs to set appropriate threshold parameters and similarity, and the target object can be positioned according to the learned template, and the target area and corresponding attribute values can be obtained. This method is simple to operate and can quickly locate the target. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 A flow chart of a blob positioning method based on blob learning and matching described in the present invention;
[0045] Figure 2 A schematic diagram of the neighborhood of a target pixel point P(i, j) in a blob positioning method based on blob learning and matching described in the present invention;
[0046] Figure 3 This is the original image of the screw hole on the plastic workpiece;
[0047] Figure 4 The screw hole area template is obtained by template learning in the spot positioning method based on Blob learning and matching described in the present invention;
[0048] Figure 5 is the original image to be matched;
[0049] Figure 6 The minimum enclosing circle of the screw hole and its center are obtained by template matching of the spot positioning method based on Blob learning and matching described in the present invention. DETAILED DESCRIPTION
[0050] The present invention is further described in detail below based on the accompanying drawings and embodiments.
[0051] like Figure 1 As shown, a blob positioning method based on blob learning and matching includes template learning and template matching, wherein:
[0052] The template learning includes the following steps:
[0053] Step (1) draw a rectangular region of interest and parameters in the initial image;
[0054] Step (2) thresholding the image within the rectangular region of interest to obtain a run length code;
[0055] Step (3) performing connectivity segmentation on the run length code in step (2) to obtain at least one template sub-block;
[0056] Step (4) respectively calculating the area, circularity and rectangularity of each of the template sub-blocks;
[0057] Step (5) selects the template sub-block that meets the conditions in step (4) as a template according to the parameters in step (1), and saves its attributes.
[0058] The template matching comprises the following steps:
[0059] Step (6) setting a rectangular search area, a grayscale threshold range and a similarity in the detection image according to the attributes of the template sub-block described in step (5);
[0060] Step (7) thresholding and connectivity segmenting the image within the rectangular search area to obtain at least one sub-block, and calculating the attributes of each sub-block and the similarity of the attributes of the sub-blocks;
[0061] Step (8) compares the sub-block attribute similarity in step (7) with the similarity in step (6). If the sub-block attribute similarity is ≥ the similarity, the template matching is successful; if the sub-block attribute similarity is < the similarity, the template matching fails.
[0062] As an optimization of this embodiment, in the template learning, in step (1), a rectangular region of interest is drawn in the initial image, and the region needs to contain the detection target. Parameters are set according to the characteristics of the target to be detected, and the parameters include threshold, area, circularity and rectangularity, wherein the range of the threshold is [Thre min ,Thre max ], the area range is [Area min ,Area max], the range of circularity is [Circularity min ,Circularity max ], the range of the rectangular degree is [Rectangularity min ,Rectangularity max ].
[0063] In the template learning, the thresholding in step (2) is specifically: extracting the pixel points whose grayscale values are within the threshold value in the rectangular region of interest, and the pixel point extraction conditions are as follows:
[0064] Thre min ≤ gray ≤ Thre max
[0065] Among them, gray represents the gray value, Thre min Represents the minimum value of the threshold, Thr max represents the maximum value of the threshold, and uses run length coding to express the coordinates of the pixel point. The structure of the run length coding is as follows:
[0066] (x,y,length)
[0067] Among them, x and y represent the starting coordinates of the trip, and length represents the length of the trip.
[0068] The basic principle of run length encoding is to use a representative value and string length to replace continuous strings with the same value, so that the symbol length is less than the length of the original data; pixels with the same grayscale value arranged in a certain direction can be regarded as continuous symbols, and replacing these continuous symbols with strings can greatly reduce the amount of data.
[0069] In the template learning, in step (3), connectivity segmentation is performed on the run length encoding in step (2), wherein connectivity is used to describe whether pixels are adjacent, and is divided into four-connected and eight-connected;
[0070] Set r1(x1,y1,length1) and r2(x2,y2,length2) to known run length encoding,
[0071] If x1<(x2+length2) and (x1+length1)>x2, then the trips r1 and r2 are four-connected;
[0072] If x1≤(x2+length2) and (x1+length1)≥x2, then the paths r1 and r2 are octave connected.
[0073] Figure 2This is a schematic diagram of the neighborhood of the target pixel point P(i,j), where P2, P4, P5, and P7 are connected to the four-neighborhood of point P, and P1, P2, P3, P4, P5, P6, P7, and P8 are connected to the eight-neighborhood of point P.
[0074] In the template learning, the area, circularity and rectangularity of each template sub-block are calculated in step (4), specifically:
[0075] Assume the area of the template sub-block is area, then:
[0076] Among them, n and length i are the number of sub-block runs and the length of the i-th run, respectively;
[0077] Assume that the circularity of the template sub-block is circularity, then:
[0078] In the formula, area is the area of the template sub-block, dist is the maximum distance from the sub-block centroid to each point on the sub-block;
[0079] Assume that the rectangularity of the template sub-block is rectangularity, then:
[0080] In the formula, area is the area of the sub-block, area boundingbox is the area of the minimum enclosing rectangle of the sub-block.
[0081] In the template learning, in step (5), the template sub-block that meets the conditions in step (4) is selected as the template according to the parameters in step (1), that is, among multiple Blob sub-blocks, a sub-block (possibly more than one) within the range of area, rectangularity and circularity is selected as the template, and its attributes are saved, and the attributes include area, rectangularity, circularity and centroid coordinates.
[0082] In the template matching, step (6) is specifically as follows: in the detection image, a rectangular search area, a grayscale threshold range (which may be consistent with the grayscale threshold range set during Blob learning), and similarity are set.
[0083] In the template matching, the attributes of the sub-blocks in step (7) include area A, circularity C and rectangularity R, and the sub-block attribute similarity includes area similarity S area , circularity similarity S cir and rectangle similarity S rect , the formula is as follows:
[0084]
[0085] Among them, min() and max() are functions for finding the minimum and maximum values, and area, circularity, and rectangularity are the corresponding attributes of the template sub-block.
[0086] In template matching, step (8) is specifically as follows:
[0087] If and only if When , the template sub-block is the target sub-block, and the comprehensive similarity is as follows:
[0088]
[0089] There may be multiple target sub-blocks, all of which can be output, or the target with the highest comprehensive similarity can be output.
[0090] Example 1
[0091] Figure 3 This is the original image of the screw hole on the plastic workpiece. The plastic workpiece has a hole. The center of the screw hole needs to be located. The center coordinates are provided to the robot arm. The robot arm grabs the screw and moves it to the specified position to drill the screw into the hole. The specific implementation method of locating the center of the screw hole is further described below in combination with the accompanying drawings and the technical solution.
[0092] Step 1: Template learning
[0093] like Figure 3 As shown, the original image is set as the template learning, and the rectangular learning area is set ( Figure 4 The coordinates of the upper left corner of the region are (605, 271), the width and height are 232 and 300 respectively, the threshold range is [0, 200], the area range is [1000, 99999999], the circularity range is [0.5, 1.0], and the rectangularity range is [0, 1.0].
[0094] Perform template learning and obtain the template area ( Figure 4 The attributes of the template region are: area: 6147, circularity: 0.849829, rectangularity: 0.767416, and centroid: (717.904, 426.925).
[0095] Step 2: Template matching:
[0096] Figure 5 For the original image to be matched, set a rectangular search area ( Figure 6 The coordinates of the upper left corner of the region are (152, 252), the width and height are 776 and 541 respectively, the threshold range is [0, 200] (the same as the threshold range during template learning), and the similarity is 0.3.
[0097] Perform template matching to obtain the target area and calculate the minimum enclosing circle of the area ( Figure 6 The circle in the figure has a cross marking its center. The target region attributes are (the corresponding attribute similarity is in parentheses), area: 6155 (0.9987), circularity: 0.672074 (0.790834), rectangularity: 0.704072 (0.917458), centroid: (736.901, 539.015), and comprehensive score: 0.902331.
[0098] The above description is only for illustrating the implementation mode of the present invention and is not intended to limit the present invention. For those skilled in the art, any modification, equivalent substitution, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A blob location method based on blob learning and matching, characterized in that: Includes template learning and template matching, where: The template learning comprises the following steps: Step (1) draws a rectangular region of interest and parameters in the initial image; the parameters include threshold, area, circularity and rectangularity, wherein the threshold range is [Thre min ,Thre max ], the area range is [Area min ,Area max ], the range of circularity is [Circularity min ,Circularity max ], the range of the rectangular degree is [Rectangularity min ,Rectangularity max ]; Step (2) thresholding the image within the rectangular region of interest to obtain a run length code; Step (3) performing connectivity segmentation on the run length code in step (2) to obtain at least one template sub-block; Step (4) respectively calculating the area, circularity and rectangularity of each of the template sub-blocks; Step (5) selects the template sub-block that meets the conditions in step (4) as a template according to the parameters in step (1), and saves its attributes; the attributes include area, rectangularity, circularity and centroid coordinates; The template matching comprises the following steps: Step (6) setting a rectangular search area, a grayscale threshold range and a similarity in the detection image according to the attributes of the template sub-block described in step (5); Step (7) thresholding and connectivity segmenting the image within the rectangular search area to obtain at least one sub-block, and calculating the attributes of each sub-block and the similarity of the attributes of the sub-blocks; Step (8) compares the sub-block attribute similarity in step (7) with the similarity in step (6). If the sub-block attribute similarity is ≥ the similarity, the template matching is successful; if the sub-block attribute similarity is < the similarity, the template matching fails.
2. A blob location method based on blob learning and matching according to claim 1, characterized in that: The thresholding in step (2) is specifically: extracting pixels within the rectangular region of interest whose grayscale values are within the threshold. The pixel extraction conditions are as follows: Thre min ≤gray≤Thre max Among them, gray represents the gray value, Thre min Represents the minimum value of the threshold, Thr max represents the maximum value of the threshold, and uses run length coding to express the coordinates of the pixel point. The structure of the run length coding is as follows: (x,y,length) Among them, x and y represent the starting coordinates of the trip, and length represents the length of the trip.
3. The blob location method based on blob learning and matching according to claim 1, characterized in that: In step (3), connectivity segmentation is performed on the run length coding in step (2), wherein connectivity is used to describe whether pixels are adjacent to each other, and is divided into four-connectedness and eight-connectedness; Set r1(x1,y1,length1) and r2(x2,y2,length2) to known run length encoding, If x1<(x2+length2) and (x1+length1)>x2, then the trips r1 and r2 are four-connected; If x1≤(x2+length2) and (x1+length1)≥x2, then the paths r1 and r2 are octave connected.
4. The blob location method based on blob learning and matching according to claim 1, characterized in that: In step (4), the area, circularity and rectangularity of each template sub-block are calculated respectively, specifically: Assume the area of the template sub-block is area, then: Among them, n and length i are the number of sub-block runs and the length of the i-th run, respectively; Assume that the circularity of the template sub-block is circularity, then: In the formula, area is the area of the template sub-block, dist is the maximum distance from the sub-block centroid to each point on the sub-block; Assume that the rectangularity of the template sub-block is rectangularity, then: In the formula, area is the area of the sub-block, area boundingbox is the area of the minimum enclosing rectangle of the sub-block.
5. The blob location method based on blob learning and matching according to claim 1, characterized in that: Step (7) The attributes of the sub-blocks include area A, circularity C and rectangularity R, and the sub-block attribute similarity includes area similarity S area , circularity similarity S cir and rectangle similarity S rect , the formula is as follows: Among them, min() and max() are functions for finding the minimum and maximum values, and area, circularity, and rectangularity are the corresponding attributes of the template sub-block.
6. The blob location method based on blob learning and matching according to claim 1, characterized in that: Step (8) is specifically: If and only if When , the template sub-block is the target sub-block, and the comprehensive similarity is as follows:
7. The blob location method based on blob learning and matching according to claim 6, characterized in that: When there are multiple target sub-blocks, all of them may be output, or the target with the highest comprehensive similarity may be output.
Citation Information
Patent Citations
Self-adaption method and system of parameters in template matching
CN107590512A
Image analysis systems and related methods
WO2018152157A1