Plane workpiece fine positioning method and device and medium

The precise positioning of flat workpieces through depth map technology solves the problems of low positioning efficiency and insufficient accuracy in traditional methods, enabling precise positioning to be completed with one photo taken. It is suitable for workpieces with deformation or edge deviation, improving processing efficiency and Accuracy.

CN118735989APending Publication Date: 2024-10-01ROBOTICPLUS AI
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310329725.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-30
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

The existing technology has low positioning efficiency in the secondary processing of flat workpieces, especially workpieces with deformation or edge offset. The traditional method requires manual point-by-point teaching or relies on line laser scanning, resulting in insufficient efficiency and accuracy, especially for belts. Precise positioning of workpieces with short sides is not possible.

Method used

Using a precise positioning method based on depth maps, the workpiece depth map data is obtained through a three-dimensional vision sensor, and connected area clustering, plane fitting, contour matching and edge fitting are performed. Combined with two-dimensional contour matching and linear programming, a single photo can be taken. Complete precise positioning.

Benefits of technology

It greatly improves the positioning efficiency of flat workpieces, solves the problem of unable to position workpieces with short sides, realizes intelligent finishing, and improves processing accuracy and efficiency.

✦ Generated by Eureka AI based on patent content.
Patent Text Reader

Abstract

According to the plane workpiece fine positioning method, the depth map data of the three-dimensional camera is directly used, direct fine positioning of the plane workpiece under one-time photographing is achieved, the positioning efficiency is greatly improved, meanwhile, the problem that a workpiece with a short edge and a line laser method cannot be positioned is solved, and intelligent fine machining is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of image recognition and positioning of planar workpieces. Background Art

[0002] In the field of mechanical processing, secondary processing of flat workpieces is a large category of machining content. The secondary processing of flat workpieces is mainly to process the edges after the next cutting, such as beveling, milling R angles, grinding and deburring. For workpieces with straight contours, traditionally, special equipment with rails set along the edges is often used, or robots are used for processing using manual teaching. However, after the previous processing, the workpiece often has defects such as slight overall buckling due to thermal deformation, and deviations between the edges and the drawings, making the above-mentioned linear fitting positioning method based on individual teaching points or linear rails not applicable.

[0003] At present, the processing positioning of the above-mentioned slightly deformed (bending or edge offset) compared with the drawings is mainly completed through three methods: manual point-by-point teaching, manual point-by-point teaching of line laser photography position + line laser scanning, and structured light camera coarse positioning + line laser scanning. The essence of the manual point-by-point teaching method is to increase the number of interpolation points and use straight lines to fit the deformation of the workpiece. It requires fixed tooling. When the consistency of the workpieces is poor or each workpiece is different, each workpiece needs to be taught one by one, which is extremely inefficient. Manual point-by-point teaching of line laser photography position + line laser scanning also has the above-mentioned defects of the manual teaching method. It only transforms the touch teaching method into the line laser measurement and positioning teaching method, which partially reduces the workload of manual close observation. Structured light camera coarse positioning + line laser scanning is the mainstream method of planar workpiece positioning automation at this stage. It mainly obtains the line laser precise positioning photography position through coarse matching of drawings and structured light camera point clouds. Using line laser measurement to obtain the precise positioning of the workpiece solves the problems of inconsistent or deformed workpieces and teaching one by one. However, this method is time-consuming to measure point by point using line laser. For short edges that are lower than the minimum accuracy of coarse positioning (usually 20-50mm), the precise positioning will fail to scan the required edge due to the deviation of the coarse positioning results. Summary of the invention

[0004] The purpose of the present invention is to solve the shortcomings of the above-mentioned existing technologies and to provide a method, system, computer equipment and medium for precise positioning of planar workpieces based on depth maps, so as to realize direct precise positioning of planar workpieces in one shot, thereby greatly improving the positioning efficiency; at the same time, it also solves the problem that workpieces with short sides cannot be positioned by line laser methods.

[0005] To achieve the above object, the technical solution adopted by the present invention is as follows:

[0006] A method for precise positioning of a planar workpiece comprises the following steps:

[0007] S1, use the 3D vision sensor to obtain the depth map data D of the workpiece i ; The N workpiece drawings that need to be matched from the database are denoted as D j (j=1, 2, ..., n);

[0008] S2, depth map data D i , perform K clustering of connected areas in two dimensions and obtain the point set A of the depth map of the K connected areas i (i=1, 2, ...k);

[0009] S3, point set A for a single workpiece i Perform plane fitting to obtain the fitting plane P i (i=1, 2, ...k); and A i All points on the point set are in accordance with the corresponding P i Normal, projected to the corresponding P i On the plane, get the point set B of the plane i (i=1, 2, ...k);

[0010] S4, using the two-dimensional contour matching method, i Perform contour matching to obtain j The point set C whose matching degree in the drawing is higher than the evaluation score threshold i , and record with C i The corresponding drawing D ij In P i On the plane with C i The relative position relationship matrix T i ;

[0011] S5, for D ij In the middle drawing outline, first break it according to the nodes to obtain the line segment set S ij ;

[0012] S6, for S ij The straight lines and / or arcs in T i The transformed edge is denoted as ST ij , in the corresponding A i In the element point set, find the points within the threshold range around each edge and register these points on the corresponding edge;

[0013] S7, plane fitting and filtering are performed on the points registered on each edge in S6 to obtain the point cloud set SA ij , will SA ij Normal vector V fitted to the internal element plane ij Projection to P i On the plane, obtain the plane point cloud set SA after processing and projecting according to the edge of the workpiece i P ij;

[0014] S8, using the plane linear programming method to calculate SA i P ij Fitting straight lines and / or arcs to the point cloud in the image;

[0015] S9, divide the edge after S8 fitting into sections according to -V ij Project back to the original plane to get the updated edge STP in the depth map ij ;

[0016] S10 vs STP ij Extend, connect and trim the broken lines in the figure to make them into a closed contour.

[0017] Furthermore, in the above step S2, the clustering method comprises the following steps:

