A method for calculating the volume of cubic objects by removing noise based on depth images
Through the noise removal method based on depth images, the edge lines and corner points of cubic objects are extracted, a three-dimensional plane is fitted, and its volume is calculated. This solves the limitations and time-consuming problems of volume measurement of cubic objects in the logistics industry, and achieves fast and accurate measurement. Volume measurement improves parcel sorting efficiency.
Patent Information
- Application Number
- CN201910989812.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-10-17
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2039-10-17
AI Technical Summary
Existing technology has limitations and time-consuming problems in measuring the volume of cubic packages, goods, containers, etc. in the logistics industry. Especially in scenarios where packages are densely accumulated, the detection error is large and cannot meet actual needs.
A noise-removing cube object volume calculation method based on depth images is adopted. By obtaining the gradient map and edge point map of the depth image, edge line detection and clustering are performed, corner points are extracted and paired, a three-dimensional plane is fitted, and noise points are removed. Calculate the length, width and height of a cubic object to calculate its volume.
It achieves fast and accurate volume measurement of cubic objects, improves detection stability and accuracy, solves the limitations and time-consuming problems of volume measurement in traditional methods, and improves the efficiency of parcel sorting in the logistics industry.
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cubic object recognition of depth images, and in particular to a cubic object volume calculation method based on depth images and eliminating noise. Background Art
[0002] Depth images, also known as distance images, refer to images that use the distance from the image collector to each point in the scene as the pixel value. They directly reflect the geometric shape of the visible surface of a cubic object. Therefore, depth images are widely used, especially in the logistics industry. At present, the throughput of domestic logistics, port shipping, and airport shipping is very large and increasing. The measurement of the volume of parcels, goods, containers, etc. by various sorting centers is relatively limited and time-consuming, which reduces transportation efficiency.
[0003] In the prior art, most packages are in the shape of cubic objects. The volume of the package is mainly measured by comparing the depth images of the conveyor belt before and after loading, extracting the rectangular area where the package is located to obtain the length and width of the package, and using the difference features to obtain the height of the package to calculate the volume of the package. This method is limited to specific scenarios and has a small scope of application. It cannot meet the needs of dense stacking of packages in the actual logistics industry. In addition, most of the prior art requires the camera to shoot objects vertically, which has great restrictions on the camera shooting angle, and can basically only detect a single object, and the detection error of multiple objects is large. At present, the volume measurement of large goods and containers is basically carried out by manual measurement. Summary of the invention
[0004] In order to solve the problem of limitation and time-consuming volume measurement of cubic objects such as cubic packages, goods, containers, etc. in the prior art, the present invention proposes a method for calculating the volume of cubic objects based on depth images.
[0005] The technical solution of the present invention is achieved in this way:
[0006] A method for calculating the volume of a cubic object by removing noise based on a depth image, comprising:
[0007] S1. Obtain a depth image of a cubic object, and obtain gradient maps of the same size in the X and Y directions according to the depth image; S2. Classify the pixels in the gradient map into three categories: horizontal plane, left vertical plane and right vertical plane, and obtain an edge point map of the depth image; S3. Obtain segmented images of the upper surface, left vertical plane and right vertical plane of the cubic object in the depth image according to the classification results, the gradient map and the edge point map; S4. Perform edge line detection on the edge point map, cluster and merge all detected edge lines, and obtain a set of collinear edge line groups; S5. Extract corner points according to the longest edge line of each group of collinear edge line groups; S6. Points are paired; S7, the upper surface and the overall contour of the cubic object are determined according to the acquired quadrilateral and upper surface segmentation images, and the left and right vertical planes corresponding to each upper surface quadrilateral are obtained according to the segmentation image of the left vertical plane and the right vertical segmentation image, so as to realize the positioning of the cubic object; S8, the plane of the cubic object in the three-dimensional space is fitted according to the upper surface, the left vertical plane and the right vertical plane, and the noise points on each surface are eliminated by repeated fitting to obtain the ideal point set corresponding to each surface; S9, the contour boundary and corner points of each surface are obtained according to the ideal point set of each surface, the length, width and height of the cubic object are obtained according to the coordinates of its corner points in the three-dimensional space, and the volume of the cubic object is calculated.
[0008] Preferably, the specific method of obtaining the segmented images of the upper surface, left vertical surface and right vertical surface of the cubic object in the depth image according to the classification results, the gradient map and the edge point map is as follows: according to the classification results, obtain the binary images of the horizontal plane, the left vertical surface and the right vertical surface of the same size as the gradient map, define the upper surface segmented image of the same size as the gradient map, and set the initial value of the pixel to 0; traverse the pixels in the first column of the binary image of the horizontal plane from bottom to top, obtain the credibility value of each pixel according to the depth map, give a credibility threshold, if the credibility value of the pixel is less than the given credibility threshold, the state of the pixel is unknown, and the next pixel is processed; otherwise, if the corresponding pixel value is 255, the state of the pixel is horizontal, if the corresponding pixel is 0, the state of the pixel is vertical, if the number of pixels with a pixel value of 0 is greater than a given height threshold, then the pixels with a pixel value of 255 that appear later are mapped to the upper surface segmented image and their pixel values are updated to 255, and each pixel state change is recorded. The number of rows where the pixel point to be transformed is located. After traversing the pixel points of all rows in the first column, the pixel values of all pixel points in the first column from the recorded number of rows to the first row corresponding to the position on the upper surface segmentation image are set to 0. In the same way, all rows and columns of the parallel surface image are traversed to obtain the initial upper surface segmentation image, and the initial upper surface segmentation image is repaired to update the upper surface segmentation image; the edge points in the edge point map are respectively mapped one by one to the updated upper surface segmentation image, the binary image of the left vertical surface, and the right vertical surface. In the binary image of the vertical surface, the pixel values of the horizontal non-edge points in the updated upper surface segmentation image are updated to 0, the pixel values of the non-edge points in the binary image of the left vertical surface with a pixel value of 255 are updated to 0, and the pixel values of the non-edge points in the binary image of the right vertical surface with a pixel value of 255 are updated to 0, so as to obtain the final upper surface segmentation image, the binary image of the left vertical surface and the binary image of the right vertical surface, and record the binary image of the left vertical surface and the binary image of the right vertical surface as the segmentation image of the left vertical surface and the segmentation image of the right vertical surface, respectively.
[0009] Preferably, edge line detection is performed on the edge point graph, and all detected edge lines are clustered and merged. The specific method for obtaining the collinear edge line group set is as follows: edge line detection is performed on the edge point graph, all edge lines are obtained and sorted into edge line sets from long to short, an empty collinear edge line group set is defined, the collinear edge line group set contains multiple groups of edge lines, the edge lines in each group are collinear, and the edge lines between two groups are not collinear, firstly, the longest edge line is added to one group of the collinear edge line group set, for each A edge line in the edge line set, it is determined whether it is collinear with the longest B edge line in each group of the collinear edge line group set, and the determination conditions are as follows:
[0010] C1. Calculate the angle difference between edge line A and edge line B, and determine whether the angle difference is less than or equal to a given angle difference threshold value e;
[0011] C2. If the angle difference is less than or equal to the angle difference threshold e, calculate the distances T1 and T2 from the start point of edge line B to the start point and end point of edge line A, and the distances T3 and T4 from the end point of edge line B to the start point and end point of edge line A. Given the point distance threshold G, determine whether the minimum distance among the distances T1, T2, T3 and T4 is less than or equal to the point distance threshold G.
[0012] C3. If min(min(T1, T2), min(T3, T4))≤G, calculate the length L of edge line A and the length H of edge line B, and determine whether the maximum distance among distances T1, T2, T3 and T4 is less than G+H+L;
[0013] C4. If max(max(T1, T2), max(T3, T4))<(G+H+L), calculate the distances S1 and S2 from the start and end points of edge line B to edge line A, and the distances S3 and S4 from the start and end points of edge line A to edge line B. Given a distance threshold J, if the maximum distance between T1 and T2 is less than L+G, determine whether S1 is less than or equal to J; if the maximum distance between T3 and T4 is less than L+G, determine whether S2 is less than or equal to J; if the maximum distance between T1 and T3 is less than L+G, determine whether S3 is less than or equal to J; if the maximum distance between T2 and T4 is less than L+G, determine whether S4 is less than or equal to J; if any maximum distance is greater than or equal to L+G, directly execute the next step;
[0014] C5. If the condition in C4 is met, the edge line A and the edge line B are collinear, and the edge line A is added to the group of the collinear edge line group set, and the edge line of the group is updated;
[0015] During the judgment process, if any condition is not met, the longest edge line of the next group in the collinear edge line group set is directly processed until all groups in the collinear edge line group set are processed, and each group of edge lines is represented by its longest edge line. If edge line A is not collinear with the longest edge lines of all groups in the collinear edge line group set, edge line A is directly added to the new group in the collinear edge line group set, and the number of groups in the collinear edge line group set is updated; after edge line A and edge line B are collinear, it is determined whether edge line A and edge line B meet the merging condition. If T1≤H, T2≤H, T3≤H and T4≤H, edge line A and edge line B do not meet the merging condition, otherwise, edge line A and edge line B are merged, the starting point and end point of edge line B are updated, and the collinear edge line group set is updated; the next edge line in the edge line set is processed in the same way as edge line A, and the collinear edge line group set is continuously updated. The edge lines of each group in the collinear edge line group set are sorted by length to obtain the final collinear edge line group set.
[0016] Preferably, the specific method of extracting corner points according to the longest edge line of each group of collinear edge line groups is:
[0017] C1. Get the longest edge line of each group of collinear edge line groups, record it as the seed edge line set, sort all the edge lines of the seed edge line set from long to short, traverse all the edge lines of the seed edge line set, and start from the longest C edge line to calculate the angle a between it and any other D edge line, where a ranges from 0 to 180 degrees. Given a curvature threshold b, determine whether min (a, 180-a) is greater than b;
[0018] C2. If min(a, 180-a)>b, calculate the intersection point W(Wx, Wy) of the edge line C and the edge line D, and determine whether Wx or Wy does not exceed the image range;
[0019] C3. If Wx or Wy does not exceed the image range, determine whether the intersection W is a corner point. The condition for determining whether the intersection W is a corner point is as follows: first calculate the distances d1 and d2 from the two endpoints of the C edge line to the intersection W, and define the minimum distance min_d1. If the intersection W is between the two endpoints of the C edge line, then min_d1=0, otherwise min_d1=min(d1, d2). If the minimum distance min_d1 is not 0 or min(d1, d2) is less than the given arm length threshold Z1, then calculate the distances d3 and d4 from the two endpoints of the D edge line to the intersection W, and define the minimum distance min_d2. If the intersection W is between the two endpoints of the D edge line, then min_d2=0, otherwise min_d2=min(d3, d4). If the minimum distance min_d2 is not 0 or min(d3, d4) is less than the given arm length threshold Z2, determine whether min(d1, d2) and min(d3, d4) are less than the given intersection radius threshold r.
[0020] C4. If the condition of C3 is met, given the threshold value v of the gap between the arms of the quadrilateral, determine whether max(min(d1, d2), min(d3, d4)) is less than or equal to v. If it is met, the intersection point W is the corner point of the quadrilateral. The conditions C1 to C4 are judged in turn. If any condition is not met, the next edge line is processed. The first corner point obtained is added to the corner point set. For the remaining corner points obtained, the distance L between them and all corner points in the corner point set is calculated. i , i is a variable, judging whether it is similar to all corner points in the corner point set, if L i<r, and is not similar to the rest of the corner points, add the corner point to the corner point set; the intersection point W corresponds to two arms, the first arm is the line connecting it with the end point of the C edge line, the second arm is the line connecting it with the end point of the D edge line, the end point of the C edge line is the larger corresponding endpoint of d1 and d2 in the C edge line, and the end point of the D edge line is the larger corresponding endpoint of d3 and d4 in the D edge line; process any other two edge lines in the seed edge line group set in the same way to obtain all the corner points, expand the two arms of each corner point according to the seed edge line set, obtain the final corner point set, and realize corner point extraction.
[0021] Preferably, the specific method of pairing the extracted corner points is as follows: C1, pairing all corner points in the corner point set in pairs, if the coordinates of the two paired corner points are different, continue to determine whether the two corner points share an arm, mark the two arms of one corner point as arm11 and arm12, and the two arms of the other corner point as arm21 and arm22, first determine whether arm11 and arm21 are the same arm of the two corner points;
[0022] C2. The method of judging whether arm11 and arm21 are the same arm is as follows: if the distance between the two corner points is greater than one-fourth of the minimum value of arm11 and arm21, first calculate the absolute value x1 of the angle difference between arm11 and the line connecting the two corner points, and the absolute value x2 of the angle difference between arm21 and the line connecting the two corner points. The value range of x1 and x2 is [0, 180]. Given an angle similarity threshold f, if both x1 and x2 are less than the angle similarity threshold f, given a corner point distance threshold u and a length ratio threshold ratio, if the sum of the lengths of arm11 and arm21 is greater than or equal to ratio times the distance between the two corner points, and greater than or equal to the difference between the distance between the two corner points and u, then arm11 and arm21 are judged to be the same arm and the corner point pairing is successful.
[0023] Otherwise, the same method is used to determine whether the other two arms of the two corner points are the same arm. If neither is the case, the corner point pairing fails, otherwise the corner point pairing succeeds. The remaining corner points are paired in the same way to obtain all successfully paired corner point combinations. The same arm of each corner point combination is a shared arm, and the other two arms are open arms. The angles u1 and u2 between the two open arms and the shared arm in each corner point combination are calculated. The value range of the angles u1 and u2 is [0, 180]. The corner point combinations whose angles u1 or u2 are less than the curvature threshold b are eliminated. For the remaining corner point combinations, determine whether their two open arms are on the same side of the shared arm, and eliminate the corner point combinations whose two open arms are not on the same side of the shared arm. Finally, determine a quadrilateral based on the currently paired corner point combination. Process all corner point combinations in the same way to obtain all quadrilaterals.
[0024] Preferably, the specific method of determining the upper surface and the overall contour of the cubic object according to the acquired quadrilateral and upper surface segmentation images is:
[0025] C1. First, process the obtained quadrilateral. If the distance between the end points of the two arms of the matching quadrilateral is less than the given distance ratio threshold, the quadrilateral does not meet the requirements. Then process the next quadrilateral, obtain all the quadrilaterals that meet the requirements, and obtain the outline and circumscribed rectangle of each quadrilateral. Calculate its convex hull according to the outline coordinate points.
[0026] C2. Perform contour detection based on the upper surface segmentation image, obtain all contours, calculate their convex hulls based on the contour coordinate points, obtain the smallest rotated rectangle containing each contour and the circumscribed rectangle containing the rotated rectangle, calculate the area of each contour, and determine whether the area of the contour is greater than a given area threshold;
[0027] C3. If the area of the contour is greater than the area threshold, match the current contour with a qualified quadrilateral, calculate the minimum distances h1 and h2 from the two corner points of the matching quadrilateral to the convex hull of the current contour, and determine whether the two corner points of the matching quadrilateral are outside the convex hull of the matching quadrilateral and whether h1 and h2 are less than or equal to the given distance threshold;
[0028] C4. If the two corner points of the matching quadrilateral are outside the convex hull of the matching quadrilateral and h1 and h2 are both less than or equal to the distance threshold, determine whether the center point of the rotated rectangle outside the current contour is inside the convex hull of the matching quadrilateral;
[0029] C5. If the center point of the rotated rectangle outside the current contour is located inside the convex hull of the matching quadrilateral, calculate the absolute value of the minimum distance from the rotated rectangle to the convex hull of the matching quadrilateral, and satisfy the conditions that the value is less than or equal to the length and width of the rotated rectangle, and the center point is located on the lower side of any arm of the matching quadrilateral, calculate the overlapping area of the circumscribed rectangle of the matching quadrilateral and the circumscribed rectangle of the current contour, if the overlapping area is greater than a given ratio threshold, the current contour and the matching quadrilateral are preliminarily matched successfully, and the matching quadrilateral is recorded as the preliminarily matched quadrilateral;
[0030] C6. Normalize the distance from the center point of the rotated rectangle of the current contour to the three arms of the preliminary matching quadrilateral. If the normalized value is within the theoretical range and the sum of h1 and h2 is less than or equal to a given threshold, the preliminary matching quadrilateral is recorded as a valid quadrilateral.
[0031] C7. Determine whether the two open arms of the valid quadrilateral are facing downward, and record the valid quadrilateral with two open arms facing downward as a seed quadrilateral; if the next seed quadrilateral is obtained, calculate whether the sum of the minimum distances from the two corner points of the seed quadrilateral to its contour is less than the sum of the minimum distances from the two corner points of the previous seed quadrilateral to its contour, if so, replace the previous seed quadrilateral with the current seed quadrilateral, otherwise remove the current seed quadrilateral, and continue processing until the final seed quadrilateral of the current contour is obtained;
[0032] C8, determine whether the final seed quadrilateral of the current contour has shared corner points with the valid quadrilateral;
[0033] C9. If there is a shared corner point, determine whether the line segments where the shared arms and open arms of the valid quadrilateral are located overlap with the line segments where the shared arms of the seed quadrilateral are located. If there is an overlap, determine whether the number of overlaps between the line segments where the shared arms and open arms of the valid quadrilateral are located and the line segments where the open arms of the seed quadrilateral are located is greater than or equal to 1. If so, obtain a cubic object contour with the three arms of the seed quadrilateral as the edges of the upper surface and the arms of the valid quadrilateral other than the overlapping arms as the edges of the lateral vertical surfaces, obtain all cubic object contours, and record them as a cubic object contour set;
[0034] C10, obtaining the coordinates of all points of the cubic object contour according to the endpoints of each edge of the cubic object contour, where the cubic object contour takes the seed quadrilateral as the upper surface;
[0035] C11. Traverse the cubic object contour set, calculate the y coordinate Py of the center point of each cubic object contour and the y coordinate ty of the center point of its upper surface, calculate the area P.area of each cubic object contour and the area t.area of its upper surface. If ty>Py or t.area>P.area, remove the cubic object contour and obtain the final cubic object contour set.
[0036] Preferably, the left and right vertical planes corresponding to each upper surface quadrilateral are obtained according to the segmented image of the left vertical plane and the segmented image of the right vertical plane, and the specific method for realizing the positioning of the cubic object is: traverse all cubic object contour sets, obtain all contours of the left vertical plane and their corresponding rotated rectangles and circumscribed rectangles according to the segmented image of the left vertical plane, and judge whether the y coordinate of the center point of the rotated rectangle is greater than or equal to the y coordinate of the center point of the upper surface quadrilateral; if the previous condition is met, judge whether the ratio of the overlapping area of the cubic object contour area corresponding to the upper surface quadrilateral and the circumscribed rectangle to the cubic object contour area is greater than or equal to a given area ratio threshold; if it is greater than or equal to the area ratio threshold, find the contour with the largest area among all left vertical plane contours that meet the above conditions, which is the left vertical plane contour of the current cubic object;
[0037] According to the right vertical segmentation image, all contours of the right vertical surface and their corresponding rotated rectangles and circumscribed rectangles are obtained. The processing method for all contours of the right vertical segmentation image is consistent with the processing method for all contours of the left vertical surface, so as to obtain the left vertical surface and right vertical surface corresponding to the upper surface of each cubic object. Each group of upper surface, left vertical surface and right vertical surface constitutes a cubic object, realizing cubic object detection.
[0038] Preferably, in S8, the plane of the cube in the three-dimensional space is fitted according to the upper surface, the left perpendicular surface and the right perpendicular surface, and the noise points on each surface are eliminated by repeated fitting for multiple times, and the specific method of obtaining the ideal point set corresponding to each surface is:
[0039] C1. Traverse all the pixel points on the upper surface of each detected cubic object, and obtain the world coordinate points of all the pixel points on the upper surface in the three-dimensional space according to the transformation relationship between the image coordinate system and the world coordinate system;
[0040] C2, traverse all world coordinate points on the current upper surface, give a point count threshold, and determine whether all points are greater than the given point count threshold;
[0041] C3. If the number of points is greater than the point threshold, calculate the mean point of all points and perform normalization. All coordinate points on the upper surface of each cubic object are located in the same plane in the three-dimensional space, and the mean point is located on the plane. Calculate the normal vector of the plane in the three-dimensional space where the mean point is located, and obtain the initial fitting three-dimensional plane equation based on the normal vector and the mean point.
[0042] C4, calculate the distances from all world coordinate points on the upper surface to the first fitted three-dimensional plane, give a distance threshold, remove all points whose distances are greater than the given distance threshold, obtain an ideal point set, perform fitting again based on the ideal point set, and obtain a second fitted three-dimensional plane equation;
[0043] C5. Repeat the above steps to perform multiple repetitive fittings. After each fitting, calculate the distances from all points in the ideal point set to the fitted three-dimensional plane, remove all points whose distances are greater than a given distance threshold, and update the ideal point set, which is recorded as the upper ideal point set.
[0044] C6. For the left and right perpendicular surfaces of the cubic object, the same method as the upper surface is used to obtain the fitting three-dimensional plane equations of the corresponding left and right perpendicular surfaces in the three-dimensional space and their corresponding left perpendicular surface ideal point sets and right perpendicular surface ideal point sets, which are recorded as the left ideal point set and the right ideal point set.
[0045] Preferably, in S9, the contour boundary and corner points of each face are obtained according to the ideal point set of each face, and the length, width and height of the cube are obtained according to the coordinates of its corner points in three-dimensional space. The specific method for calculating the volume of the cubic object is: obtain the plane coordinate points corresponding to all world coordinate points of the upper ideal point set, the left ideal point set and the right ideal point set in the two-dimensional plane, and perform contour detection based on them, obtain all contours, calculate the overlapping area of the circumscribed rectangle of each contour and the circumscribed rectangle of the upper surface corresponding to the upper ideal point set, find the contour with the largest overlapping area and greater than a given threshold, and the contour is the final contour of the upper surface, calculate the convex hull of the upper surface according to the contour, and obtain its corresponding pseudo-contour according to its convex hull. Fit the polygon and obtain all edge lines of the fitting polygon of the upper surface. These edge lines are the contour boundaries of the upper surface. The contour boundaries of the left and right vertical planes are obtained in the same way. The four corner points of the upper surface are obtained according to the contour boundary, and the world coordinates of the four corner points corresponding to the three-dimensional space are obtained. The length and width of the upper surface are calculated according to the world coordinates, which are the length and width of the current cubic object. The larger vertical plane of the left and right vertical planes is selected, and the four corner points of the vertical plane are obtained according to the contour boundary of the vertical plane, and the world coordinates of the four corner points corresponding to the three-dimensional space are obtained. The height of the vertical plane is calculated according to the world coordinates, which is the height of the current cube. The volume of the cubic object is calculated according to the length, width and height of the cube.
[0046] Preferably, the specific manner of extending the two arms of each corner point according to the seed edge line set is:
[0047] Traverse all edge lines in the seed edge line set, and for each corner point, calculate its distance to the current seed edge
[0048] If the distance is less than the given threshold, it is determined whether the seed edge line can extend the two arms of the current corner point. First, it is determined whether the seed edge line can extend the arm 1 of the current corner point. The specific method is:
[0049] C1. Calculate the distance from the current corner point to the starting point and the end point of the seed edge line, recorded as dist1 and dist2, and determine whether the current corner point is between the two end points of the seed edge line;
[0050] C2. If the current corner point is between the two endpoints of the seed edge line, the line segment from the current corner point to the starting point of the seed edge line is recorded as M, the starting point of line segment M is the current corner point, the end point is the starting point of the seed edge line, the line segment where arm 1 of the current corner point is located is recorded as N, the starting point of line segment N is the current corner point, calculate the angle angle1 of line segment M and the angle angle2 of line segment N, and determine whether the absolute value of the difference between angle1 and angle2 is less than the given angle threshold;
[0051] C3. If the absolute value of the difference between angle1 and angle2 is less than the given angle threshold, calculate the distance rM from the end point of line M to the current corner point, calculate the length rN of line segment N, and determine whether the difference between rM and rN is less than the given length difference threshold;
[0052] C4, if the difference between rM and rN is less than the given length difference threshold, calculate the distance from the end point of line segment N to the current seed edge line. If the distance is less than the given point-to-line distance threshold and dist1 is greater than rN, the current seed edge line can extend the arm 1 of the current corner point. The end point of the extended arm 1 of the current corner point is the starting point of the seed edge line, and the length of the extended arm 1 is dist1.
[0053] C5. If any of the conditions from C2 to C4 is not met, it indicates that the current seed edge line cannot extend the arm 1 of the current corner point. Then the same method is used to determine whether the current seed edge line can extend the arm 2 of the current corner point. If it can be extended, the end point of the extended arm 2 is the starting point of the seed edge line, and the length of the extended arm 2 is dist1. If it cannot be extended, directly execute the next step;
[0054] C6, update the end point of line segment M in C2 to the end point of the current seed edge line, update line segment N to the line segment where arm 2 of the current corner point is located, the starting point of line segment N is the current corner point, dist1 is updated to dist2, and the same method is used to determine again whether the current seed edge line can extend arm 1 and arm 2 of the current corner point to achieve the extension of the two arms of the current corner point;
[0055] C7. At this time, if the condition in C1 is not met, determine whether dist1 is less than or equal to dist2;
[0056] C8, if dist1 is less than or equal to dist2, update the starting point of line segment M in C2 to the starting point of the current seed edge line, and the end point to the end point of the current edge line. Line segment N is the line segment where arm 1 or arm 2 of the current corner point is located. Use the same method to determine whether the current seed edge line can extend arm 1 and arm 2 of the current corner point to achieve the extension of the two arms of the current corner point.
[0057] C9. If dist1 is greater than dist2, update the starting point of the line segment M in C2 to the end point of the current seed edge line, and the end point is updated to the starting point of the current edge line. The line segment N is the line segment where arm 1 or arm 2 of the current corner point is located. Dist1 is updated to dist2. The same method is used to determine whether the current seed edge line can extend arm 1 and arm 2 of the current corner point to achieve the extension of the two arms of the current corner point.
[0058] The beneficial effects of the present invention are as follows: the method for calculating the volume of a cubic object based on a depth image and removing noise of the present invention, on the basis of quickly distinguishing the surface of the cubic object by segmenting the image, performs edge line detection on the edge point map, clusters and merges all the detected edge lines, obtains all collinear edge line groups, the edge lines in each group are collinear, and the longest edge line is selected to represent each group of edge lines. When calculating, each group of edge lines also uses only the longest edge line, which reduces the amount of calculation and improves the stability of detection; then, the intersection points between the edge lines after clustering and merging are used to extract corner points and pair them, and the corner point pairing verifies the two corner points. Whether there is a shared arm between points, whether the two open arms of the corner point are on the same side of its shared arm, and whether the angle between each corner point is greater than the given angle threshold, quadrilateral detection is realized according to the corner point pairing results, and then all upper surface contours are obtained by detecting the upper surface segmentation image, and the upper surface contours are matched with all detected quadrilaterals to obtain the upper surface of the cube and the overall contour of the cube, and then all left vertical surface contours and right vertical surface contours are obtained by combining the left vertical surface and right vertical surface segmentation images, and then the left vertical surface and right vertical surface corresponding to each upper surface are determined according to the overall contour of the cube, and the positioning of the cubic object is accurately realized. According to the three faces of the cubic object, its plane in three-dimensional space is fitted, and points with a large distance to the fitted three-dimensional plane are eliminated after each fitting. After repeated fitting, the noise points on each face are eliminated to increase the accuracy of fitting and improve the stability of the algorithm; according to the ideal point set corresponding to each face after fitting, the contour and corner points of each face are obtained, and then the length, width and height of the cubic object are obtained to accurately calculate the volume of the cubic object.
[0059] The cubic object volume calculation method of the present invention is applied to the volume measurement of cubic objects such as parcels, goods, containers, etc., avoiding the comparison of the depth images before and after the conveyor belt is loaded, but directly identifying the cubic object, obtaining the corresponding length, width and height to calculate the volume of the cubic object, solving the limitation and time-consuming problem of parcel volume measurement, helping the logistics industry to improve the efficiency of parcel sorting, and having important practical application significance. The cubic object volume calculation method based on the noise removal of the depth image of the present invention can also be applied in the field of image recognition. DETAILED DESCRIPTION
[0060] The technical solutions in the embodiments of the present invention are described clearly and completely below. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0061] Embodiment: A method for calculating the volume of a cubic object based on a depth image, comprising: S1, obtaining a depth image of the cubic object, and obtaining gradient images in the X direction and the Y direction of the same size as the depth image respectively according to the depth image; S2, classifying the pixel points therein according to the gradient image, and obtaining an edge point map of the depth image; S3, obtaining a segmented image of the upper surface, the left vertical surface, and the right vertical surface of the cubic object in the depth image according to the classification result, the gradient map, and the edge point map; S4, performing edge line detection on the edge point map, clustering and merging all detected edge lines, and obtaining a set of collinear edge line groups; S5, extracting corner points according to the longest edge line of each group of the collinear edge line set; S6, matching the extracted corner points; S7, determining the upper surface and overall contour of the cubic object according to the acquired quadrilateral and upper surface segmentation images, obtaining the left and right vertical planes corresponding to each upper surface quadrilateral according to the segmentation image of the left vertical plane and the right vertical segmentation image, and realizing the positioning of the cubic object; S8, fitting the plane of the cubic object in three-dimensional space according to its upper surface, left vertical plane and right vertical plane, eliminating the noise points on each surface by repeated fitting, and obtaining the ideal point set corresponding to each surface; S9, obtaining the contour boundary and corner points of each surface according to the ideal point set of each surface, obtaining the length, width and height of the cubic object according to the coordinates of its corner points in three-dimensional space, and calculating the volume of the cubic object.
[0062] The pixel classification method is applicable to any object in any scene. When it is actually used in cubic object positioning and volume measurement, the cubic object contains at least a visible upper surface and a vertical surface in the image, and the plane where the target is located is the lowest plane in the depth image or directly on the ground, which facilitates more accurate cubic object positioning and improves the accuracy of volume calculation.
[0063] The specific method of dividing the pixels in S2 into three categories according to the gradient map: horizontal plane, left vertical plane and right vertical plane: traverse each pixel value DX (r, c) in the gradient map in the X direction, and each pixel value DY (r, c) in the gradient map in the Y direction, where r = 0...m, c = 0...n, m represents the number of rows in the gradient map, and n represents the number of columns in the gradient map; given a positive segmentation threshold p and a negative segmentation threshold q, the pixel points corresponding to DY (r, c) greater than or equal to p are located in the vertical plane, and the pixel points corresponding to DY (r, c) less than or equal to q are located in the horizontal plane; for all points on the vertical plane, the pixel points corresponding to DX (r, c) less than or equal to q are located in the left vertical plane, and the pixel points corresponding to DY (r, c) greater than or equal to p are located in the right vertical plane.
[0064] The specific method of obtaining the edge point map of the depth image in S2 is as follows: calculate the gradient average value Yp in the Y direction of all pixels of the vertical plane after classification, the gradient average value Yq in the Y direction of all pixels of the horizontal plane, the gradient average value Xp in the X direction of all pixels of the left vertical plane, and the gradient average value Xq in the X direction of all pixels of the right vertical plane; set the positive threshold in the Y direction, the negative threshold in the Y direction, the positive threshold in the X direction, and the negative threshold in the X direction according to Yp, Yq, Xp, and Xq; define an image with the same size as the gradient map, and set the initial value of the pixel in the image to 0; traverse all the gradient maps in the X direction and the gradient maps in the Y direction. Pixel point, for each pixel point, if the absolute value of its gradient value in the Y direction is greater than the absolute value of the gradient value in the X direction, and is less than the negative threshold in the Y direction or greater than or equal to the positive threshold in the Y direction, the pixel point is an edge point, and the pixel point is matched to the defined image and its pixel value is updated to 255; if the absolute value of its gradient value in the Y direction is less than the absolute value of the gradient value in the X direction, and the absolute value of its gradient value in the X direction is less than or equal to the negative threshold in the X direction or greater than or equal to the positive threshold in the X direction, the pixel point is an edge point, and the pixel point is matched to the defined image and its pixel value is updated to 255; an edge point map is obtained, and the edge point map is a binary map.
[0065] In S3, the specific method of obtaining the segmented images of the upper surface, left vertical surface and right vertical surface of the cubic object in the depth image according to the classification results, the gradient map and the edge point map is as follows: according to the classification results, the binary images of the horizontal plane, the left vertical surface and the right vertical surface of the same size as the gradient map are obtained, and the upper surface segmented image with the same size as the gradient map is defined, and the initial value of the pixel is set to 0; the pixels in the first column of the binary image of the horizontal plane are traversed from bottom to top, and the credibility value of each pixel is obtained according to the depth map, and a credibility threshold is given. If the credibility value of the pixel is less than the given credibility threshold, the state of the pixel is unknown, and the next pixel is processed; otherwise, if the corresponding pixel value is 255, the state of the pixel is horizontal, if the corresponding pixel is 0, the state of the pixel is vertical, and if the number of pixels with a pixel value of 0 is greater than the given height threshold, the pixels with a pixel value of 255 that appear later are matched on the upper surface segmented image and their pixel values are updated to 255, and each time the pixel state changes is recorded. The number of rows where the pixel point changes, after traversing the pixel points of all rows in the first column, the pixel values of all pixel points in the first column from the recorded number of rows to the first row corresponding to the position on the upper surface segmentation image are set to 0, and all rows and columns of the parallel surface image are traversed in the same way to obtain the initial upper surface segmentation image; the initial upper surface segmentation image is repaired to update the upper surface segmentation image; the edge points in the edge point map are respectively mapped one by one to the updated upper surface segmentation image, the binary image of the left vertical surface, and the right vertical surface. In the binary image of the vertical surface, the pixel values of the horizontal non-edge points in the updated upper surface segmentation image are updated to 0, the pixel values of the non-edge points in the binary image of the left vertical surface with a pixel value of 255 are updated to 0, and the pixel values of the non-edge points in the binary image of the right vertical surface with a pixel value of 255 are updated to 0, so as to obtain the final upper surface segmentation image, the binary image of the left vertical surface and the binary image of the right vertical surface, and record the binary image of the left vertical surface and the binary image of the right vertical surface as the segmentation image of the left vertical surface and the segmentation image of the right vertical surface, respectively.
[0066] During the calculation process, due to noise interference, individual points on the upper surface may be misjudged as points on the vertical surface, resulting in discontinuity of the upper surface points. In order to improve the stability of the algorithm, the upper surface segmentation image is patched. The specific method of patching the initial upper surface segmentation image is as follows: given an image slice size threshold t, define an upper surface patch image with the same size as the upper surface segmentation image, set the initial value of the pixel to 0, update the pixel value of the upper surface patch image from the tth column to the total number of columns minus the tth column according to the upper surface segmentation image, traverse all rows and 1 to 2*t columns of the upper surface segmentation image, update each pixel value of the tth column of each row of the upper surface patch image to the sum of the pixel values of the 1 to 2*t columns of the current row of the upper surface segmentation image, and update the upper surface patch image; traverse all rows and t+tth columns of the upper surface segmentation image. 1 column to the total number of columns minus t columns, update each pixel value of the upper surface patch image to the pixel value of the upper surface patch image in the previous column of the current row and current column plus the pixel value of the upper surface segmentation image in the current row and current column plus t columns, and then minus the pixel value of the upper surface segmentation image in the current row and current column minus t columns, to obtain the final upper surface patch image; traverse all pixels of the upper surface patch image, give a pixel value sum threshold, if the pixel value of the current pixel is greater than the given pixel value sum threshold, then update its corresponding pixel value on the upper surface segmentation image to 255, otherwise update it to 0, and update the upper surface segmentation image.
[0067] Record the row number of each pixel point where the pixel state changes, obtain the depth image of the target in S1, the target can be completely seen in the depth image, traverse each column of pixels from bottom to top, if the vertical and horizontal surfaces of the cubic object appear successively, then the pixel category will definitely change again, and set the pixel values of all pixels in the current column from the row number corresponding to the position where the pixel state changed for the last time to the first row to 0 (the point value of the recorded row number to the first row may be 0 or 255, and is uniformly set to 0); otherwise, it is very likely that the upper surface of the current cubic object does not appear completely in the picture, and such upper surface points are eliminated, and their corresponding pixel values on the upper surface segmentation image are set to 0.
[0068] In S4, edge line detection is performed on the edge point image, and all detected edge lines are clustered and merged to obtain a collinear edge line group set. The specific method is as follows: edge line detection is performed on the edge point image, all edge lines are obtained and sorted into an edge line set from long to short, and an empty collinear edge line group set is defined. The collinear edge line group set contains multiple groups of edge lines. The edge lines in each group are collinear, and the edge lines between two groups are not collinear. First, the longest edge line is added to one group of the collinear edge line group set. For each A edge line in the edge line set, it is determined whether it is collinear with the longest B edge line in each group of the collinear edge line group set. The judgment conditions are as follows: C1. Calculate the angle difference between edge line A and edge line B, and judge Is the angle difference less than or equal to the given angle difference threshold e? If the angle difference is greater than e, edge line A and edge line B are definitely not collinear, because two collinear edge lines should be approximately parallel and have a relatively small angle difference. C2. If the angle difference is less than or equal to e, calculate the distances T1 and T2 from the starting point of edge line B to the starting point and end point of edge line A, and T3 and T4 from the end point of edge line B to the starting point and end point of edge line A. Given the point distance threshold G, is the minimum distance among distances T1, T2, T3 and T4 less than or equal to the point distance threshold G? This part is to detect whether the minimum distance between the two endpoints of edge line A and edge line B is less than the given point distance threshold G. If the minimum distance is greater than the given point distance threshold, it means that this The two edge lines are far apart, min(min(T1, T2), min(T3, T4))>G, then edge lines A and B are definitely not collinear; C3. If min(min(T1, T2), min(T3, T4))≤G, calculate the length L of edge line A and the length H of edge line B, and determine whether the maximum distance among distances T1, T2, T3 and T4 is less than G+H+L, max(max(T1, T2), max(T3, T4))≥(G+H+L), edge lines A and B are not collinear; C4. If max(max(T1, T2), max(T3, T4))<(G+H+L), calculate the distance from the start and end points of edge line B to edge line A. From S1 and S2, the distances S3 and S4 from the start and end points of edge line A to edge line B, given a distance threshold J, if the maximum distance between T1 and T2 is less than L+G, determine whether S1 is less than or equal to J; if the maximum distance between T3 and T4 is less than L+G, determine whether S2 is less than or equal to J; if the maximum distance between T1 and T3 is less than L+G, determine whether S3 is less than or equal to J; if the maximum distance between T2 and T4 is less than L+G, determine whether S4 is less than or equal to J; if any maximum distance is greater than or equal to L+G, directly execute the next step; C5, if the conditions in C4 are met, edge line A and edge line B are collinear, add edge line A to the group of the collinear edge line group set, and update the edge line of the group;In the above sequential judgment process from C1 to C6, if any condition is not satisfied, directly process the longest edge line of the next group in the collinear edge line group set, until all groups in the collinear edge line group set are processed, and each group of edge lines is represented by its longest edge line. If edge line A is not collinear with the longest edge lines of all groups in the collinear edge line group set, directly add edge line A to the new group in the collinear edge line group set, and update the number of groups in the collinear edge line group set; after edge line A and edge line B are collinear, determine whether edge line A and edge line B meet the merging condition. If T1≤H, T2≤H, T3≤H and T4≤H, edge line A and edge line B do not meet the merging condition. Otherwise, merge edge line A and edge line B, update the starting point and end point of edge line B, and update the collinear edge line group set; process the next edge line in the edge line set in the same way as processing edge line A, continuously update the collinear edge line group set, sort the edge lines in the collinear edge line group set by length, and obtain the final collinear edge line group set. ;
[0069] The main reason for performing collinear clustering and merging of edge lines here is that in the process of edge line detection, the originally continuous edge lines are often disconnected due to noise interference. Originally there was only one edge line, but multiple nearly parallel edge lines with close distances but different lengths may be detected during detection, which will reduce the stability and accuracy of the algorithm. The main purpose of performing collinear clustering and merging is to divide multiple line segments that may belong to the same line into the same group and merge them, merge multiple disconnected collinear edge lines, obtain the longest edge line of each group, and use the longest edge line to represent all edge lines of the group. On the one hand, it reduces the amount of calculation, and on the other hand, it improves the stability of the algorithm.
[0070] Merge edge line A and edge line B, and update the starting and ending points of edge line B as follows: edge line B is the longest edge line in its group. If edge line A and edge line B are collinear and meet the merging conditions, update the starting and ending points of edge line B according to edge line A. If the x-coordinates of the two end points of the edge line are different, define the left end point of the edge line as the starting point and the right end point as the end point. If the x-coordinates of the two end points are the same, define the upper end point as the starting point and the lower end point as the end point. The judgment method for updating the end point of edge line B is as follows: C1, if T1 >H and T2 > H, on this basis, T3 > T4, then the end point of edge line B is updated to the starting point of edge line A. If the condition of T3 > T4 is not met, the end point of edge line B is updated to the end point of edge line A; C2, if the condition in C1 is not met, T1 >H and T2 > H, if T1 > H but T2 <= H, then the end point of edge line B is updated to the starting point of edge line A; C3, if the conditions in C1 and C2 are not met, if T2 >H but T1<= H, then the end point of edge line B is updated to the end point of edge line A. The judgment method for updating the starting point of edge line B is: C1, if T3>H and T4>H, on this basis, T1>T2, then the starting point of edge line B is updated to the starting point of edge line A. If the condition of T1>T2 is not met, the starting point of edge line B is updated to the end point of edge line A; C2, if the condition in C1 is not met, T3>H and T4>H, if T3>H but T4<=H, then the starting point of edge line B is updated to the starting point of edge line A; C3, if the conditions in C1 and C2 are not met, if T4>H but T3<=H, then the starting point of edge line B is updated to the end point of edge line A.
[0071] The specific method of extracting corner points according to the longest edge line of each group of collinear edge line groups in S5 is as follows: C1. Obtain the longest edge line of each group of collinear edge line groups, record it as the seed edge line set, sort all edge lines of the seed edge line set from long to short, traverse all edge lines of the seed edge line set, and start from the longest C edge line to calculate the angle a between it and any other D edge line, where a ranges from 0 to 180 degrees. Given a curvature threshold b, determine whether min (a, 180-a) is greater than b; C2. If min (a, 180-a)> b, calculate the intersection W of the C edge line and the D edge line (Wx, Wy), determine whether Wx or Wy does not exceed the image range; if Wx or Wy exceeds the image range, start processing the next edge line; C3, if Wx or Wy does not exceed the image range, determine whether the intersection W is a corner point. The condition for determining whether the intersection W is a corner point is: first calculate the distances d1 and d2 from the two endpoints of the C edge line to the intersection W, and define the minimum distance min_d1. If the intersection W is between the two endpoints of the C edge line, then min_d1=0, otherwise min_d1=min(d1, d2), If the minimum distance min_d1 is not 0 or min(d1, d2) is less than the given arm length threshold Z1, then calculate the distances d3 and d4 from the two endpoints of the edge line D to the intersection point W, and define the minimum distance min_d2. If the intersection point W is between the two endpoints of the edge line D, then min_d2=0, otherwise min_d2=min(d3, d4). If the minimum distance min_d2 is not 0 or min(d3, d4) is less than the given arm length threshold Z2, determine min(d1, d2) and min(d3, d4) Is it less than the given intersection radius threshold r? C4. If the condition of C3 is met, given the quadrilateral arm gap threshold v, determine whether max(min(d1, d2), min(d3, d4)) is less than or equal to v. If not, process the next edge line. If satisfied, the intersection W is the corner point of the quadrilateral. The conditions C1 to C4 are judged in turn. If any condition is not met, process the next edge line. Add the first corner point obtained to the corner point set. For the remaining corner points obtained, calculate their distance L to all corner points in the corner point set. i , i is a variable, judging whether it is similar to all corner points in the corner point set, if L i<r, and is not similar to the rest of the corner points, add the corner point to the corner point set; the intersection point W corresponds to two arms, the first arm is the line connecting it with the end point of the C edge line, the second arm is the line connecting it with the end point of the D edge line, the end point of the C edge line is the larger corresponding endpoint of d1 and d2 in the C edge line, and the end point of the D edge line is the larger corresponding endpoint of d3 and d4 in the D edge line; process any other two edge lines in the seed edge line group set in the same way to obtain all the corner points, expand the two arms of each corner point according to the seed edge line set, obtain the final corner point set, and realize corner point extraction.
[0072] The specific method to determine whether two corner points are similar is: calculate the absolute values a11, a12, a21, and a22 of the difference between the angle of each open arm of one corner point and the angle of each open arm of the other corner point, and the absolute value of the angle difference ranges from [0, 180]. Select min(a11, a12), min(a21, a22), and give an angle similarity threshold f. If max(min(a11, a12), min(a21, a22)) < f, the two corner points are similar.
[0073] The similarity of two corner points means that the opening arms corresponding to the two corner points are approximately parallel. For example: if the two corner points contain a horizontal opening arm and a vertical opening arm respectively, the horizontal opening arms of the two corner points are approximately parallel, and the angle difference is very small. The two vertical opening arms are approximately parallel, and the angle difference is also very small. Therefore, the minimum value of min(a11, a12) and min(a21, a22) should also be less than the given similarity angle threshold, otherwise the two corner points are not similar.
[0074] The specific method of extending the two arms of each corner point according to the seed edge line set is: traverse all edge lines of the seed edge line set, and for each corner point, calculate the distance from it to the current seed edge line. If the distance is less than a given threshold, determine whether the seed edge line can extend the two arms of the current corner point. First, determine whether the seed edge line can extend arm 1 of the current corner point. The specific method is:
[0075] C1. Calculate the distance from the current corner point to the starting point and the end point of the seed edge line, recorded as dist1 and dist2, and determine whether the current corner point is between the two end points of the seed edge line;
[0076] C2. If the current corner point is between the two endpoints of the seed edge line, the line segment from the current corner point to the starting point of the seed edge line is recorded as M, the starting point of line segment M is the current corner point, the end point is the starting point of the seed edge line, the line segment where arm 1 of the current corner point is located is recorded as N, the starting point of line segment N is the current corner point, calculate the angle angle1 of line segment M and the angle angle2 of line segment N, and determine whether the absolute value of the difference between angle1 and angle2 is less than the given angle threshold;
[0077] C3. If the absolute value of the difference between angle1 and angle2 is less than the given angle threshold, calculate the distance rM from the end point of line M to the current corner point, calculate the length rN of line segment N, and determine whether the difference between rM and rN is less than the given length difference threshold;
[0078] C4, if the difference between rM and rN is less than the given length difference threshold, calculate the distance from the end point of line segment N to the current seed edge line. If the distance is less than the given point-to-line distance threshold and dist1 is greater than rN, the current seed edge line can extend the arm 1 of the current corner point. The end point of the extended arm 1 of the current corner point is the starting point of the seed edge line, and the length of the extended arm 1 is dist1.
[0079] C5. If any of the conditions from C2 to C4 is not met, it indicates that the current seed edge line cannot extend the arm 1 of the current corner point. Then the same method is used to determine whether the current seed edge line can extend the arm 2 of the current corner point. If it can be extended, the end point of the extended arm 2 is the starting point of the seed edge line, and the length of the extended arm 2 is dist1. If it cannot be extended, directly execute the next step;
[0080] C6, update the end point of line segment M in C2 to the end point of the current seed edge line, update line segment N to the line segment where arm 2 of the current corner point is located, the starting point of line segment N is the current corner point, dist1 is updated to dist2, and the same method is used to determine again whether the current seed edge line can extend arm 1 and arm 2 of the current corner point to achieve the extension of the two arms of the current corner point;
[0081] C7. At this time, if the condition in C1 is not met, determine whether dist1 is less than or equal to dist2;
[0082] C8, if dist1 is less than or equal to dist2, update the starting point of line segment M in C2 to the starting point of the current seed edge line, and the end point to the end point of the current edge line. Line segment N is the line segment where arm 1 or arm 2 of the current corner point is located. Use the same method to determine whether the current seed edge line can extend arm 1 and arm 2 of the current corner point to achieve the extension of the two arms of the current corner point.
[0083] C9. If dist1 is greater than dist2, update the starting point of the line segment M in C2 to the end point of the current seed edge line, and the end point is updated to the starting point of the current edge line. The line segment N is the line segment where arm 1 or arm 2 of the current corner point is located. Dist1 is updated to dist2. The same method is used to determine whether the current seed edge line can extend arm 1 and arm 2 of the current corner point to achieve the extension of the two arms of the current corner point.
[0084] The specific method of pairing the extracted corner points in S6 is as follows: C1. Pair all corner points in the corner point set in pairs. If the coordinates of the two paired corner points are different, continue to determine whether the two corner points share an arm. Mark the two arms of one corner point as arm11 and arm12, and the two arms of the other corner point as arm21 and arm22. First determine whether arm11 and arm21 are the same arm of the two corner points; C2. Determine whether arm11 and arm21 are the same arm as follows: if the distance between the two corner points is less than one-fourth of the minimum value of arm11 and arm21, then arm11 and arm21 are not are the same arm; if the distance between the two corner points is greater than one-fourth of the minimum value of arm11 and arm21, first calculate the absolute value x1 of the angle difference between arm11 and the line connecting the two corner points, and the absolute value x2 of the angle difference between arm21 and the line connecting the two corner points. The value range of x1 and x2 is [0, 180]. Given the angle similarity threshold f, if both x1 and x2 are less than the angle similarity threshold f, given the corner point distance threshold u and the length ratio threshold ratio, if the sum of the lengths of arm11 and arm21 is greater than or equal to ratio times the distance between the two corner points, and greater than or equal to the difference between the distance between the two corner points and u, then arm1 is determined to be If arm1 and arm21 are the same arm, the corner point pairing is successful; otherwise, the same method is used to determine whether the other two arms of the two corner points are the same arm. If neither is the case, the corner point pairing fails, otherwise the corner point pairing is successful; the same method is used to pair the remaining corner points in pairs to obtain all successfully paired corner point combinations. The same arm of each corner point combination is a shared arm, and the other two arms are open arms. The angles u1 and u2 between the two open arms and the shared arm in each corner point combination are calculated. The value range of the angles u1 and u2 is [0, 180]. The corner point combinations whose angles u1 or u2 are less than the curvature threshold b are eliminated; for the remaining corner point combinations, determine whether their two open arms are the same arm. Whether the arms are on the same side of the shared arm, calculate the center point of the shared arm of the corner point combination, take the center point as the starting point, calculate the unit normal vector of the shared arm, calculate the vector v1 where the line connecting the end point of the open arm of the first corner point and the center point is located, and the vector v2 where the line connecting the end point of the open arm of the second corner point and the center point is located. If the inner products of vectors v1 and v2 with the unit normal vector of the shared arm are one positive and one negative, the two open arms are not on the same side of the shared arm. The corner point combination whose two open arms are not on the same side of the shared arm is eliminated. Finally, a quadrilateral is determined based on the currently paired corner point combination; all corner point combinations are processed in the same way to obtain all quadrilaterals.
[0085] In S7, the upper surface and overall contour of the cubic object are determined based on the acquired quadrilateral and upper surface segmentation images, and then the left and right vertical planes corresponding to each upper surface quadrilateral are obtained based on the segmentation image of the left vertical plane and the right vertical segmentation image to realize the positioning of the cubic object. The specific method for determining the upper surface and overall contour of the cubic object is as follows: C 1. First, process the acquired quadrilateral. If the distance between the end points of the two arms of the matching quadrilateral is less than 0.8 times the distance between its two corner points, the quadrilateral does not meet the requirements, and the next quadrilateral is processed to obtain all quadrilaterals that meet the conditions, and obtain the contour and circumscribed rectangle of each quadrilateral, and calculate its convex hull according to the contour coordinate points; C2. Perform contour detection based on the upper surface segmentation image, obtain all contours, calculate their convex hulls according to the contour coordinate points, and obtain the smallest rotated rectangle containing each contour and the circumscribed rectangle containing the rotated rectangle, calculate the area of each contour, and determine whether the area of the contour is If the area of the contour is less than the given area threshold, process the next contour; C3, if the area of the contour is greater than the given area threshold, match the current contour with a qualified quadrilateral, calculate the minimum distances h1 and h2 from the two corner points of the matching quadrilateral to the convex hull of the current contour, and determine whether the two corner points of the matching quadrilateral are outside the convex hull of the matching quadrilateral and whether h1 and h2 are less than or equal to the given distance threshold. If either of h1 and h2 is greater than the given distance threshold, it indicates that there is a corner point inside the contour. And match the next quadrilateral close to its center point; C4, if the two corner points of the matching quadrilateral are outside the convex hull of the matching quadrilateral and h1 and h2 are both less than or equal to the distance threshold, the two corner points of the matching quadrilateral are located outside the current contour, and determine whether the center point of the rotated rectangle outside the current contour is inside the convex hull of the matching quadrilateral. If not, match the next quadrilateral; C5, if the center point of the rotated rectangle outside the current contour is inside the convex hull of the matching quadrilateral, calculate its closest distance to the matching quadrilateral contour. The absolute value of the minimum distance satisfies the condition that the value is less than or equal to the length and width of the rotated rectangle, and the center point is located at the lower side of any arm of the matching quadrilateral, and the overlapping area of the circumscribed rectangle of the matching quadrilateral and the circumscribed rectangle of the current contour is calculated. If the overlapping area is greater than a given ratio threshold, the current contour and the matching quadrilateral are preliminarily matched successfully, and the matching quadrilateral is recorded as a preliminary matching quadrilateral; C6, the distance from the center point of the rotated rectangle of the current contour to the three arms of the preliminary matching quadrilateral is normalized, and the normalized value is within the theoretical range, and the sum of h1 and h2 is less than or equal to the given threshold, and the preliminary matching quadrilateral is recorded as a valid quadrilateral;C7. Determine whether the two open arms of the valid quadrilateral are facing downwards, and record the valid quadrilateral with two open arms facing downwards as the seed quadrilateral. The judgment method is: take the two corner points of the valid quadrilateral as the starting point, the horizontal right is the X-axis, the line segment angle on the X-axis is 0 degrees, and the line segment angle increases continuously as it rotates clockwise. The value range of the angle is [0, 360]. Use this definition rule to calculate the angles of the two open arms. If both angles are less than 15 degrees or greater than 165 degrees, it means that the two open arms of the valid quadrilateral are facing upwards, and the next one is processed; otherwise, if the end points of the two open arms of the valid quadrilateral are above the two corner points, the next one is processed, otherwise, the two open arms are facing upwards. The valid quadrilateral under is recorded as the seed quadrilateral; if the next seed quadrilateral that meets the above conditions is obtained, then calculate whether the sum of the minimum distances from the two corner points of the current seed quadrilateral to its convex hull is less than the sum of the minimum distances from the two corner points of the previous seed quadrilateral to its convex hull. If it is less, replace the previous seed quadrilateral with the current seed quadrilateral, otherwise eliminate the current seed quadrilateral, and continue processing to obtain the final seed quadrilateral of the current contour; C8, determine whether the final seed quadrilateral of the current contour has shared corner points with the valid quadrilateral. The judgment method is that among the seed quadrilateral and the valid quadrilateral matching the current contour, each contour has only one seed quadrilateral but there may be multiple seed quadrilaterals. C9: if there is a shared corner point, determine whether the line segments where the shared arms and open arms of the effective quadrilateral are located overlap with the line segments where the shared arms of the seed quadrilateral are located. If there is an overlap, determine whether the number of overlaps between the line segments where the shared arms and open arms of the effective quadrilateral are located and the line segments where the open arms of the seed quadrilateral are located is greater than or equal to 1. If so, obtain the edge with the three arms of the seed quadrilateral as the upper surface and the arms of the effective quadrilateral other than the overlapping arms as the side vertical surface. The cubic object contour of each edge is obtained, and all the cubic object contours are recorded as a cubic object contour set. Each cubic object contour is a polygon; C10, according to the endpoints of each edge of the cubic object contour, all the point coordinates of the cubic object contour are obtained. The cubic object contour uses the seed quadrilateral as the upper surface; C11, traverse the cubic object contour set, calculate the y coordinate Py of the center point of each cubic object contour and the y coordinate ty of the center point of its upper surface, calculate the area P.area of each cubic object contour and the area t.area of its upper surface. If ty>Py or t.area>P.area, then the cubic object contour is eliminated to obtain the final cubic object contour set. 0.8 is the given distance ratio threshold. ;
[0086] The method for judging whether two line segments overlap is as follows: given line segment E and line segment F, the length of E is L1 and the length of F is H1; calculate the angle difference between line segment E and line segment F. If the angle difference is greater than a given threshold, line segment E and line segment F do not overlap; otherwise, calculate the distances R1 and R2 from the start point of E to the start point and end point of F, and the distances R3 and R4 from the end point of E to the start point and end point of F. If max(max(R1, R2), max(R3, R4)) >= (max(L1, H1) + min(L1, H1) / 2), line segment E and line segment F do not overlap; otherwise, if max(R1, R2)
[0087] In S7, the left and right vertical planes corresponding to each upper surface quadrilateral are obtained according to the segmented image of the left vertical plane and the right vertical segmented image, and the specific method for realizing the positioning of the cubic object is: traverse all the cubic object contour sets, obtain all the contours of the left vertical plane and their corresponding rotated rectangles and circumscribed rectangles according to the segmented image of the left vertical plane, judge whether the y coordinate of the center point of the rotated rectangle is greater than or equal to the y coordinate of the center point of the upper surface quadrilateral, if the y coordinate of the center point of the rotated rectangle is less than the y coordinate of the center point of the upper surface quadrilateral, process the next contour; if the y coordinate of the center point of the rotated rectangle is greater than or equal to the y coordinate of the center point of the upper surface quadrilateral, judge the cubic object corresponding to the upper surface quadrilateral. Is the ratio of the overlapping area of the cubic object contour area and the circumscribed rectangle to the cubic object contour area greater than or equal to 0.6? If it is greater than or equal to 0.6, find the contour with the largest area among all left vertical contours that meet the above conditions, which is the left vertical contour of the current cubic object; obtain all contours of the right vertical surface and their corresponding rotated rectangles and circumscribed rectangles according to the right vertical segmentation image, and process all contours of the right vertical segmentation image in the same way as all contours of the left vertical surface, so as to obtain the left vertical surface and right vertical surface corresponding to the upper surface of each cubic object, and each group of upper surface, left vertical surface and right vertical surface constitutes a cubic object, so as to realize cubic object detection. 0.6 is the given area ratio threshold.
[0088] In S8, the plane of the cube in the three-dimensional space is fitted according to the upper surface, the left vertical surface and the right vertical surface. The noise points on each surface are eliminated by repeated fitting. The specific method of obtaining the ideal point set corresponding to each surface is as follows: C1. All pixel points on the upper surface of each detected cubic object are traversed, and the world coordinate points of all pixel points on the upper surface in the three-dimensional space are obtained according to the transformation relationship between the image coordinate system and the world coordinate system; C2. All world coordinate points on the current upper surface are traversed, and a point count threshold is given to determine whether all the points are greater than the given point count threshold; C3. If the point count is greater than the point count threshold, the mean point of all points is calculated and normalized. All coordinate points on the upper surface of each cubic object are located in the same plane in the three-dimensional space, and the mean point is located on the plane. The normal vector of the plane in the three-dimensional space where the mean point is located is calculated according to Normal vector and mean point to obtain its fitting three-dimensional plane equation; C4, calculate the distance from all world coordinate points of the upper surface to the first fitting three-dimensional plane, give a distance threshold, eliminate all points with a distance greater than the given distance threshold, obtain an ideal point set, and perform fitting again according to the ideal point set to obtain the second fitting three-dimensional plane equation; C5, repeat the above steps for multiple fittings, calculate the distance from all points of the ideal point set to the fitting three-dimensional plane after each fitting, eliminate all points with a distance greater than the given distance threshold, update the ideal point set, and record it as the upper ideal point set; C6, for the left and right perpendicular surfaces of the cubic object, use the same method as the upper surface to obtain the fitting three-dimensional plane equations of the corresponding left and right perpendicular surfaces in the three-dimensional space and their corresponding left perpendicular surface ideal point set and right perpendicular surface ideal point set, which are recorded as the left ideal point set and the right ideal point set. The number of fittings in C5 can be determined according to the actual situation, and the final fitting three-dimensional plane equation of the current upper surface and the corresponding upper surface ideal point set are obtained after multiple repeated fittings.
[0089] In S9, the contour boundary and corner points of each face are obtained according to the ideal point set of each face, and the length, width and height of the cube are obtained according to the coordinates of its corner points in three-dimensional space. The specific method for calculating the volume of the cubic object is: obtain the plane coordinate points corresponding to all world coordinate points of the upper ideal point set, the left ideal point set and the right ideal point set in the two-dimensional plane, and perform contour detection based on them, obtain all contours, calculate the overlapping area of the circumscribed rectangle of each contour and the circumscribed rectangle of the upper surface corresponding to the upper ideal point set, find the contour with the largest overlapping area and greater than a given threshold, and the contour is the final contour of the upper surface, calculate the convex hull of the upper surface according to the contour, obtain its corresponding fitting polygon according to its convex hull, and obtain all edges of the fitting polygon of the upper surface Lines, these edge lines are the contour boundaries of the upper surface, and the contour boundaries of the left and right vertical surfaces of the upper surface are obtained in the same way; according to the contour boundary of the upper surface, its four corner points are obtained, and the world coordinates of the four corner points corresponding to the three-dimensional space are obtained. The world coordinates are its coordinates in the actual space. The length and width of the upper surface are calculated according to the world coordinates, which are the length and width of the current cubic object; the larger vertical surface of the left and right vertical surfaces is selected, and its four corner points are obtained according to the contour boundary of the vertical surface, and the world coordinates of the four corner points corresponding to the three-dimensional space are obtained. The world coordinates are its coordinates in the actual space. The height of the vertical surface is calculated according to the world coordinates, which is the height of the current cube, and the volume of the cubic object is calculated according to the length, width and height of the cube.
[0090] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, 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 method for calculating the volume of cubic objects based on depth image with noise removed. It is characterized in that include: S1. Obtain a depth image of a cubic object, and obtain gradient maps of the same size in the X and Y directions according to the depth image; S2. Classify the pixels in the gradient map into three categories: horizontal plane, left vertical plane and right vertical plane, and obtain an edge point map of the depth image; S3. Obtain segmented images of the upper surface, left vertical plane and right vertical plane of the cubic object in the depth image according to the classification results, the gradient map and the edge point map; S4. Perform edge line detection on the edge point map, cluster and merge all detected edge lines, and obtain a set of collinear edge line groups; S5. Extract corner points according to the longest edge line of each group of collinear edge line groups; S6. Points are matched; S7, the upper surface and the overall contour of the cubic object are determined according to the acquired quadrilateral and upper surface segmentation images, and the left and right vertical planes corresponding to each upper surface quadrilateral are obtained according to the segmentation image of the left vertical plane and the right vertical segmentation image, so as to realize the positioning of the cubic object; S8, the plane of the cubic object in the three-dimensional space is fitted according to the upper surface, the left vertical plane and the right vertical plane, and the noise points on each surface are eliminated by repeated fitting to obtain the ideal point set corresponding to each surface; S9, the contour boundary and corner points of each surface are obtained according to the ideal point set of each surface, and the length, width and height of the cubic object are obtained according to the coordinates of its corner points in the three-dimensional space, and the volume of the cubic object is calculated; The specific method of obtaining the segmented images of the upper surface, left vertical surface and right vertical surface of the cubic object in the depth image according to the classification results, the gradient map and the edge point map is as follows: According to the classification results, binary images of the horizontal plane, left vertical plane and right vertical plane with the same size as the gradient map are obtained, and the upper surface segmentation image with the same size as the gradient map is defined, and the initial value of the pixel point is set to 0; Traverse the pixels in the first column of the binary image of the horizontal plane from bottom to top, obtain the credibility value of each pixel according to the depth map, give a credibility threshold, if the credibility value of the pixel is less than the given credibility threshold, the state of the pixel is unknown, and process the next pixel; otherwise, if the corresponding pixel value is 255, the state of the pixel is horizontal, if the corresponding pixel is 0, the state of the pixel is vertical, if the number of pixels with a pixel value of 0 is greater than the given height threshold, then the pixels with a pixel value of 255 that appear later are mapped to the upper surface segmentation image and their pixel values are updated to 255, and the row number of the pixel where the pixel state changes each time is recorded. After traversing all rows of the first column, set the pixel values of all pixels in the first column from the recorded row number to the first row corresponding to the position on the upper surface segmentation image to 0, traverse all rows and columns of the parallel surface image in the same way, obtain the initial upper surface segmentation image, repair the obtained initial upper surface segmentation image, and update the upper surface segmentation image; The edge points in the edge point map are respectively matched one by one in the updated upper surface segmentation image, the binary map of the left vertical surface, and the binary map of the right vertical surface, the pixel values of the horizontal non-edge points in the updated upper surface segmentation image are updated to 0, the pixel values of the non-edge points in the binary map of the left vertical surface with a pixel value of 255 are updated to 0, and the pixel values of the non-edge points in the binary map of the right vertical surface with a pixel value of 255 are updated to 0, and the final upper surface segmentation image, the binary map of the left vertical surface, and the binary map of the right vertical surface are obtained, and the binary map of the left vertical surface and the binary map of the right vertical surface are recorded as the segmentation image of the left vertical surface and the segmentation image of the right vertical surface, respectively; The specific method of performing edge line detection on the edge point graph, clustering and merging all detected edge lines, and obtaining a set of collinear edge line groups is as follows: Perform edge line detection on the edge point graph, obtain all edge lines and sort them into edge line sets from long to short, define an empty collinear edge line group set, the collinear edge line group set contains multiple groups of edge lines, the edge lines in each group are collinear, and the edge lines between two groups are not collinear. First, add the longest edge line to one of the collinear edge line group sets, for each A edge line in the edge line set, determine whether it is collinear with the longest B edge line in each group of the collinear edge line group set, and the judgment conditions are as follows: C1. Calculate the angle difference between edge line A and edge line B, and determine whether the angle difference is less than or equal to a given angle difference threshold value e; C2. If the angle difference is less than or equal to the angle difference threshold e, calculate the distances T1 and T2 from the start point of edge line B to the start point and end point of edge line A, and the distances T3 and T4 from the end point of edge line B to the start point and end point of edge line A. Given the point distance threshold G, determine whether the minimum distance among the distances T1, T2, T3 and T4 is less than or equal to the point distance threshold G. C3. If min(min(T1, T2), min(T3, T4))≤G, calculate the length L of edge line A and the length H of edge line B, and determine whether the maximum distance among distances T1, T2, T3 and T4 is less than G+H+L; C4. If max(max(T1, T2), max(T3, T4))<(G+H+L), calculate the distances S1 and S2 from the start and end points of edge line B to edge line A, and the distances S3 and S4 from the start and end points of edge line A to edge line B. Given a distance threshold J, if the maximum distance between T1 and T2 is less than L+G, determine whether S1 is less than or equal to J; if the maximum distance between T3 and T4 is less than L+G, determine whether S2 is less than or equal to J; if the maximum distance between T1 and T3 is less than L+G, determine whether S3 is less than or equal to J; if the maximum distance between T2 and T4 is less than L+G, determine whether S4 is less than or equal to J; if any maximum distance is greater than or equal to L+G, directly execute the next step; C5. If the condition in C4 is met, the edge line A and the edge line B are collinear, and the edge line A is added to the group of the collinear edge line group set, and the edge line of the group is updated; During the judgment process, if any condition is not met, directly process the longest edge line of the next group in the collinear edge line group set, until all groups in the collinear edge line group set are processed, and each group of edge lines is represented by its longest edge line. If edge line A is not collinear with the longest edge lines of all groups in the collinear edge line group set, directly add edge line A to the new group in the collinear edge line group set, and update the number of groups in the collinear edge line group set; after edge line A and edge line B are collinear, determine whether edge line A and edge line B meet the merging condition. If T1≤H, T2≤H, T3≤H and T4≤H, edge line A and edge line B do not meet the merging condition, otherwise, merge edge line A and edge line B, update the starting point and end point of edge line B, and update the collinear edge line group set; Process the next edge line in the edge line set in the same way as processing edge line A, continuously update the collinear edge line group set, sort the edge lines of each group in the collinear edge line group set by length, and obtain the final collinear edge line group set; The specific method of extracting corner points based on the longest edge line of each group of collinear edge line groups is: C1. Get the longest edge line of each group of collinear edge line groups, record it as the seed edge line set, sort all the edge lines of the seed edge line set from long to short, traverse all the edge lines of the seed edge line set, and start from the longest C edge line to calculate the angle a between it and any other D edge line, where a ranges from 0 to 180 degrees. Given a curvature threshold b, determine whether min (a, 180-a) is greater than b; C2. If min(a, 180-a)>b, calculate the intersection point W(Wx, Wy) of the edge line C and the edge line D, and determine whether Wx or Wy does not exceed the image range; C3. If Wx or Wy does not exceed the image range, determine whether the intersection W is a corner point. The condition for determining whether the intersection W is a corner point is as follows: first calculate the distances d1 and d2 from the two endpoints of the C edge line to the intersection W, and define the minimum distance min_d1. If the intersection W is between the two endpoints of the C edge line, then min_d1=0, otherwise min_d1=min(d1, d2). If the minimum distance min_d1 is not 0 or min(d1, d2) is less than the given arm length threshold Z1, then calculate the distances d3 and d4 from the two endpoints of the D edge line to the intersection W, and define the minimum distance min_d2. If the intersection W is between the two endpoints of the D edge line, then min_d2=0, otherwise min_d2=min(d3, d4). If the minimum distance min_d2 is not 0 or min(d3, d4) is less than the given arm length threshold Z2, determine whether min(d1, d2) and min(d3, d4) are less than the given intersection radius threshold r. C4. If the condition of C3 is met, given the threshold value v of the gap between the arms of the quadrilateral, determine whether max(min(d1, d2), min(d3, d4)) is less than or equal to v. If so, the intersection point W is the corner point of the quadrilateral. The conditions C1 to C4 are judged in sequence. If any condition is not met, the next edge line is processed; The first corner point obtained is added to the corner point set. For the remaining corner points obtained, the distance Li between them and all the corner points in the corner point set is calculated, where i is a variable. It is determined whether they are similar to all the corner points in the corner point set. If Li < r and they are not similar to the remaining corner points, the corner point is added to the corner point set. The intersection point W corresponds to two arms, the first arm is the line connecting it with the end point of the C edge line, and the second arm is the line connecting it with the end point of the D edge line. The end point of the C edge line is the larger corresponding endpoint of d1 and d2 in the C edge line, and the end point of the D edge line is the larger corresponding endpoint of d3 and d4 in the D edge line. The same method is used to process any other two edge lines in the seed edge line group set to obtain all corner points, and the two arms of each corner point are expanded according to the seed edge line set to obtain the final corner point set, thereby realizing corner point extraction.
2. The method for calculating the volume of a cubic object by removing noise based on a depth image according to claim 1, It is characterized in that The specific method of pairing the extracted corner points is: C1. Pair all corner points in the corner point set. If the coordinates of the two paired corner points are different, continue to determine whether the two corner points share an arm. Mark the two arms of one corner point as arm11 and arm12, and the two arms of the other corner point as arm21 and arm22. First determine whether arm11 and arm21 are the same arm of the two corner points. C2. The method of judging whether arm11 and arm21 are the same arm is as follows: if the distance between the two corner points is greater than one-fourth of the minimum value of arm11 and arm21, first calculate the absolute value x1 of the angle difference between arm11 and the line connecting the two corner points, and the absolute value x2 of the angle difference between arm21 and the line connecting the two corner points. The value range of x1 and x2 is [0, 180]. Given an angle similarity threshold f, if both x1 and x2 are less than the angle similarity threshold f, given a corner point distance threshold u and a length ratio threshold ratio, if the sum of the lengths of arm11 and arm21 is greater than or equal to ratio times the distance between the two corner points, and greater than or equal to the difference between the distance between the two corner points and u, then arm11 and arm21 are judged to be the same arm and the corner point pairing is successful. Otherwise, the same method is used to determine whether the other two arms of the two corner points are the same arm. If neither is the case, the corner point pairing fails, otherwise the corner point pairing succeeds. In the same way, the remaining corner points are paired in pairs to obtain all successfully paired corner point combinations. The same arm of each corner point combination is the shared arm, and the other two arms are open arms. The angles u1 and u2 between the two open arms and the shared arm in each corner point combination are calculated. The value range of the angles u1 and u2 is [0, 180]. The corner point combinations whose angles u1 or u2 are less than the curvature threshold b are eliminated; for the remaining corner point combinations, determine whether their two open arms are on the same side of the shared arm, and eliminate the corner point combinations whose two open arms are not on the same side of the shared arm. Finally, determine a quadrilateral based on the currently paired corner point combination; process all corner point combinations in the same way to obtain all quadrilaterals.
3. The method for calculating the volume of a cubic object by removing noise based on a depth image according to claim 2, It is characterized in that The specific method of determining the upper surface and overall contour of the cubic object based on the acquired quadrilateral and upper surface segmentation images is as follows: C1. First, process the obtained quadrilateral. If the distance between the end points of the two arms of the matching quadrilateral is less than the given distance ratio threshold, the quadrilateral does not meet the requirements. Then process the next quadrilateral, obtain all the quadrilaterals that meet the requirements, and obtain the outline and circumscribed rectangle of each quadrilateral. Calculate its convex hull according to the outline coordinate points. C2. Perform contour detection based on the upper surface segmentation image, obtain all contours, calculate their convex hulls based on the contour coordinate points, obtain the smallest rotated rectangle containing each contour and the circumscribed rectangle containing the rotated rectangle, calculate the area of each contour, and determine whether the area of the contour is greater than a given area threshold; C3. If the area of the contour is greater than the area threshold, match the current contour with a qualified quadrilateral, calculate the minimum distances h1 and h2 from the two corner points of the matching quadrilateral to the convex hull of the current contour, and determine whether the two corner points of the matching quadrilateral are outside the convex hull of the matching quadrilateral and whether h1 and h2 are less than or equal to the given distance threshold; C4. If the two corner points of the matching quadrilateral are outside the convex hull of the matching quadrilateral and h1 and h2 are both less than or equal to the distance threshold, determine whether the center point of the rotated rectangle outside the current contour is inside the convex hull of the matching quadrilateral; C5. If the center point of the rotated rectangle outside the current contour is located inside the convex hull of the matching quadrilateral, calculate the absolute value of the minimum distance from the rotated rectangle to the convex hull of the matching quadrilateral, and satisfy the conditions that the value is less than or equal to the length and width of the rotated rectangle, and the center point is located on the lower side of any arm of the matching quadrilateral, calculate the overlapping area of the circumscribed rectangle of the matching quadrilateral and the circumscribed rectangle of the current contour, if the overlapping area is greater than a given ratio threshold, the current contour and the matching quadrilateral are preliminarily matched successfully, and the matching quadrilateral is recorded as the preliminarily matched quadrilateral; C6. Normalize the distance from the center point of the rotated rectangle of the current contour to the three arms of the preliminary matching quadrilateral. If the normalized value is within the theoretical range and the sum of h1 and h2 is less than or equal to a given threshold, the preliminary matching quadrilateral is recorded as a valid quadrilateral. C7. Determine whether the two open arms of the valid quadrilateral are facing downward, and record the valid quadrilateral with two open arms facing downward as a seed quadrilateral; if the next seed quadrilateral is obtained, calculate whether the sum of the minimum distances from the two corner points of the seed quadrilateral to its contour is less than the sum of the minimum distances from the two corner points of the previous seed quadrilateral to its contour, if so, replace the previous seed quadrilateral with the current seed quadrilateral, otherwise remove the current seed quadrilateral, and continue processing until the final seed quadrilateral of the current contour is obtained; C8, determine whether the final seed quadrilateral of the current contour has shared corner points with the valid quadrilateral; C9. If there is a shared corner point, determine whether the line segments where the shared arms and open arms of the valid quadrilateral are located overlap with the line segments where the shared arms of the seed quadrilateral are located. If there is an overlap, determine whether the number of overlaps between the line segments where the shared arms and open arms of the valid quadrilateral are located and the line segments where the open arms of the seed quadrilateral are located is greater than or equal to 1. If so, obtain a cubic object contour with the three arms of the seed quadrilateral as the edges of the upper surface and the arms of the valid quadrilateral other than the overlapping arms as the edges of the lateral vertical surfaces, obtain all cubic object contours, and record them as a cubic object contour set; C10, obtaining the coordinates of all points of the cubic object contour according to the endpoints of each edge of the cubic object contour, where the cubic object contour uses the seed quadrilateral as the upper surface; C11. Traverse the cubic object contour set, calculate the y coordinate Py of the center point of each cubic object contour and the y coordinate ty of the center point of its upper surface, calculate the area P.area of each cubic object contour and the area t.area of its upper surface. If ty>Py or t.area>P.area, remove the cubic object contour and obtain the final cubic object contour set.
4. The method for calculating the volume of a cubic object by removing noise based on a depth image according to claim 3, It is characterized in that The left and right vertical planes corresponding to each upper surface quadrilateral are obtained according to the segmented image of the left vertical plane and the segmented image of the right vertical plane, and the specific method of realizing the positioning of the cubic object is as follows: traverse all cubic object contour sets, obtain all contours of the left vertical plane and their corresponding rotated rectangles and circumscribed rectangles according to the segmented image of the left vertical plane, and judge whether the y coordinate of the center point of the rotated rectangle is greater than or equal to the y coordinate of the center point of the upper surface quadrilateral; if the previous condition is met, judge whether the ratio of the overlapping area of the cubic object contour area corresponding to the upper surface quadrilateral and the circumscribed rectangle to the cubic object contour area is greater than or equal to a given area ratio threshold; if it is greater than or equal to the area ratio threshold, find the contour with the largest area among all left vertical plane contours that meet the above conditions, which is the left vertical plane contour of the current cubic object; According to the right vertical segmentation image, all contours of the right vertical surface and their corresponding rotated rectangles and circumscribed rectangles are obtained. The processing method for all contours of the right vertical segmentation image is consistent with the processing method for all contours of the left vertical surface, so as to obtain the left vertical surface and right vertical surface corresponding to the upper surface of each cubic object. Each group of upper surface, left vertical surface and right vertical surface constitutes a cubic object, realizing cubic object detection.
5. The method for calculating the volume of a cubic object by removing noise based on a depth image according to claim 3, It is characterized in that In S8, the plane of the cube in three-dimensional space is fitted according to the upper surface, left vertical plane and right vertical plane. The noise points on each surface are eliminated by repeated fitting. The specific method of obtaining the ideal point set corresponding to each surface is as follows: C1. Traverse all the pixel points on the upper surface of each detected cubic object, and obtain the world coordinate points of all the pixel points on the upper surface in the three-dimensional space according to the transformation relationship between the image coordinate system and the world coordinate system; C2, traverse all world coordinate points on the current upper surface, give a point count threshold, and determine whether all points are greater than the given point count threshold; C3. If the number of points is greater than the point threshold, calculate the mean point of all points and perform normalization. All coordinate points on the upper surface of each cubic object are located in the same plane in the three-dimensional space, and the mean point is located on the plane. Calculate the normal vector of the plane in the three-dimensional space where the mean point is located, and obtain the initial fitting three-dimensional plane equation based on the normal vector and the mean point. C4, calculate the distances from all world coordinate points on the upper surface to the first fitted three-dimensional plane, give a distance threshold, remove all points whose distances are greater than the given distance threshold, obtain an ideal point set, perform fitting again based on the ideal point set, and obtain a second fitted three-dimensional plane equation; C5. Repeat the above steps to perform multiple repetitive fittings. After each fitting, calculate the distances from all points in the ideal point set to the fitted three-dimensional plane, remove all points whose distances are greater than a given distance threshold, and update the ideal point set, which is recorded as the upper ideal point set. C6. For the left and right perpendicular surfaces of the cubic object, the same method as the upper surface is used to obtain the fitting three-dimensional plane equations of the corresponding left and right perpendicular surfaces in the three-dimensional space and their corresponding left perpendicular surface ideal point sets and right perpendicular surface ideal point sets, which are recorded as the left ideal point set and the right ideal point set.
6. The method for calculating the volume of a cubic object by removing noise based on a depth image according to claim 5, It is characterized in that In S9, the contour boundary and corner points of each face are obtained according to the ideal point set of each face, and the length, width and height of the cube are obtained according to the coordinates of its corner points in three-dimensional space. The specific method for calculating the volume of the cubic object is: obtain the plane coordinate points corresponding to all world coordinate points of the upper ideal point set, the left ideal point set and the right ideal point set in the two-dimensional plane, and perform contour detection based on them, obtain all contours, calculate the overlapping area of the circumscribed rectangle of each contour and the circumscribed rectangle of the upper surface corresponding to the upper ideal point set, find the contour with the largest overlapping area and greater than a given threshold, and the contour is the final contour of the upper surface, calculate the convex hull of the upper surface according to the contour, and obtain its corresponding fitting polygon according to its convex hull. Shape, get all the edge lines of the fitting polygon of the upper surface, these edge lines are the contour boundary of the upper surface, and use the same method to get the contour boundary of the left and right vertical planes; according to the contour boundary of the upper surface, get its four corner points, and get the world coordinates of the four corner points corresponding to it in the three-dimensional space, and calculate the length and width of the upper surface according to the world coordinates, which are the length and width of the current cubic object; select the larger vertical plane of the left and right vertical planes, get its four corner points according to the contour boundary of the vertical plane, and get the world coordinates of the four corner points corresponding to it in the three-dimensional space, and calculate the height of the vertical plane according to the world coordinates, which is the height of the current cube, and calculate the volume of the cubic object according to the length, width and height of the cube.
7. The method for calculating the volume of a cubic object by removing noise based on a depth image according to claim 1, It is characterized in that The specific method of extending the two arms of each corner point according to the seed edge line set is: Traverse all edge lines of the seed edge line set, and for each corner point, calculate the distance from it to the current seed edge line. If the distance is less than a given threshold, determine whether the seed edge line can extend the two arms of the current corner point. First, determine whether the seed edge line can extend arm 1 of the current corner point. The specific method is: C1. Calculate the distance from the current corner point to the starting point and the end point of the seed edge line, recorded as dist1 and dist2, and determine whether the current corner point is between the two end points of the seed edge line; C2. If the current corner point is between the two endpoints of the seed edge line, the line segment from the current corner point to the starting point of the seed edge line is recorded as M, the starting point of line segment M is the current corner point, the end point is the starting point of the seed edge line, the line segment where arm 1 of the current corner point is located is recorded as N, the starting point of line segment N is the current corner point, calculate the angle angle1 of line segment M and the angle angle2 of line segment N, and determine whether the absolute value of the difference between angle1 and angle2 is less than the given angle threshold; C3. If the absolute value of the difference between angle1 and angle2 is less than the given angle threshold, calculate the distance rM from the end point of line M to the current corner point, calculate the length rN of line segment N, and determine whether the difference between rM and rN is less than the given length difference threshold; C4. If the difference between rM and rN is less than the given length difference threshold, calculate the end point of line segment N The distance to the current seed edge line. If the distance is less than the given point-to-line distance threshold and dist1 is greater than rN, the current seed edge line can extend the arm 1 of the current corner point. The end point of the extended arm 1 of the current corner point is the starting point of the seed edge line, and the length of the extended arm 1 is dist1. C5: If any of the conditions from C2 to C4 is not met, it means that the current seed edge line cannot be expanded. For the arm 1 of the current corner point, the same method is used to determine whether the current seed edge line can extend the arm 2 of the current corner point. If it can be extended, the end point of the extended arm 2 is the starting point of the seed edge line, and the length of the extended arm 2 is dist1. If it cannot be extended, directly execute the next step; C6, update the end point of line segment M in C2 to the end point of the current seed edge line, update line segment N to the line segment where arm 2 of the current corner point is located, the starting point of line segment N is the current corner point, dist1 is updated to dist2, and the same method is used to determine again whether the current seed edge line can extend arm 1 and arm 2 of the current corner point to achieve the extension of the two arms of the current corner point; C7. At this time, if the condition in C1 is not met, determine whether dist1 is less than or equal to dist2; C8, if dist1 is less than or equal to dist2, update the starting point of line segment M in C2 to the starting point of the current seed edge line, and the end point to the end point of the current edge line. Line segment N is the line segment where arm 1 or arm 2 of the current corner point is located. Use the same method to determine whether the current seed edge line can extend arm 1 and arm 2 of the current corner point to achieve the extension of the two arms of the current corner point. C9. If dist1 is greater than dist2, update the starting point of the line segment M in C2 to the end point of the current seed edge line, and the end point is updated to the starting point of the current edge line. The line segment N is the line segment where arm 1 or arm 2 of the current corner point is located. Dist1 is updated to dist2. The same method is used to determine whether the current seed edge line can extend arm 1 and arm 2 of the current corner point to achieve the extension of the two arms of the current corner point.
Citation Information
Patent Citations
Object size measurement method based on depth image processing
CN109472822A
Measurement of dimensions of solid objects from two-dimensional image(s)
US6995762B1