[0018] S201, divide the depth map into multiple blocks, select a suitable point in each block as a seed point, and ensure that at least 12 pixels in the neighborhood of the point with a distance of 2 (the diagonal distance is also 1) have valid depth values;

[0019] S202, taking the seed point as the center point, searching for pixel points in a neighborhood with a distance of 3, and putting points whose three-dimensional distance to the center point is less than a threshold into this class; then iterating the above operation for points in this class that have not been searched as the center point, until the entire class cannot be expanded in the depth map;

[0020] S203, repeating S202 operation for the seed points in the remaining blocks in any order. If the pixel where the seed point is located is already occupied by the class of the previous seed point, skip this seed point;

[0021] S204, when the number of clusters finally obtained is less than the number of blocks, clusters with too few points are eliminated to ensure the quality of clustering.

[0022] Furthermore, before processing the clustering data, the photographing background and / or the distance threshold background are pre-subtracted from the depth map to reduce the amount of clustering calculations; at the same time, the removal of the background can reduce the amount of calculations for subsequent matching, that is, the number of connected areas of non-artifacts obtained by clustering is reduced.

[0023] The following method can be used to pre-subtract the background of the photo:

[0024] In the depth map, the horizontal axis is set to i, and the vertical axis is set to j. The depth value is od ij , in the background depth map corresponding to the coordinate, calculate the difference between the depth value of the surrounding circle and the depth value, and take the minimum value If the value is less than the threshold th, the point is considered to belong to the background; otherwise, it does not.

[0025] The following method can be used to pre-subtract the distance threshold background:

[0026] 1) Take any point (x, y, z) on a plane in a 3D space that satisfies Ax+By+Cz+D=0, and represent the plane with (A, B, C, D);

[0027] 2) In the three-dimensional sensor coordinate system, find a plane plane0 (A0, B0, C0, D0), where C0>0, so that the workpiece is below the plane and the other objects are above the plane;

[0028] 3) In the depth map, each pixel is converted into the position (x, y, z) in the 3D sensor coordinate system using the 3D sensor internal parameters, and the distance of each point from plane0

[0029] Keep satisfied ij The remaining points that are less than 0 are deleted as background.

[0030] After preprocessing, each remaining connected area is a workpiece (due to process requirements, the default distance between workpieces is not less than 100 mm).

[0031] Furthermore, the plane fitting described in S3 adopts Ransac+least square method. Furthermore, the inner point distance threshold is set to 5 mm.

[0032] Ransac+ least squares plane fitting:

[0033] 1) First use the Ransac (Random Sample Consensus) algorithm to fit the plane. The basic assumption of the RANSAC algorithm is that the sample contains correct data (inliers, data that can be described by the model) and abnormal data (outliers, data that deviates far from the normal range and cannot fit the mathematical model). The basic principle of the algorithm is to perform a certain number of iterations. Each iteration will randomly select several sample points to calculate the mathematical model, and calculate the distance of all points from the mathematical model. Points within the threshold are called inliers, otherwise they are outliers. Finally, the mathematical model used in the iteration with the highest inlier rate will be selected as the final fitting result.

[0034] 2) After obtaining the plane with the highest inlier rate, all inliers are used to fit the plane using the least square method. The least square method (also known as the least square method) is a mathematical optimization technique. It finds the best function match for the data by minimizing the sum of squares of errors. The least square method can be used to easily obtain unknown data and minimize the sum of squares of errors between the obtained data and the actual data. This patent uses the least square method to fit the plane by minimizing the sum of squares of the distances of the points from the plane.

[0035] Preferably, before projection, each element of the Ai point set is filtered. The filtering can be performed by comparing the points in the point set with the Ransac plane P i Distance threshold method to obtain the updated A i Point set.

[0036] Furthermore, the two-dimensional contour matching method described in step S4 adopts a multi-layer image pyramid method based on an image template. Furthermore, the multi-layer image pyramid search method includes: S401 performing full-image derivation on the template image and the workpiece image to obtain a gradient map, and normalizing the gradient direction; S402 moving the template image in the entire workpiece image, calculating the dot product of the gradient of each pixel in the template and the gradient of the current corresponding image pixel, and taking the sum of the dot products as the similarity score, sorting the similarity scores, and obtaining a preliminary positioning of the workpiece; S403 further adjusting using the NCC algorithm until the search of all pyramid layers is completed to obtain the final position of the workpiece.

[0037] Furthermore, to improve the search speed, the template data is directly sampled from the json file to sample the template contour, sampling one point for each pixel along the direction of the entity; and the ideal gradient direction of each sampling point (perpendicular to the direction pointing outward from the entity) is calculated, and the sampling points and corresponding gradients are stored in two vectors in the form of Eigen::Vector2f. Furthermore, to improve the search speed, the template data is not sampled, and the template data is directly screened at specified intervals according to the number of pyramid layers and converted into the form of Eigen::Matrix.

[0038] Furthermore, the template transformation method of this patent is adopted: each time scaling and rotation is performed, the corresponding two-dimensional transformation matrix M is calculated, and this transformation matrix is ​​multiplied with the filtered template data in the form of Eigen::Matrix2Xf to obtain the template data after scale transformation and rotation transformation. The transformed template data is directly calculated with the corresponding image for similarity.

[0039] Furthermore, the template positioning method of this patent is adopted: the output is the transformation matrix of Eigen::Matrix4f, and only the scaling, rotation, and translation transformation matrices that meet the conditions are recorded; when visually displayed, only the transformation matrix is ​​multiplied with the template point set in the form of Eigen::Matrix.

[0040] Furthermore, the search method of the highest layer of the pyramid layer can be changed, that is, the scale transformation of the highest layer of the pyramid can be fixed, and the range of the size transformation can be expanded during precise positioning. At the same time, multi-threading is added to the search of the highest layer of the pyramid. While ensuring the independence of each transformation and parameter in the algorithm, multiple rotation and translation transformations are searched and similarities are calculated at the same time, and the speed is improved more significantly. Multi-threading can also be added to the local hierarchical search. Similarly, while ensuring the independence of each transformation and parameter in the algorithm, the templates selected by the highest layer search are searched locally at the same time, and the speed is also significantly improved.

[0041] The line segments described in step S5 generally include straight line segments and circular arc segments, which can be further ij The length of the midline segment is calculated, divided by the length threshold Tr, and the result is added by 1. The straight line or arc is evenly divided and interrupted according to this result, and re-recorded in S ij middle.

[0042] Through step S6, we can get S obtained in S5 ij The 2D position of each line segment in S on the rough positioning plane. ij The midline segment processing methods include:

[0043] S601, for the straight line segment, set a rectangular ROI, the length direction of the rectangle is parallel to the straight line segment, the length value is equal to the length of the straight line segment + 100 pixels, the width value is equal to 100 pixels, and the straight line segment is the center;

[0044] S602, for the arc segment, a partial annular area is used to represent it, wherein the inner diameter of the annular area is the arc radius - 50 pixels, if it is less than 0, it is a sector; the outer diameter is the arc radius + 50 pixels; the starting angle of the sweep is the arc segment starting angle - 3°, and the ending angle is the arc segment ending angle + 3°;

[0045] S603, traverse each pixel point on the depth map, flatten the pixel point to the plane through perspective transformation, calculate the position of the pixel point on the plane, and then use S ij The ROI of each line segment in is compared; if the position is in a certain line segment ROI, the pixel point in the matched depth map is registered to the corresponding line segment.

[0046] Furthermore, the filtering described in step S7 first refers to removing points in the point set that are more than 2 mm away from the plane; edge extraction is performed on the pixel mask of the filtered point set on the depth map, and after all edge points are extracted, filtering is performed using the distance between these edge points and the corresponding line segments, and those less than 10 mm are retained.

[0047] The pixel position of the retained edge point in the original depth map and the plane corresponding to the line segment are used to calculate the 3D position information of the point, and then the 3D position information of the point is used to locate the point perpendicular to the rough positioning large plane P i Projection to obtain a large plane SAP ij , for SAP ij Fit a straight line or arc to the point cloud in the image.

[0048] The fitting method described in step S8 may use the nearest enclosing hyperplane and a linear support vector machine. This patent further provides an envelope fitting method, comprising the following steps:

[0049] S801, SAP ij Each edge entity e i Including straight line l i and / or arc c i , traverse all line entities, for each line entity l i and its corresponding point set Given a control point u outside the model;

[0050] S802, given a set of spatial points and a single control point u, find two isolated parallel lines while maximizing the distance between the two lines; among the two lines, close to the point set The line of the nearest envelope is recorded as

[0051] S803, model current edge l i The normal direction is n, the nearest envelope straight line The normal direction is Calculate n and The angle bisector direction

[0052] S804, calculation point set The projection distance set h1,...,h in the n′ direction N , get the maximum value h in the projection set max and its corresponding point p max ;

[0053] S805, point set All the h i ≥h max -∈ points are selected, and if the number of these points is less than the set number threshold, p max From point set Delete, and repeat steps S801-S804;

[0054] S806, point set All the h i≥h max -γ points are selected to form a reliable point set

[0055] S807, repeat steps S804-S806 until all straight line entities l are obtained i Corresponding trusted registration point set These line entities and the corresponding point sets form a set of size N l The data container L;

[0056] S808, given data container All straight line entities in i and the corresponding set of trusted registration points Solve a global two-dimensional rotation matrix R and each linear entity l i The corresponding optimal displacement d i , so that the sum of the squares of the point-to-line distances between the rotated and offset straight line entity and its corresponding trusted registration point set is minimized;

[0057] S809, given point set and arc entity c, minimize the point set All points p i To the arc entity c to be estimated i The sum of the absolute distances; at the same time, all pixel points are required to be on one side of the arc, and the final center position is based on the initial positioning result In a square area with a center and a side length of η;

[0058] S810: Update endpoint data in parameterized descriptions of all edge entities.

[0059] SAP ij Parameter settings for each edge entity:

[0060] Each specific edge entity e i is a straight line entity l i 、arc c i or default entity v i ;

[0061] The line entity l includes the starting point x of the line la 、End point x lb and towards n, arc c includes the starting point x of the arc ca 、End point x cb , center o, radius r and concave and convex marker s;

[0062] The set of registration points corresponding to each edge entity

[0063] A two-dimensional Euclidean transformation A with three degrees of freedom, including a two-dimensional rotation R Aand the two-dimensional displacement t A ; For a two-dimensional point x, the transformation A takes the form A[x] = R A x+t A , the parametric description of the line l and arc c entities is converted into A[l] and A[c] under any two-dimensional Euclidean transformation.

[0064] The edge entity sequence corresponds to the front-to-back order of edge entities. For any two adjacent edge entities that are not default, they are connected end to end, that is, the end point of the former and the starting point of the latter are the same or the distance between the two is less than the tolerance threshold.

[0065] The global two-dimensional rotation matrix R of S808 transforms all linear entities l i The normal is updated to Rn i , traverse all updated entities, extract the next edge entity in the sequence, and use different update methods according to the types of the current and next edge entities.

[0066] Case 1: The current edge entity is a straight line l i , the next edge entity is the line l i+1 :Determine whether two straight lines are parallel. If so, calculate the straight line l i The original end point and the straight line l i+1 The average point y of the original starting point, after applying the global rotation, we get q = Ry, the straight line l i The end point is updated to q on the straight line l i The projection point on the straight line l i+1 The starting point is updated to q on the straight line l i+1 If not, calculate the intersection of the two lines and convert the line entity l i The end point of the line is updated to the intersection point, and the line entity l i+1 The starting point is updated to the intersection point.

[0067] Case 2: The current edge entity is a straight line l i , the next edge entity is arc c i+1 :Calculate the straight line l i With arc c i+1 If the number of intersections is zero, the straight line entity l i The end point is updated to arc c i+1 The center of the circle is on the line l i The projection point on the arc c i+1 The starting point of the arc is updated to the point in $o+nr$ and $o-nr$ that is closer to the original starting point of the arc, where r and o are the arc c i+1 The radius and center of the circle, n is the straight line l i Normal direction; if the intersection point is one, then the arc c i+1 The starting point and the line entity li The end point of the arc c is updated to the intersection point; if the number of intersection points is two, the distance between the two intersection points is determined, and if it is less than the threshold, the arc c i+1 The starting point and the line entity l i The end point is updated to the average point of the two intersection points. If it is greater than the threshold, the straight line l after the initial positioning update is selected. i The end point (or the original arc c i+1 The closer intersection point is the arc c. i+1 The starting point and the line entity l i The end point.

[0068] Case 3, the current entity is line l i , the next entity is the default v i+1 :The straight line l i The end point x lb After applying global rotation, we get q = Rx la , straight line l i The end point is updated to q on the straight line l i The projection point on .

[0069] Case 4, the current entity is the default v i , the next entity is the line l i+1 :The straight line l i+1 Starting point x la After applying global rotation, we get q = Rx la , straight line l i+1 The starting point is updated to q on the straight line l i+1 The projection point on .

[0070] Case 5, if the current entity is the default v i , the next entity is the default v i+1 :jump over.

[0071] Case 6, the current entity is the default v i , the next entity is arc c i+1 :The original starting point x of the arc a After the global optimal rotation transformation, we get q = Rx la , and then calculate the straight line and arc c passing through q and the center o i+1 The two intersection points will be closer to the original starting point x of the arc. ca The intersection point is updated to arc c i+1 The starting point.

[0072] Case 7, the current entity is arc c i , the next entity is arc c i+1 : Determine whether the two arcs intersect. If they do not intersect, calculate the straight line and arc c passing through the centers of the two circles iThe two intersection points will be away from the arc c i+1 The intersection point with a closer center is updated to c i The end point of the line is calculated. i+1 The two intersection points will be away from the arc c i The intersection point with a closer center is updated to c i+1 If they intersect, and there is only one intersection point or two intersection points are very close, then the two circles are determined to be tangent, and the intersection point or the average point of the two intersection points is updated as the arc c i+1 The starting point and c i Otherwise, it is determined that there are two independent intersection points between the two circles, and the independent intersection point closer to the original end point is updated to the arc c i The end point of the arc c is updated to the point closer to the original starting point. i+1 The starting point.

[0073] Case 8, the current entity is arc c i , the next entity is the line l i+1 : Same as case 2, only the current entity and the next entity need to be swapped.

[0074] Case 9, the current entity is arc c i , the next entity is the default v i+1 : Same as case six, just swap the current entity with the next entity.

[0075] This patent also provides a device or terminal for precise positioning of a planar workpiece, including one or more processors and a storage device; the storage device is used to store one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement any method for precise positioning of a planar workpiece provided by this patent.

[0076] This patent also provides a computer-readable storage medium, which stores a computer program. When the program is executed by a processor, it implements any planar workpiece precision positioning method provided by this patent.

[0077] Beneficial effects of the present invention:

[0078] The method for precise positioning of planar workpieces based on depth maps provided by the present invention directly uses the depth map data of a three-dimensional camera to achieve direct precise positioning of the planar workpiece in one shot, greatly improving the positioning efficiency. At the same time, it also solves the problem that workpieces with short sides cannot be positioned by line laser methods, thereby realizing intelligent precision machining. DETAILED DESCRIPTION

[0079] The specific embodiments described herein are only used to explain the technical solution of this patent, rather than to limit the disclosed technical solution. It should also be noted that, for ease of description, only the parts related to the disclosed technical solution are shown in the drawings, rather than all structures.

[0080] Before discussing the exemplary embodiments in more detail, it should be mentioned that the structures of the device components and / or modules themselves mentioned in the embodiments, if not described in detail, are understandable to those skilled in the art based on the existing public technology or commercially available products.

[0081] This embodiment provides a planar workpiece precision positioning method, comprising the following steps:

[0082] S1, use the 3D vision sensor to obtain the depth map data D of the workpiece i ; The N workpiece drawings that need to be matched from the database are denoted as D j (j=1, 2,…, n).

[0083] S2, depth map data D i , perform K clustering of connected areas in two dimensions and obtain the point set A of the depth map of the K connected areas i (i=1, 2, ...k).

[0084] S3, point set A for a single workpiece i Perform plane fitting to obtain the fitting plane P i (i=1, 2, ...k); and A i All points on the point set are in accordance with the corresponding P i Normal, projected to the corresponding P i On the plane, get the point set B of the plane i (i=1, 2, ...k).

[0085] S4, using the two-dimensional contour matching method, i Perform contour matching to obtain j The point set C whose matching degree in the drawing is higher than the evaluation score threshold i (l may be an empty set, indicating that there are no qualified workpieces on the table; it may contain one element or multiple elements. The number of elements in l represents the number of workpieces within the field of view of the table that meet the drawing form in the drawing library) and is recorded with C i The corresponding drawing D ij In P i On the plane with C i The relative position relationship matrix T i .

[0086] S5, for D ijIn the middle drawing outline, first break it according to the nodes to obtain the line segment (including straight line segments and arc segments) set S ij .

[0087] S6, for S ij The straight lines and / or arcs in T i The transformed edge is denoted as ST ij , in the corresponding A i element In the point set, find the points within the threshold range around each edge and register these points on the corresponding edge.

[0088] S7, plane fitting and filtering are performed on the points registered on each edge in S6 to obtain the point cloud set SA ij , will SA ij Normal vector V fitted to the internal element plane ij Projection to P i On the plane, obtain the plane point cloud set SA after processing and projecting according to the edge of the workpiece i P ij .

[0089] S8, using the plane linear programming method to calculate SA i P ij Fit straight lines and / or arcs to the point cloud in the image.

[0090] S9, divide the edge after S8 fitting into sections according to -V ij Project back to the original plane to get the updated edge STP in the depth map ij ;

[0091] S10 vs STP ij Extend, connect and trim the broken lines in the figure to make them into a closed contour.

[0092] The clustering method of step S2 may include the following steps:

[0093] S201, divide the depth map into blocks of size n×m, select one suitable point in each block as the seed point, and ensure that there are at least 12 pixels with valid depth values ​​in the neighborhood of the point with a distance of 2 (the diagonal distance is also 1); the values ​​of n and m are adjusted according to the original image resolution and the corresponding physical resolution, and can also be adjusted according to the specific application. For example, the camera used is 4096*3072 (12 million pixel resolution), and the seed value is 50x50 pixels. If the block is too large, the number of the final k clusters may be insufficient; if the block is too small, the amount of calculation is large, and some continuous noise may be obtained. This patent believes that a value of 1%-2% of the single-sided resolution is feasible.

[0094] S202, taking the seed point as the center point, searching for pixel points in a neighborhood with a distance of 3, and putting points whose three-dimensional distance to the center point is less than a threshold into this class; then iterating the above operation for points in this class that have not been searched as the center point, until the entire class cannot be expanded in the depth map;

[0095] S203, repeating S202 operation for the seed points in the remaining blocks in any order. If the pixel where the seed point is located is already occupied by the class of the previous seed point, skip this seed point;

[0096] S204, when the number of clusters finally obtained is less than the number of blocks, clusters with too few points are eliminated to ensure the quality of clustering.

[0097] The connected area k described in step S2 includes effective workpieces and other interferences, and may also include background, workbench, pads, etc. Therefore, a more preferred method is to pre-subtract the photographing background and / or distance threshold background from the depth map before processing the clustering data to reduce the amount of clustering calculations; at the same time, the elimination of the background can reduce the amount of calculations for subsequent matching, that is, the number of connected areas of non-workpieces obtained by clustering is reduced.

[0098] This embodiment provides a method for pre-removing the background of a photo:

[0099] In the depth map, the horizontal axis is set to i, and the vertical axis is set to j. The depth value is od ij , in the background depth map corresponding to the coordinate, calculate the difference between the depth value of the surrounding circle and the depth value, and take the minimum value If the value is less than the threshold th, the point is considered to belong to the background; otherwise, it does not.

[0100] This embodiment provides a method for pre-subtracting the distance threshold background:

[0101] 1) Take any point (x, y, z) on a plane in a 3D space that satisfies Ax+By+Cz+D=0, and represent the plane with (A, B, C, D);

[0102] 2) In the three-dimensional sensor coordinate system, find a plane plane0(A0, B0, C0, D0), where C0>0, so that the workpiece is below the plane and the other objects are above the plane;

[0103] 3) In the depth map, each pixel is converted into the position (x, y, z) in the 3D sensor coordinate system using the 3D sensor internal parameters, and the distance of each point from plane0

[0104] Keep satisfied ij The remaining points that are less than 0 are deleted as background.

[0105] After preprocessing, each remaining connected area is a workpiece (due to process requirements, the default distance between workpieces is not less than 100 mm).

[0106] The plane fitting described in S3 can be performed using the Ransac+ least squares method. The inner point distance threshold is set to 5 mm.

[0107] The Ransac+ least squares plane fitting steps include:

[0108] 1) First use the Ransac (Random Sample Consensus) algorithm to fit the plane. The basic assumption of the RANSAC algorithm is that the sample contains correct data (inliers, data that can be described by the model) and abnormal data (outliers, data that deviates far from the normal range and cannot fit the mathematical model). The basic principle of the algorithm is to perform a certain number of iterations. Each iteration will randomly select several sample points to calculate the mathematical model, and calculate the distance of all points from the mathematical model. Points within the threshold are called inliers, otherwise they are outliers. Finally, the mathematical model used in the iteration with the highest inlier rate will be selected as the final fitting result;

[0109] 2) After obtaining the plane with the highest inlier rate, all inliers are used to fit the plane using the least square method. The least square method (also known as the least square method) is a mathematical optimization technique. It finds the best function match for the data by minimizing the sum of squares of errors. The least square method can be used to easily obtain unknown data and minimize the sum of squares of errors between the obtained data and the actual data. This patent uses the least square method to fit the plane by minimizing the sum of squares of the distances of the points from the plane.

[0110] Preferably, before projection, each element of the Ai point set is filtered. The filtering can be performed by comparing the points in the point set with the Ransac plane P i Distance threshold method to obtain the updated A i Point set.

[0111] The two-dimensional contour matching method described in step S4 preferably adopts a multi-layer image pyramid method based on an image template. More preferably, the multi-layer image pyramid search method provided by this system is adopted, including: S401 performing full-image derivation of the template image and the workpiece image to obtain a gradient map, and normalizing the gradient direction; S402 moving the template image in the entire workpiece image, calculating the dot product of the gradient of each pixel in the template and the gradient of the current corresponding image pixel, and taking the sum of the dot products as the similarity score, sorting the similarity scores, and obtaining the preliminary positioning of the workpiece; S403 further adjusting with the NCC algorithm until the search of all pyramid layers is completed to obtain the final position of the workpiece.

[0112] In order to improve the search speed, this embodiment further provides a template data algorithm, which directly samples the template contour from the json file, samples one point for each pixel along the direction of the entity; and calculates the ideal gradient direction of each sampling point (perpendicular to the direction pointing outward from the entity), and stores the sampling point and the corresponding gradient in two vectors in the form of Eigen::Vector2f. The function for generating template data is: genMatchModelData (specifically implemented in DxfModel-Gen2DModel). In the prior art, template data is usually generated from a json file to generate a model image in the cv::Mat format, and the generated template image is subjected to sobel gradient detection, distance transformation and other operations. Using the method of this embodiment, the template data no longer needs to call opencv to perform sobel gradient detection, distance transformation and other operations.

[0113] The present embodiment also provides a template data processing method to further improve the search speed, that is, the template data is not sampled, and the template data is directly screened at a specified interval according to the number of layers of the pyramid, and converted into the Eigen::Matrix form. For example, the matching interval at the 6th layer is 32, the 5th layer is 16, and so on, and the last layer interval is 1. Before matching, the data is screened to reduce the memory and data transmission time, and converted into the Eigen::Matrix form, which is convenient for subsequent rotation and translation transformation. The existing pyramid search method is to first perform pyramid downsampling on the template image, and then perform gradient transformation, distance transformation, etc. on the downsampled image, and the pyramid needs to be repeated several times according to the number of layers. The applicant has found that directly screening the template data at a specified interval according to the number of layers of the pyramid does not need to downsample the template data, and can also avoid repeated operations such as sobel transformation and gradient transformation, thereby reducing a lot of data processing time.

[0114] This embodiment provides a template transformation method, which does not require the extraction of a template point set for each transformation, reduces the tedious calculation of multiple library calls, and simplifies the algorithm. The method is: each time you scale or rotate, find the corresponding two-dimensional transformation matrix M, multiply this transformation matrix with the filtered template data in the form of Eigen::Matrix2Xf, and you can get the template data after scale transformation and rotation transformation. The transformed template data is directly calculated with the corresponding image for similarity. The existing public method is that each time you scale, you need to resize the current template, and each time you rotate, you also need to call the opencv library to obtain the transformation matrix and perform an affine transformation. And for SHAPE_MATCH, its gradient image is required after each transformation, and for DST_MATCH, its image after distance transformation is required.

[0115] The embodiment of the present invention also provides a template positioning method: the output is a transformation matrix of Eigen::Matrix4f, and only the scaling, rotation, and translation transformation matrices that meet the conditions are recorded; when visually displayed, only the transformation matrix is ​​multiplied with the template point set in the form of Eigen::Matrix. The calculation is convenient and more intuitive. The existing known template positioning method is to select a reference point before transformation, and track the position change of the reference point each time the transformation is performed until the optimal solution is found. The output positioning parameters are the transformation scale, rotation angle, and translation distance in the x and y directions, a total of 4 position parameters. This method is more complicated than the method provided by this patent, and cannot be directly transformed. When visualizing it, it needs to be calculated separately.

[0116] When searching the highest level of the known pyramid, the scale of the outermost loop is transformed multiple times, and each scale transformation requires a scale transformation, and the image is traversed with a template. The applicant unexpectedly found that by fixing the scale transformation of the highest level of the pyramid and expanding the range of the size transformation during precise positioning, the matching effect accuracy did not deteriorate, but the amount of calculation was reduced by 5 times. Therefore, fixing the scale transformation of the highest level of the pyramid can directly reduce the amount of calculation and speed up the search.

[0117] In addition, multithreading is added to the top-level pyramid search. While ensuring the independence of each transformation and parameter in the algorithm, multiple rotation and translation transformations are searched and similarity is calculated at the same time, which improves the speed more significantly. Multithreading can also be added to the local hierarchical search. Similarly, while ensuring the independence of each transformation and parameter in the algorithm, the templates selected by the top-level search are searched locally at the same time, which also significantly improves the speed.

[0118] The line segments described in step S5 generally include straight line segments and circular arc segments, which can be further ij The length of the midline segment is calculated, divided by the length threshold Tr, and the result is added by 1. The straight line or arc is evenly divided and interrupted according to this result, and re-recorded in S ij In. S ij The 2D position of each line segment in the rough positioning plane is obtained through step S6.

[0119] This embodiment provides a step S6 for S ij The midline segment processing method comprises the following steps:

[0120] S601, for the straight line segment, set a rectangular ROI, the length direction of the rectangle is parallel to the straight line segment, the length value is equal to the length of the straight line segment + 100 pixels, the width value is equal to 100 pixels, and the straight line segment is the center;

[0121] S602, for the arc segment, a partial annular area is used to represent it, wherein the inner diameter of the annular area is the arc radius - 50 pixels, if it is less than 0, it is a sector; the outer diameter is the arc radius + 50 pixels; the starting angle of the sweep is the arc segment starting angle - 3°, and the ending angle is the arc segment ending angle + 3°;

[0122] S603, traverse each pixel point on the depth map, flatten the pixel point to the plane through perspective transformation, calculate the position of the pixel point on the plane, and then use S ij The ROI of each line segment in is compared; if the position is in a certain line segment ROI, the pixel point in the matched depth map is registered to the corresponding line segment.

[0123] Fit the plane to the point set of each line segment obtained in S6, record it, and perform distance filtering on the point set to remove points that are more than 2 mm away from the plane. Perform edge extraction on the pixel mask of the filtered point set on the original depth map. After all edge points are extracted, use the distance of these edge points from the corresponding line segment to filter, and retain those less than 10 mm. Use the pixel position of the retained edge point in the original depth map and the plane corresponding to the line segment to calculate the 3D position information of the point, and then use the 3D position information of the point to locate the point perpendicular to the rough positioning large plane P. i Projection to obtain a large plane SAP ij All edge points processed in this way are regarded as points that can be optimized with the standard model and enter the optimization step S8.

[0124] ST ij With SAP ij , both located in P i On the plane, and with the corresponding relationship between the point cloud registration on the edge, the linear programming method of the plane can be used to use different fitting methods for the straight line and the arc, respectively, for SAP ij Fitting a point cloud in the image is done by straight line or arc fitting. The fitting method can be the nearest enclosing hyperplane and linear support vector machine.

[0125] About SAP ij The present embodiment provides an envelope fitting method for performing straight line or arc fitting on the point cloud in the image, comprising the following steps:

[0126] S801, SAP ij Each edge entity e i Including straight line l i and / or arc c i , traverse all line entities, for each line entity l i and its corresponding point set Given a control point u outside the model;

[0127] S802, given a set of spatial points and a single control point u, find two isolated parallel lines while maximizing the distance between the two lines; among the two lines, close to the point set The line of the nearest envelope is recorded as

[0128] S803, model current edge l i The normal direction is n, the nearest envelope straight line The normal direction is Calculate n and The angle bisector direction

[0129] S804, calculation point set The projection distance set h1,...,h in the n′ direction N , get the maximum value h in the projection set max and its corresponding point p max ;

[0130] S805, point set All the h i ≥h max -∈ points are selected, and if the number of these points is less than the set number threshold, p max From point set Delete, and repeat steps S801-S804;

[0131] S806, point set All the h i ≥h max -γ points are selected to form a reliable point set

[0132] S807, repeat steps S804-S806 until all straight line entities l are obtained i Corresponding trusted registration point set These line entities and the corresponding point sets form a set of size N l Data container

[0133] S808, given data container All straight line entities in i and the corresponding set of trusted registration points Solve a global two-dimensional rotation matrix R and each linear entity l i The corresponding optimal displacement d i , so that the sum of the squares of the point-to-line distances between the rotated and offset straight line entity and its corresponding trusted registration point set is minimized;

[0134] S809, given point set and arc entity c, minimize the point set All points p i To the arc entity c to be estimated i The sum of the absolute distances; at the same time, all pixel points are required to be on one side of the arc, and the final center position is based on the initial positioning result In a square area with a center and a side length of η;

[0135] S810: Update endpoint data in parameterized descriptions of all edge entities.

[0136] SAP ij Parameter settings for each edge entity:

[0137] Each specific edge entity e i is a straight line entity l i 、arc c i or default entity v i ;

[0138] The line entity l includes the starting point x of the line 1a 、End point x 1b and towards n, arc c includes the starting point x of the arc ca 、End point x cb , center o, radius r and concave and convex marker s;

[0139] The set of registration points corresponding to each edge entity

[0140] A two-dimensional Euclidean transformation A with three degrees of freedom, including a two-dimensional rotation R A and the two-dimensional displacement t A ; For a two-dimensional point x, the transformation A takes the form A[x] = R A x+t A , the parametric description of the line l and arc c entities is converted into A[l] and A[c] under any two-dimensional Euclidean transformation.

[0141] The edge entity sequence corresponds to the front-to-back order of edge entities. For any two adjacent edge entities that are not default, they are connected end to end, that is, the end point of the former and the starting point of the latter are the same or the distance between the two is less than the tolerance threshold.

[0142] The global two-dimensional rotation matrix R of S808 transforms all linear entities l i The normal is updated to Rn i , traverse all updated entities, extract the next edge entity in the sequence, and use different update methods according to the types of the current and next edge entities.

[0143] Case 1: The current edge entity is a straight line l i, the next edge entity is the line l i+1 :Determine whether two straight lines are parallel. If so, calculate the straight line l i The original end point and the straight line l i+1 The average point y of the original starting point, after applying the global rotation, we get q = Ry, the straight line l i The end point is updated to q on the straight line l i The projection point on the straight line l i+1 The starting point is updated to q on the straight line l i+1 If not, calculate the intersection of the two lines and convert the line entity l i The end point of the line is updated to the intersection point, and the line entity l i+1 The starting point is updated to the intersection point.

[0144] Case 2: The current edge entity is a straight line l i , the next edge entity is arc c i+1 :Calculate the straight line l i With arc c i+1 If the number of intersections is zero, the straight line entity l i The end point is updated to arc c i+1 The center of the circle is on the line l i The projection point on the arc c i+1 The starting point of the arc is updated to the point in $o+nr$ and $o-nr$ that is closer to the original starting point of the arc, where r and o are the arc c i+1 The radius and center of the circle, n is the straight line l i Normal direction; if the intersection point is one, then the arc c i+1 The starting point and the line entity l i The end point of the arc c is updated to the intersection point; if the number of intersection points is two, the distance between the two intersection points is determined, and if it is less than the threshold, the arc c i+1 The starting point and the line entity l i The end point is updated to the average point of the two intersection points. If it is greater than the threshold, the straight line l after the initial positioning update is selected. i The end point (or the original arc c i+1 The closer intersection point is the arc c. i+1 The starting point and the line entity l i The end point.

[0145] Case 3, the current entity is line l i , the next entity is the default v i+1 :The straight line l i The end point x 1b After applying global rotation, we get q = Rx 1a , straight line l i The end point is updated to q on the straight line l iThe projection point on .

[0146] Case 4, the current entity is the default v i , the next entity is the line l i+1 :The straight line l i+1 Starting point x 1a After applying global rotation, we get q = Rx 1a , straight line l i+1 The starting point is updated to q on the straight line l i+1 The projection point on .

[0147] Case 5, if the current entity is the default v i , the next entity is the default v i+1 :jump over.

[0148] Case 6, the current entity is the default v i , the next entity is arc c i+1 :The original starting point x of the arc a After the global optimal rotation transformation, we get q = Rx 1a , and then calculate the straight line and arc c passing through q and the center o i+1 The two intersection points will be closer to the original starting point x of the arc. ca The intersection point is updated to arc c i+1 The starting point.

[0149] Case 7, the current entity is arc c i , the next entity is arc c i+1 : Determine whether the two arcs intersect. If they do not intersect, calculate the straight line and arc c passing through the centers of the two circles i The two intersection points will be away from the arc c i+1 The intersection point with a closer center is updated to c i The end point of the line is calculated. i+1 The two intersection points will be away from the arc c i The intersection point with a closer center is updated to c i+1 If they intersect, and there is only one intersection point or two intersection points are very close, then the two circles are determined to be tangent, and the intersection point or the average point of the two intersection points is updated as the arc c i+1 The starting point and c i Otherwise, it is determined that there are two independent intersection points between the two circles, and the independent intersection point closer to the original end point is updated to the arc c i The end point of the arc c is updated to the point closer to the original starting point. i+1 The starting point.

[0150] Case 8, the current entity is arc c i , the next entity is the line l i+1 : Same as case 2, only the current entity and the next entity need to be swapped.

[0151] Case 9, the current entity is arc c i , the next entity is the default v i+1 : Same as case six, just swap the current entity with the next entity.

[0152] S10 STP 1j Extend the broken line in the figure to both ends, find the closest point of the two adjacent extended lines, move the end nodes (Knot) or control points (Control point) of the original two broken lines to the closest point, because the two adjacent broken lines are connected at this point, a closed contour can be formed. For the error caused by this step, since the lines are originally at the same point in the physical world, the broken lines are caused by visual accuracy and fitting errors, so the maximum error is no higher than the visual error, which can meet the actual processing requirements.

[0153] This patent also provides a device or terminal for precise positioning of a planar workpiece, including one or more processors and a storage device; the storage device is used to store one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement any method for precise positioning of a planar workpiece provided by this patent.

[0154] This patent also provides a computer-readable storage medium, which stores a computer program. When the program is executed by a processor, it implements any planar workpiece precision positioning method provided by this patent.

[0155] It is understandable to those skilled in the art that all or part of the steps / functions provided by the method of the above-mentioned embodiment can be implemented by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium. When the program is executed, it includes one of the steps in the method or various combinations thereof.

[0156] The above is an example of the preferred implementation of the present invention, but the invention is not limited to the embodiments. Those skilled in the art can make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of this application.

Claims

1. A method for precise positioning of a planar workpiece, comprising the following steps: S1, use the 3D vision sensor to obtain the depth map data D of the workpiece i ; The N workpiece drawings that need to be matched from the database are denoted as D j ; S2, depth map data D i , perform K clustering of connected areas in two dimensions and obtain the point set A of the depth map of the K connected areas i ; S3, point set A for a single workpiece i Perform plane fitting to obtain the fitting plane P i ; and A i All points on the point set are in accordance with the corresponding P i Normal, projected to the corresponding P i On the plane, get the point set B of the plane i ; S4, using the two-dimensional contour matching method, i Perform contour matching to obtain j The point set C whose matching degree in the drawing is higher than the evaluation score threshold i , and record with C i The corresponding drawing D ij In P i On the plane with C i The relative position relationship matrix T i ; S5, for D ij In the middle drawing outline, first break it according to the nodes to obtain the line segment set S ij ; S6, for S ij The straight lines and / or arcs in T i The transformed edge is denoted as ST ij , in the corresponding A i In the element point set, find the points within the threshold range around each edge and register these points on the corresponding edge; S7, plane fitting and filtering are performed on the points registered on each edge in S6 to obtain the point cloud set SA ij , will SA ij Normal vector V fitted to the internal element plane ij Projection to P i On the plane, obtain the plane point cloud set SA after processing and projecting according to the edge of the workpiece i P ij ; S8, using the plane linear programming method to calculate SA i P ij Fitting straight lines and / or arcs to the point cloud in the image; S9, divide the edge after S8 fitting into sections according to -V ij Project back to the original plane to get the updated edge STP in the depth map ij ; S10 vs STP ij Extend, connect and trim the broken lines in the figure to make them into a closed contour.

2. The method for precise positioning of a planar workpiece according to claim 1, characterized in that: Step S2, the clustering method comprises the following steps: S201, divide the depth map into multiple blocks, select one suitable point in each block as a seed point, and ensure that at least 12 pixels in the neighborhood of the point with a distance of 2 have valid depth values; S202, use the seed point as the center point, find the pixel points in the neighborhood of a distance of 3, and put the points whose three-dimensional distance to the center point is less than the threshold into this class; then iterate the above operation for the points in this class that have not been searched as the center point, until the entire class cannot be expanded in the depth map; S203, repeating S202 operation for the seed points in the remaining blocks in any order. If the pixel where the seed point is located is already occupied by the class of the previous seed point, skip this seed point; S204, when the number of clusters finally obtained is less than the number of blocks, clusters with too few points are eliminated to ensure the quality of clustering.

3. The method for precise positioning of a planar workpiece according to claim 1, characterized in that: Before processing the cluster data in step S2, the photographing background and / or the distance threshold background are pre-subtracted from the depth map.

4. The method for precise positioning of a planar workpiece according to claim 1, characterized in that: The plane fitting described in step S3 adopts the Ransac+least squares method, and the inner point distance threshold is set to 5 mm.

5. The method for precise positioning of a planar workpiece according to claim 1, characterized in that: The two-dimensional contour matching method described in step S4 adopts a multi-layer image pyramid method based on image templates.

6. The method for precise positioning of a planar workpiece according to claim 5, characterized in that: The multi-layer image pyramid search method comprises: S401 performing full-image derivation on the template image and the workpiece image to obtain a gradient image, and normalizing the gradient direction; S402 moving the template image in the entire workpiece image, calculating the dot product of the gradient of each pixel in the template and the gradient of the current corresponding image pixel, taking the sum of the dot products as a similarity score, sorting the similarity scores, and obtaining a preliminary positioning of the workpiece; S403 further adjusting using the NCC algorithm until the search of all pyramid layers is completed to obtain the final position of the workpiece.

7. The planar workpiece precise positioning method according to claim 1, characterized in that: Step S6: ij The midline segment processing methods include: S601, for the straight line segment, set a rectangular ROI, the length direction of the rectangle is parallel to the straight line segment, the length value is equal to the length of the straight line segment + 100 pixels, the width value is equal to 100 pixels, and the straight line segment is the center; S602, for the arc segment, a partial annular area is used to represent it, wherein the inner diameter of the annular area is the arc radius - 50 pixels, if it is less than 0, it is a sector; the outer diameter is the arc radius + 50 pixels; the starting angle of the sweep is the arc segment starting angle - 3°, and the ending angle is the arc segment ending angle + 3°; S603, traverse each pixel point on the depth map, flatten the pixel point to the plane through perspective transformation, calculate the position of the pixel point on the plane, and then use S ij The ROI of each line segment in is compared; if the position is in a certain line segment ROI, the pixel point in the matched depth map is registered to the corresponding line segment.

8. The planar workpiece precise positioning method according to claim 1, characterized in that: The filtering described in step S7 first refers to removing points in the point set that are more than 2 mm away from the plane; edge extraction is performed on the pixel mask of the filtered point set on the depth map. After all edge points are extracted, filtering is performed using the distance between these edge points and the corresponding line segments, and those less than 10 mm are retained.

9. A device or terminal for precise positioning of a planar workpiece, comprising one or more processors and a storage device; the storage device is used to store one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the method for precise positioning of a planar workpiece as described in any one of claims 1-8.

10. A computer-readable storage medium storing a computer program, wherein the program, when executed by a processor, implements the planar workpiece precise positioning method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Groove cutting method and system based on workpiece shape and character recognition

    CN121259016A