CN110728246A - A Cube Object Recognition Method Based on Depth Image - Google Patents
A Cube Object Recognition Method Based on Depth Image Download PDFInfo
- Publication number
- CN110728246A CN110728246A CN201910989775.9A CN201910989775A CN110728246A CN 110728246 A CN110728246 A CN 110728246A CN 201910989775 A CN201910989775 A CN 201910989775A CN 110728246 A CN110728246 A CN 110728246A
- Authority
- CN
- China
- Prior art keywords
- point
- edge line
- edge
- corner
- quadrangle
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V20/00—Scenes; Scene-specific elements
- G06V20/60—Type of objects
- G06V20/64—Three-dimensional objects
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/22—Matching criteria, e.g. proximity measures
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/23—Clustering techniques
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/24—Classification techniques
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/136—Segmentation; Edge detection involving thresholding
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/20—Image preprocessing
- G06V10/28—Quantising the image, e.g. histogram thresholding for discrimination between background and foreground patterns
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/10—Image acquisition modality
- G06T2207/10028—Range image; Depth image; 3D point clouds
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/40—Extraction of image or video features
- G06V10/46—Descriptors for shape, contour or point-related descriptors, e.g. scale invariant feature transform [SIFT] or bags of words [BoW]; Salient regional features
- G06V10/469—Contour-based spatial representations, e.g. vector-coding
- G06V10/473—Contour-based spatial representations, e.g. vector-coding using gradient analysis
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Life Sciences & Earth Sciences (AREA)
- Artificial Intelligence (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Bioinformatics & Computational Biology (AREA)
- Evolutionary Biology (AREA)
- Evolutionary Computation (AREA)
- General Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Image Analysis (AREA)
Abstract
本发明提出一种基于深度图像的立方物体识别方法,包括:S1、获取目标的深度图像及其X方向和Y方向的梯度图;S2、根据梯度图对其中的像素点进行分类,获取边缘点图;S3、根据上述结果获取深度图像中目标的上表面、左垂面和右垂面的分割图像;S4、对边缘点图进行边缘线检测,将检测到的所有边缘线进行聚类与合并,获取共线边缘线组集合;S5、根据共线边缘线组集合的每组最长的边缘线提取角点;S6、对提取的角点进行配对,获取四边形;S7、确定立方物体的上表面和整体轮廓;S8、获取每个上表面四边形对应的左右垂直面,实现立方物体定位。本发明应用在物流行业中,解决对立方物体状包裹等目标的体积测量局限和耗时的问题,提高包裹分拣效率。The present invention proposes a method for recognizing a cube object based on a depth image, including: S1, acquiring a depth image of the target and its gradient maps in the X and Y directions; S2, classifying the pixel points in it according to the gradient map, and acquiring edge points Figure; S3, obtain the segmented images of the upper surface, the left vertical plane and the right vertical plane of the target in the depth image according to the above results; S4, carry out edge line detection to the edge point map, and cluster and merge all detected edge lines , obtain a set of collinear edge line groups; S5, extract corner points according to the longest edge line of each group of the collinear edge line group set; S6, pair the extracted corner points to obtain a quadrilateral; S7, determine the upper surface of the cubic object Surface and overall outline; S8, obtain the left and right vertical planes corresponding to each upper surface quadrangle, and realize the positioning of the cubic object. The invention is applied in the logistics industry, solves the problems of volume measurement limitation and time-consuming for objects such as cube-shaped packages, and improves the efficiency of package sorting.
Description
技术领域technical field
本发明涉及深度图像的目标识别领域,特别涉及一种基于深度图像的立方物体识别方法。The invention relates to the field of target recognition of depth images, in particular to a method for recognizing cubic objects based on depth images.
背景技术Background technique
深度图像也被称为距离影像,是指将从图像采集器到场景中各点的距离作为像素值的图像,它直接反映了目标可见表面的几何形状,因此,基于深度图像的应用比较广泛,尤其是在物流行业。目前,国内物流、港口航运、机场航运的吞吐量非常大,且呈递增趋势,各个分拣中心对包裹、货物、货柜等体积的测量比较局限和耗时,降低了运输效率。Depth image, also known as range image, refers to an image whose pixel value is taken from the distance from the image collector to each point in the scene. It directly reflects the geometry of the visible surface of the target. Therefore, depth image-based applications are widely used. Especially in the logistics industry. At present, the throughput of domestic logistics, port shipping, and airport shipping is very large, and it is increasing. The volume measurement of parcels, goods, and containers by various sorting centers is relatively limited and time-consuming, which reduces transportation efficiency.
现有技术中,包裹多为立方物体状,对包裹的体积测量主要通过比对传输带装货前和装货后的深度图像,提取包裹所在的矩形区域获知包裹的长宽,利用差异特征获取包裹的高度,计算包裹的体积,这种方式局限于特定场景,应用范围较小,无法满足实际物流行业中包裹密集堆积的需求;另外,现有技术大部分没有对长方体状的平面进行区分,容易造成长方体状的物体长宽高的误判,导致体积计算误差较大;而且现有技术中大部分要求相机垂直拍摄物体,对相机拍摄角度限制较大,基本上只能检测单个物体,多个物体检测误差较大,同时对于立方物体的多个面难以准确检测,且受外界环境噪声干扰,影响计算精度。目前对大型的货物、货柜的体积测量也基本采用手工测量。In the prior art, most of the packages are in the shape of cubic objects. The volume measurement of the package is mainly by comparing the depth images of the conveyor belt before and after loading, extracting the rectangular area where the package is located to know the length and width of the package, and using the difference feature to obtain the package. This method is limited to specific scenarios and has a small scope of application, which cannot meet the needs of dense accumulation of parcels in the actual logistics industry; Causes misjudgment of the length, width and height of the cuboid-shaped object, resulting in a large volume calculation error; and most of the existing technologies require the camera to shoot the object vertically, which limits the camera's shooting angle. Basically, only a single object can be detected. The object detection error is large, and it is difficult to accurately detect multiple faces of a cubic object, and the calculation accuracy is affected by the interference of external environmental noise. At present, the volume measurement of large goods and containers is basically manual measurement.
发明内容SUMMARY OF THE INVENTION
为解决现有技术中对立方物体状包裹、货物、货柜等目标的体积测量局限和耗时的问题,本发明提出一种基于深度图像的立方物体识别方法。In order to solve the problems of limited and time-consuming volume measurement of objects in the shape of cubic objects such as packages, goods, and containers in the prior art, the present invention proposes a method for recognizing cubic objects based on depth images.
本发明的技术方案是这样实现的:The technical scheme of the present invention is realized as follows:
一种基于深度图像的立方物体识别方法,包括:A cube object recognition method based on depth image, comprising:
S1、获取目标的深度图像,根据深度图像分别获取与其大小相同的X方向和Y方向的梯度图;S2、根据梯度图对其中的像素点分为水平面、左垂面和右垂面三类,获取深度图像的边缘点图;S3、根据分类结果、梯度图和边缘点图获取深度图像中目标的上表面、左垂面和右垂面的分割图像;S4、对边缘点图进行边缘线检测,将检测到的所有边缘线进行聚类与合并,获取共线边缘线组集合;S5、根据共线边缘线组集合的每组最长的边缘线提取角点;S6、对提取的角点进行配对,获取四边形;S7、根据获取的四边形和上表面的分割图像确定立方物体的上表面和整体轮廓;S8、根据左垂面的分割图像和右垂面的分割图像获取每个上表面四边形对应的左右垂直面,实现立方物体定位。S1. Obtain the depth image of the target, and obtain the gradient maps in the X direction and the Y direction with the same size according to the depth image; S2. According to the gradient map, the pixels are divided into three categories: horizontal plane, left vertical plane and right vertical plane. Obtain the edge point map of the depth image; S3. Obtain the segmented images of the upper surface, the left vertical plane and the right vertical plane of the target in the depth image according to the classification result, the gradient map and the edge point map; S4, Perform edge line detection on the edge point map , clustering and merging all detected edge lines to obtain 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 group set; S6, extracting corner points Pairing is performed to obtain a quadrilateral; S7, the upper surface and the overall outline of the cubic object are determined according to the obtained quadrilateral and the segmented image of the upper surface; S8, each upper surface quadrilateral is obtained according to the segmented image of the left vertical plane and the segmented image of the right vertical plane The corresponding left and right vertical planes are used to realize the positioning of cubic objects.
优选的是,根据分类结果、梯度图和边缘点图获取深度图像中目标的上表面、左垂面和右垂面的分割图像的具体方式为:Preferably, according to the classification result, the gradient map and the edge point map, the specific method of obtaining the segmented images of the upper surface, the left vertical surface and the right vertical surface of the target in the depth image is as follows:
根据分类结果获取与梯度图大小相同的水平面、左垂面和右垂面的二值图,定义与梯度图大小相同的上表面的分割图像,设定像素点的初始值为0;According to the classification result, obtain the binary image of the horizontal plane, left vertical plane and right vertical plane with the same size as the gradient image, define the segmented image of the upper surface with the same size as the gradient image, and set the initial value of the pixel point to 0;
从下到上遍历水平面的二值图中第一列的像素点,根据深度图获取每个像素点的可信度值,给定可信度阈值,若该像素点的可信度值小于给定的可信度阈值,则该像素点的状态为未知,处理下一像素点;否则,若对应的像素点值为255,则该像素点的状态为水平,若对应的像素点为0,则该像素点的状态为垂直,若像素点值为0的像素点的数目大于给定的高度阈值,则将其后出现的像素点值为255的像素点对应在上表面的分割图像上并将其像素值更新为255,记录每一次像素点状态发生转变的像素点所在的行数,遍历完第一列所有行的像素点后,将从记录的行数起到第1行的第一列所有像素点对应在上表面的分割图像上的位置的像素值置为0,同样的方式遍历完平行面图像的所有行列,获取初始的上表面的分割图像,对获取的初始的上表面的分割图像进行修补,更新上表面的分割图像;Traverse the pixels in the first column of the binary image on the horizontal plane from bottom to top, obtain the credibility value of each pixel according to the depth map, and give the credibility threshold, if the credibility value of the pixel is less than the given credibility value If the reliability threshold is determined, 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, and if the corresponding pixel is 0, Then 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 correspond to the segmented image on the upper surface. Update its pixel value to 255, and record the number of rows where the pixel state changes each time. After traversing the pixels of all rows in the first column, it will start from the number of recorded rows to the first row of the first row. The pixel values of all the pixel points in the column corresponding to the positions on the upper surface segmented image are set to 0. In the same way, all rows and columns of the parallel plane image are traversed, and the initial upper surface segmented image is obtained. The segmented image is patched, and the segmented image on the upper surface is updated;
将边缘点图中的边缘点分别一一对应在更新后的上表面的分割图像、左垂面的二值图和右垂面的二值图中,将更新后的上表面的分割图像中水平状态的非边缘点的像素点值更新为0,将左垂面的二值图中非边缘点的像素值为255的像素点值更新为0,将右垂面的二值图中非边缘点的像素值为255的像素点值更新为0,获取最终的上表面的分割图像、左垂面的二值图和右垂面的二值图,将左垂面的二值图和右垂面的二值图分别记作左垂面的分割图像和右垂面的分割图像。The edge points in the edge point map are respectively corresponded one-to-one in the updated upper surface segmented image, the left vertical surface binary image and the right vertical surface binary image, and the updated segmented image of the upper surface is horizontally divided. The pixel value of the non-edge point of the state is updated to 0, the pixel value of the non-edge point in the left vertical plane is updated to 0, the pixel value of the non-edge point in the left vertical plane is 255, and the non-edge point in the right vertical plane is updated. The pixel value of 255 is updated to 0, and the final segmented image of the upper surface, the binary image of the left vertical plane and the binary image of the right vertical plane are obtained, and the binary image of the left vertical plane and the right vertical plane are obtained. The binary images of are denoted as the segmented image of the left vertical plane and the segmented image of the right vertical plane, respectively.
优选的是,获取深度图像的边缘点图的具体方式为:Preferably, the specific method for obtaining the edge point map of the depth image is:
计算分类后的垂直面的所有像素点的Y方向的梯度平均值Yp、水平面的所有像素点的Y方向的梯度平均值Yq、左垂面的所有像素点的X方向的梯度平均值Xp以及右垂面的所有像素点的X方向的梯度平均值Xq;根据Yp、Yq、Xp、Xq设定Y方向正阈值、Y方向负阈值、X方向正阈值、X方向负阈值;定义一个与梯度图大小相同的图像,该图像中的像素点的初始值设定为0;遍历X方向的梯度图和Y方向的梯度图的所有像素点,对于每一个像素点,如果其Y方向的梯度值的绝对值大于X方向的梯度值的绝对值,且小于Y方向负阈值或大于等于Y方向正阈值,该像素点为边缘点,将该像素点对应到定义的图像中并将其像素值更新为255;如果其Y方向的梯度值的绝对值小于X方向的梯度值的绝对值,且其X方向的梯度值的绝对值小于等于X方向负阈值或大于等于X方向正阈值,该像素点为边缘点,将该像素点对应到定义的图像中并将其像素值更新为255;得到边缘点图。Calculate the average gradient value Yp in the Y direction of all the pixels in the vertical plane, the gradient average value Yq in the Y direction of all the pixels in the horizontal plane, and the gradient average value Xp in the X direction of all the pixels in the left vertical plane. The average value Xq of the gradient in the X direction of all the pixels of the vertical plane; according to Yp, Yq, Xp, Xq, 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; define a gradient map with For images of the same size, the initial value of the pixels in the image is set to 0; traverse all the pixels of the gradient map in the X direction and the gradient map in the Y direction, for each pixel, if the gradient value in the Y direction is The absolute value is greater than the absolute value of the gradient value in the X direction, and is smaller than the negative threshold value in the Y direction or greater than or equal to the positive threshold value in the Y direction, the pixel point is an edge point, the pixel point corresponds to the defined image and its pixel value is updated as 255; if the absolute value of the 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 the gradient value in the X direction is less than or equal to the negative threshold value in the X direction or greater than or equal to the positive threshold value in the X direction, the pixel is Edge point, correspond the pixel point to the defined image and update its pixel value to 255; get the edge point map.
优选的是,对边缘点图进行边缘线检测,将检测到的所有边缘线进行聚类与合并,获取共线边缘线组集合的具体方式为:Preferably, edge line detection is performed on the edge point graph, and all detected edge lines are clustered and merged to obtain a set of collinear edge line groups as follows:
对边缘点图进行边缘线检测,获取所有边缘线并按照长到短排序成边缘线集合,定义一个空的共线边缘线组集合,共线边缘线组集合包含多组边缘线,每组内的边缘线是共线的,两组间边缘线是不共线的,首先将最长的边缘线加入到共线边缘线组集合的一组中,对于边缘线集合中的每一条A边缘线,判断其与共线边缘线组集合的每组最长的B边缘线是否共线,判断条件依次如下:Perform edge line detection on the edge point graph, obtain all edge lines and sort them into edge line sets according to length to short, and define an empty collinear edge line group set. The edge lines of A are collinear, and the edge lines between the two groups are not collinear. First, add the longest edge line to a set of collinear edge line sets. For each A edge line in the edge line set , judging whether it is collinear with the longest B edge line in each set of collinear edge line groups, and the judgment conditions are as follows:
C1、计算A边缘线与B边缘线的角度差,判断该角度差是否小于等于给定的角度差阈值e;C1. Calculate the angle difference between the A edge line and the B edge line, and determine whether the angle difference is less than or equal to a given angle difference threshold e;
C2、若角度差小于等于角度差阈值e,计算B边缘线的起点到A边缘线的起点和终点的距离T1和T2,B边缘线的终点到A边缘线的起点和终点的距离T3和T4,给定点间距离阈值G,判断距离T1、T2、T3和T4中的最小距离是否小于等于点间距离阈值G;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 the B edge line to the start point and end point of the A edge line, and the distances T3 and T4 from the end point of the B edge line to the start point and end point of the A edge line , given the distance threshold G between points, determine whether the minimum distance among the distances T1, T2, T3 and T4 is less than or equal to the distance threshold G between points;
C3、若min(min(T1,T2),min(T3,T4))≤G,计算A边缘线的长度L和B边缘线的长度H,判断距离T1、T2、T3和T4中的最大距离是否小于G+H+L;C3. If min(min(T1, T2), min(T3, T4)) ≤ G, calculate the length L of the edge line of A and the length H of the edge line of B, and judge the maximum distance among the distances T1, T2, T3 and T4 Is it less than G+H+L;
C4、若max(max(T1,T2),max(T3,T4))<(G+H+L),计算B边缘线的起点和终点到A边缘线的距离S1和S2,A边缘线的起点和终点到B边缘线的距离S3和S4,给定距离阈值J,若T1和T2的最大距离小于L+G,判断S1是否小于等于J;若距离T3和T4的最大距离小于L+G,判断S2是否小于等于J;若距离T1和T3的最大距离小于L+G,判断S3是否小于等于J;若距离T2和T4的最大距离小于L+G,判断S4是否小于等于J;若任意最大距离均大于等于L+G则直接执行下一步骤;C4. If max(max(T1, T2), max(T3, T4))<(G+H+L), calculate the distances S1 and S2 from the starting point and end point of the B edge line to the A edge line, and the distance of the A edge line The distances S3 and S4 from the starting point and the end point to the edge line of B, given the distance threshold J, if the maximum distance between T1 and T2 is less than L+G, judge whether S1 is less than or equal to J; if the maximum distance between T3 and T4 is less than L+G , judge whether S2 is less than or equal to J; if the maximum distance between T1 and T3 is less than L+G, judge whether S3 is less than or equal to J; if the maximum distance between T2 and T4 is less than L+G, judge whether S4 is less than or equal to J; if any If the maximum distance is greater than or equal to L+G, then directly execute the next step;
C5、若满足C4中的条件,则A边缘线和B边缘线共线,将A边缘线加入到共线边缘线组集合的该组中,更新该组的边缘线;C5. If the conditions in C4 are met, the A edge line and the B edge line are collinear, and the A edge line is added to the group of the collinear edge line group set, and the edge line of the group is updated;
判断过程中,任一个条件不满足,直接处理共线边缘线组集合中的下一组的最长边缘线,直至处理完共线边缘线组集合的所有组,每组边缘线用其最长边缘线表示,如果A边缘线与共线边缘线组集合的所有组的最长边缘线均不共线,则直接将A边缘线加入到共线边缘线组集合的新组中,更新共线边缘线组集合的组数;A边缘线和B边缘线共线后,判断A边缘线和B边缘线是否满足合并条件,若T1≤H、T2≤H、T3≤H且T4≤H,则A边缘线与B边缘线不满足合并条件,否则,将A边缘线和B边缘线合并,更新B边缘线的起点和终点,更新共线边缘线组集合;During the judgment process, if any of the conditions are not satisfied, the longest edge line of the next group in the set of collinear edge lines is directly processed, until all the groups of the set of collinear edge lines are processed, and the longest edge line of each set of edge lines is used. The edge line indicates that if the A edge line is not collinear with the longest edge line of all groups of the collinear edge line group set, the A edge line is directly added to the new group of the collinear edge line group set, and the collinear edge line is updated. The number of line group sets; after the A edge line and the B edge line are collinear, determine whether the A edge line and the B edge line meet the merging conditions. If T1≤H, T2≤H, T3≤H and T4≤H, then A The edge line and the B edge line do not meet the merging conditions, otherwise, the A edge line and the B edge line are merged, the starting point and the end point of the B edge line are updated, and the set of collinear edge line groups is updated;
与处理A边缘线相同的方式处理边缘线集合中的下一条边缘线,不断更新共线边缘线组集合,共线边缘线组集合中每组的边缘线按照长短排序,获取最终的共线边缘线组集合。Process the next edge line in the edge line set in the same way as processing the A edge line, and continuously update the collinear edge line group set. Line set collection.
优选的是,根据共线边缘线组集合的每组最长的边缘线提取角点的具体方式为:Preferably, the specific method of extracting the corner points according to the longest edge line of each group of the collinear edge line group set is:
C1、获取共线边缘线组集合的每组的最长边缘线,记作种子边缘线集合,将种子边缘线集合的所有边缘线按从长到短排序,遍历种子边缘线集合的所有边缘线,从其中最长的C边缘线开始计算其与其余任一条D边缘线的夹角a,a的范围是0到180度,给定弯曲度阈值b,判断min(a,180-a)是否大于b;C1. Obtain the longest edge line of each group of the collinear edge line set, record it as the seed edge line set, sort all the edge lines of the seed edge line set from long to short, and traverse all the edge lines of the seed edge line set , start from the longest C edge line and calculate the angle a between it and any other D edge lines. The range of a is 0 to 180 degrees. Given the curvature threshold b, determine whether min(a, 180-a) greater than b;
C2、若min(a,180-a)>b,计算C边缘线与D边缘线的交点W(Wx,Wy),判断Wx或Wy是否未超出图像范围;C2. If min(a, 180-a)>b, calculate the intersection point W(Wx, Wy) of the C edge line and the D edge line, and judge whether Wx or Wy does not exceed the image range;
C3、若Wx或Wy未超出图像范围,判断交点W是否是角点,判断交点W是角点的条件为:先计算C边缘线的两个端点到交点W的距离d1和d2,定义最小距离min_d1,如果交点W在C边缘线的两个端点之间,则min_d1=0,否则min_d1=min(d1,d2), 若最小距离min_d1不为0或min(d1,d2)小于给定的臂长阈值Z1,再计算D边缘线的两个端点到交点W的距离d3和d4,定义最小距离min_d2,如果交点W在D边缘线的两个端点之间,则min_d2=0,否则min_d2=min(d3,d4),若最小距离min_d2不为0或 min(d3,d4)小于给定的臂长阈值Z2,判断min(d1,d2)和min(d3,d4)是否小于给定的交点半径阈值r;C3. If Wx or Wy does not exceed the image range, determine whether the intersection point W is a corner point. The conditions for judging whether the intersection point W is a corner point are: first calculate the distances d1 and d2 from the two endpoints of the C edge line to the intersection point 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 Long 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, judge whether min(d1, d2) and min(d3, d4) are less than the given intersection radius threshold r;
C4、若满足C3的条件,给定四边形臂间差距阈值v,判断max(min(d1,d2),min(d3,d4))是否小于等于v,若满足则交点W是四边形的角点;C4. If the condition of C3 is met, given the threshold v of the gap between the arms of the quadrilateral, judge 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;
该条件C1到C4中依次判断,任一个条件不满足,则处理下一条边缘线;The conditions C1 to C4 are judged in turn, if any one of the conditions is not satisfied, the next edge line is processed;
将获取的第一个角点添加到角点集合中,对于获取的其余角点,将计算其与角点集合中所有角点的距离Li,i为变量,判断与角点集合中的所有角点是否相似,若Li<r,并与其余角点不相似,将该角点添加到角点集合中;Add the acquired first corner point to the corner point set, and for the rest of the acquired corner points, calculate the distance L i from all the corner points in the corner point set, i is a variable, and judge all the corner points in the corner point set. Whether the corner points are similar, if L i < r and not similar to other corner points, add the corner point to the corner point set;
该交点W对应两条臂,第一条臂为其与C边缘线的终点的连线,第二条臂为其与D边缘线的终点的连线,C边缘线的终点为C边缘线中d1和d2中较大的对应端点,D边缘线的终点为D边缘线中d3和d4中较大的对应端点;同样的方式处理种子边缘线组集合中的其余任两条边缘线,获取所有的角点,根据种子边缘线集合扩展每个角点的两臂,得到最终的角点集合,实现角点提取。The intersection point W corresponds to two arms, the first arm is the line connecting the end point of the C edge line, the second arm is the line connecting the end point of the D edge line, and the end point of the C edge line is the middle line of the C edge line. The larger corresponding endpoint of d1 and d2, the end point of the D edge line is the larger corresponding endpoint of d3 and d4 in the D edge line; the same way to deal with any other two edge lines in the seed edge line group set, get all the The corner points of , expand the two arms of each corner point according to the set of seed edge lines to obtain the final set of corner points to realize corner point extraction.
优选的是,对提取的角点配对的具体方式为:Preferably, the specific method for pairing the extracted corner points is:
C1、对角点集合中的所有角点进行两两配对,若配对的两个角点的坐标不同,则继续判断两个角点之间是否共享一个臂,将一个角点的两臂标记为arm11和arm12,另一个角点的两臂记为arm21和arm22,先判断arm11和arm21是否为两个角点的同一个臂;C1. Pair all the corner points in the corner point set. If the coordinates of the two paired corner points are different, continue to judge whether the two corner points share an arm, and mark the two arms of one corner point as arm11 and arm12, the two arms of the other corner are recorded as arm21 and arm22, first determine whether arm11 and arm21 are the same arm of the two corners;
C2、判断arm11和arm21是同一臂的方式为:若两个角点之间的距离大于arm11和arm21的最小值的四分之一,先计算arm11与两个角点连线的角度差的绝对值x1,arm21与两个角点连线的角度差的绝对值x2,x1和x2的取值范围是[0,180],给定角度相似阈值f,若x1和x2均小于角度相似阈值f,给定角点间距离阈值u和长度比例阈值ratio,若arm11和arm21的长度和大于等于两个角点距离的ratio倍,并大于等于两个角点的距离与u的差值,则判定arm11和arm21是同一臂,角点配对成功;C2. The way of judging that arm11 and arm21 are the same arm is: if the distance between the two corner points is greater than one quarter of the minimum value of arm11 and arm21, first calculate the absolute value of the angle difference between arm11 and the two corner points. Value x1, the absolute value of the angle difference between arm21 and the line connecting the two corner points x2, 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 distance threshold u between the corner points and the length ratio threshold ratio, if the sum of the lengths of arm11 and arm21 is greater than or equal to the ratio times the distance between the two corner points, and is greater than or equal to the difference between the distance between the two corner points and u, then determine arm11 and arm21 are the same arm, and the corners are paired successfully;
否则,采用同样的方法判断两个角点的其余任两个臂是否是同一臂,若均不是则角点配对失败,否则角点配对成功;Otherwise, use the same method to judge whether the other two arms of the two corners are the same arm, if not, the corner pairing fails, otherwise the corner pairing succeeds;
同样的方式对其余的角点两两配对,获取所有配对成功的角点组合,每个角点组合的同一臂为共享臂,另两个臂为打开臂,计算每一个角点组合中两个打开臂与共享臂之间的夹角u1和u2,夹角u1和u2的取值范围是[0,180],将夹角u1或u2小于弯曲度阈值b的角点组合剔除;对剩余的角点组合,判断其两个打开臂是否在共享臂的同一侧,将两个打开臂不在共享臂的同一侧的角点组合剔除,最后根据当前配对的角点组合确定一个四边形;同样的方式处理所有的角点组合,获取所有的四边形。In the same way, pair the remaining corners in pairs to obtain all the successfully paired corner combinations. The same arm of each corner combination is the shared arm, and the other two arms are open arms. Calculate the two corners in each corner combination. Open the included angles u1 and u2 between the arm and the shared arm, the value range of the included angles u1 and u2 is [0, 180], and remove the combination of corners whose included angle u1 or u2 is less than the curvature threshold b; Corner combination, determine whether its two open arms are on the same side of the shared arm, remove the corner combination of the two open arms that are not on the same side of the shared arm, and finally determine a quadrilateral according to the currently paired corner combination; the same way Process all corner combinations to get all quads.
优选的是,根据种子边缘线集合扩展每个角点的两臂的具体方式为:Preferably, the specific manner of extending the two arms of each corner point according to the set of seed edge lines is:
遍历种子边缘线集合的所有边缘线,对于每个角点,计算其到当前种子边Traverse all edge lines in the set of seed edge lines, and for each corner point, calculate it to the current seed edge
缘线的距离,如果该距离小于给定的阈值,则判断该种子边缘线是否可以扩展当前角点的两臂,首先判断该种子边缘线是否可以扩展当前角点的臂1,具体方式为:The distance of the edge line, if the distance is less than the given threshold, it is judged whether the seed edge line can extend the two arms of the current corner point, first determine whether the seed edge line can extend the arm 1 of the current corner point, the specific method is:
C1、计算当前角点到该种子边缘线的起点和终点的距离,记作dist1和C1. Calculate the distance from the current corner to the starting point and ending point of the seed edge line, denoted as dist1 and
dist2,判断当前角点是否在该种子边缘线的两端点之间;dist2, determine whether the current corner point is between the two ends of the seed edge line;
C2、若当前角点在该种子边缘线的两端点之间,将当前角点到该种子边缘C2. If the current corner point is between the two ends of the seed edge line, move the current corner point to the seed edge
线的起点所在的线段记作M,线段M的起点为当前角点,终点为该种子边缘线的起点,当前角点的臂1所在的线段记作N,线段N的起点为当前角点,计算线段M的角度angle1和线段N的角度angle2,判断angle1和angle2的差的绝对值是否小于给定的角度阈值;The line segment where the starting point of the line is located is recorded as M, the starting point of the line segment M is the current corner point, the end point is the starting point of the seed edge line, the line segment where the arm 1 of the current corner point is located is recorded as N, the starting point of the 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 judge whether the absolute value of the difference between angle1 and angle2 is less than the given angle threshold;
C3、若angle1和angle2的差的绝对值小于给定的角度阈值,则计算线M的终点到当前角点的距离rM,计算线段N的长度rN,判断rM与rN的差值是否小于给定的长度差阈值;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 the line M to the current corner point, calculate the length rN of the line segment N, and judge whether the difference between rM and rN is less than the given value The length difference threshold of ;
C4、若rM与rN的差值小于给定的长度差阈值,计算线段N的终点C4. If the difference between rM and rN is less than the given length difference threshold, calculate the end point of the line segment N
到当前种子边缘线的距离,若该距离小于给定的点到线的距离阈值且dist1大于rN,则当前种子边缘线可以扩展当前角点的臂1,当前角点的扩展后的臂1的终点为该种子边缘线的起点,扩展后的臂1的长度为dist1;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, then the current seed edge line can extend the arm 1 of the current corner, and the extended arm 1 of the current corner. The end point is the starting point of the seed edge line, and the length of the expanded arm 1 is dist1;
C5、若C2到C4的任一条件不满足,则表明当前种子边缘线不可以扩展C5. If any of the conditions from C2 to C4 are not satisfied, it means that the current seed edge line cannot be extended
当前角点的臂1,则采用同样的方法判断当前种子边缘线是否可以扩展当前角点的臂2,如果可以扩展,扩展后的臂2的终点为该种子边缘线的起点,扩展后的臂2的长度为dist1,如果不能扩展,直接执行下一步骤;For arm 1 at the current corner point, the same method is used to determine whether the current seed edge line can expand the arm 2 of the current corner point. If it can be expanded, the end point of the expanded arm 2 is the starting point of the seed edge line. The length of 2 is dist1. If it cannot be extended, go to the next step directly;
C6、将C2中的线段M的终点更新为当前种子边缘线的终点,线段N更新为当前角点的臂2所在的线段,线段N的起点为当前角点,dist1更新为dist2,采用同样的方法再次判断当前种子边缘线是否可以扩展当前角点的臂1和臂2,实现当前角点两臂的扩展;C6. Update the end point of the line segment M in C2 to the end point of the current seed edge line, update the line segment N to the line segment where the arm 2 of the current corner point is located, the starting point of the line segment N is the current corner point, dist1 is updated to dist2, using the same The method judges again whether the current seed edge line can extend the arms 1 and 2 of the current corner, and realizes the expansion of the two arms of the current corner;
C7、此时,若不满足C1中的条件,判断dist1 是否小于等于 dist2;C7. At this time, if the conditions in C1 are not met, judge whether dist1 is less than or equal to dist2;
C8、若dist1 小于等于 dist2,将C2中的线段M的起点更新为当前种子边C8. If dist1 is less than or equal to dist2, update the starting point of line segment M in C2 to the current seed edge
缘线的起点,终点更新为当前边缘线的终点,线段N为当前角点的臂1或臂2所在的线段,采用同样的方法判断当前种子边缘线是否可以扩展当前角点的臂1和臂2,实现当前角点两臂的扩展;The starting point of the edge line, the end point is updated to the end point of the current edge line, and the line segment N is the line segment where the 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 the current corner point. Arm 1 and arm 2. Realize the expansion of the two arms at the current corner;
C9、若dist1大于 dist2,将C2中的线段M的起点更新为当前种子边缘线C9. If dist1 is greater than dist2, update the starting point of line segment M in C2 to the current seed edge line
的终点,终点更新为当前边缘线的起点,线段N为当前角点的臂1或臂2所在的线段,dist1更新为dist2,采用同样的方法判断当前种子边缘线是否可以扩展当前角点的臂1和臂2,实现当前角点两臂的扩展。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, and the same method is used to determine whether the current seed edge line can extend the arm of the current corner point. 1 and arm 2, to realize the expansion of the two arms at the current corner.
优选的是,S7、根据获取的四边形和上表面的分割图像确定立方物体的上表面和整体轮廓的具体方式为:Preferably, in S7, the specific manner of determining the upper surface and the overall outline of the cubic object according to the obtained segmented images of the quadrilateral and the upper surface is:
C1、先对获取的四边形进行处理,若进行匹配的四边形的两个臂的终点距离小于给定的距离比例阈值倍,该四边形不符合,处理下一个四边形,获取所有符合条件的四边形,并获取每个四边形的轮廓和外接矩形,根据轮廓坐标点计算其凸包;C1. Process the acquired quadrilateral first. If the distance between the end points of the two arms of the matched quadrilateral is less than the given distance ratio threshold times, the quadrilateral does not meet the requirement, process the next quadrilateral, obtain all the quadrilaterals that meet the conditions, and obtain For the contour and circumscribed rectangle of each quadrilateral, calculate its convex hull according to the contour coordinate points;
C2、根据上表面的分割图像进行轮廓检测,获取所有的轮廓,根据轮廓坐标点计算其凸包,并获取包含每个轮廓的最小的旋转矩形以及包含旋转矩形的外接矩形,计算每个轮廓的面积,判断轮廓的面积是否大于给定的面积阈值;C2. Perform contour detection according to the segmented image of the upper surface, obtain all contours, calculate the convex hull according to the contour coordinate points, obtain the smallest rotated rectangle containing each contour and the circumscribed rectangle containing the rotated rectangle, and calculate the Area, to determine whether the area of the contour is greater than the given area threshold;
C3、若轮廓的面积大于面积阈值,将当前轮廓与符合条件的四边形进行匹配,分别计算进行匹配的四边形的两个角点到当前轮廓的凸包的最小距离h1和h2,判断进行匹配的四边形的两个角点是否在进行匹配的四边形的凸包的外部以及h1和h2是否小于等于给定的距离阈值;C3. If the area of the contour is greater than the area threshold, match the current contour with the qualified quadrilateral, calculate the minimum distances h1 and h2 from the two corner points of the matched quadrilateral to the convex hull of the current contour, and judge the quadrilateral for matching Whether the two corner points of is outside the convex hull of the matching quadrilateral and whether h1 and h2 are less than or equal to the given distance threshold;
C4、若进行匹配的四边形的两个角点在进行匹配的四边形的凸包的外部且h1和h2均小于等于该距离阈值,判断当前轮廓外的旋转矩形的中心点是否在进行匹配的四边形的凸包内部;C4. If the two corner points of the matching quadrilateral are outside the convex hull of the matching quadrilateral and both h1 and h2 are less than or equal to the distance threshold, judge whether the center point of the rotating rectangle outside the current contour is in the matching quadrilateral inside the convex hull;
C5、若当前轮廓外的旋转矩形的中心点位于进行匹配的四边形的凸包内部,计算其到进行匹配的四边形凸包的最小距离的绝对值,满足该值小于等于旋转矩形的长和宽,且中心点位于进行匹配的四边形的任一个臂的下侧的条件,计算进行匹配的四边形的外接矩形与当前轮廓的外接矩形的重叠面积,若该重叠面积大于给定的比例阈值,则当前轮廓与进行匹配的四边形初步匹配成功,进行匹配的四边形记作初步匹配四边形;C5. If the center point of the rotating rectangle outside the current contour is located inside the convex hull of the matching quadrilateral, calculate the absolute value of the minimum distance to the matching quadrilateral convex hull, if the value is less than or equal to the length and width of the rotating rectangle, And the center point is located on the lower side of any arm of the matching quadrilateral, calculate the overlapping area of the bounding rectangle of the matching quadrilateral and the bounding rectangle of the current contour, if the overlapping area is greater than the given ratio threshold, then the current contour The initial matching with the matching quadrilateral is successful, and the matching quadrilateral is recorded as the preliminary matching quadrilateral;
C6、将当前轮廓的旋转矩形的中心点到初步匹配四边形的三个臂的距离进行归一化处理,归一化处理后的值在理论范围内,且h1与h2 的和小于等于给定阈值,将该初步匹配四边形记作有效四边形;C6. Normalize the distance from the center point of the rotating rectangle of the current contour to the three arms of the preliminary matching quadrilateral. The normalized value is within the theoretical range, and the sum of h1 and h2 is less than or equal to the given threshold , denote the preliminary matching quadrilateral as an effective quadrilateral;
C7、判断有效四边形的两个打开臂是否朝下,将两个打开臂朝下的有效四边形记作种子四边形;若获取下一个种子四边形,则计算该种子四边形的两个角点到其轮廓的最小距离之和是否小于上一个种子四边形的两个角点到其轮廓的最小距离之和,若小于则用当前种子四边形替换上一个种子四边形,否则剔除当前种子四边形,继续处理直至获取当前轮廓的最终的种子四边形;C7. Determine whether the two open arms of the effective quadrilateral face down, and record the effective quadrilateral with the two open arms facing down as the seed quadrilateral; if the next seed quadrilateral is obtained, calculate the distance from the two corners of the seed quadrilateral to its outline Whether the sum of the minimum distances is less than the sum of the minimum distances from the two corners of the previous seed quadrilateral to its contour, if it is less than, replace the previous seed quadrilateral with the current seed quadrilateral, otherwise remove the current seed quadrilateral, and continue processing until the current contour is obtained. the final seed quad;
C8、判断当前轮廓的最终的种子四边形是否与有效四边形存在共享角点;C8. Determine whether the final seed quadrilateral of the current contour has a shared corner point with the effective quadrilateral;
C9、若存在共享角点,判断有效四边形的共享臂和打开臂所在线段与种子四边形的共享臂所在线段是否存在重叠,若存在重叠,判断有效四边形的共享臂和打开臂所在线段与种子四边形的打开臂所在线段的重叠数目是否大于等于1,若满足则获取以种子四边形的三条臂为上表面的边,有效四边形的除重叠臂以外的臂为侧垂面的边的立方物体轮廓,获取所有的立方物体轮廓,记作立方物体轮廓集合;C9. If there is a shared corner point, determine whether the line segment of the shared arm and the open arm of the effective quadrilateral overlaps with the line segment of the shared arm of the seed quadrilateral. Whether the overlapping number of the line segment of the open arm of the seed quadrilateral is greater than or equal to 1, if so, obtain a cubic object with the three arms of the seed quadrilateral as the upper surface, and the arms of the effective quadrilateral except the overlapping arms as the sides of the side vertical plane Contour, get all the contours of cubic objects, and record them as the set of contours of cubic objects;
C10、根据立方物体轮廓的每条边的端点获取立方物体轮廓的所有点坐标,立方物体轮廓以种子四边形为上表面;C10. Obtain all point coordinates of the outline of the cubic object according to the endpoints of each side of the outline of the cubic object, and the outline of the cubic object takes the seed quadrangle as the upper surface;
C11、遍历立方物体轮廓集合,计算每个立方物体轮廓中心点的y坐标P.y和其上表面的中心点的y坐标t.y,计算每个立方物体轮廓的面积P.area和其上表面的面积t.area,如果t.y>P.y或t.area>P.area,则剔除该立方物体轮廓,获取最终的立方物体轮廓集合。C11. Traverse the set of cubic object contours, calculate the y-coordinate P.y of the center point of the contour of each cubic object and the y-coordinate t.y of the center point of its upper surface, and calculate the area P.area of the contour of each cubic object and the area t of its upper surface .area, if t.y>P.y or t.area>P.area, then remove the outline of the cube to obtain the final set of outlines of the cube.
优选的是,根据左垂面的分割图像和右垂面的分割图像获取每个上表面四边形对应的左右垂直面,实现立方物体定位的具体方式为:遍历所有立方物体轮廓集合,根据左垂面的分割图像获取左垂直面所有的轮廓及其对应的旋转矩形和外接矩形,判断旋转矩形的中心点的y坐标是否大于等于上表面四边形中心点的y坐标;若满足前一条件,判断上表面四边形对应的立方物体轮廓面积和外接矩形的重叠面积占立方物体轮廓面积的比例是否大于等于给定的面积比例阈值;若大于等于给定的面积比例阈值,寻找满足上述条件的所有左垂面轮廓中面积最大的轮廓即为当前立方物体的左垂直面轮廓;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. Obtain all the contours of the left vertical plane and their corresponding rotating rectangles and circumscribed rectangles, and judge whether the y-coordinate of the center point of the rotating rectangle is greater than or equal to the y-coordinate of the center point of the quadrilateral on the upper surface; Whether the ratio of the contour area of the cube corresponding to the quadrilateral and the overlapping area of the circumscribed rectangle to the contour area of the cube is greater than or equal to the given area ratio threshold; The contour with the largest area is the left vertical contour of the current cubic object;
根据右垂面的分割图像获取右垂直面所有轮廓及其对应的旋转矩形和外接矩形,对右垂面的分割图像的所有轮廓的处理方式与左垂直面的所有轮廓的处理方式一致,以此获取每个立方物体上表面对应的左垂直面和右垂直面,每组上表面、左垂直面和右垂直面构成一个立方物体,实现立方物体检测。Obtain all the contours of the right vertical plane and their corresponding rotated rectangles and circumscribed rectangles according to the segmented image of the right vertical plane. The left vertical plane and the right vertical plane corresponding to the upper surface of each cubic object are obtained, and each group of the upper surface, the left vertical plane and the right vertical plane constitutes a cubic object to realize the detection of the cubic object.
优选的是,C8中判断当前轮廓的最终的种子四边形是否与有效四边形存在共享角点的具体方式为:计算最终的种子四边形的两个角点分别到有效四边形的两个角点的距离,若满足四个距离均大于给定的阈值条件,则表明该种子四边形和有效四边形不存在共享角点,若不满足四个距离均大于给定的阈值条件,则表明该种子四边形和有效四边形存在共享角点。Preferably, in C8, the specific method for judging whether the final seed quadrilateral of the current contour has a shared corner point with the effective quadrilateral is: calculating the distances from the two corner points of the final seed quadrilateral to the two corner points of the effective quadrilateral respectively, if If the four distances are all greater than the given threshold, it means that the seed quadrilateral and the effective quadrilateral do not have shared corners; if the four distances are all greater than the given threshold, it means that the seed quadrilateral and the effective quadrilateral share corner.
本发明的有益效果为:本发明的基于深度图像的立方物体识别方法,在通过分割图像快速区分出立方物体的表面的基础上,对边缘点图进行边缘线检测,将检测到的所有边缘线进行聚类与合并,获取所有共线的边缘线组别,每个组别内边缘线共线,选取其最长边缘线表示每组边缘线,在计算时每组边缘线也只使用其最长边缘线,减少计算量,提高检测的稳定性;再利用聚类合并后的边缘线间的交点提取角点并进行配对,角点配对验证两个角点之间是否存在共享臂,角点的两个打开臂是否在其共享臂的同一侧以及每个角点间的夹角是否大于给定的角度阈值,根据角点配对结果实现四边形检测,然后通过检测上表面的分割图像获取所有的上表面轮廓,并将上表面轮廓与所有检测到的四边形进行匹配,获取立方体上表面和立方体整体轮廓,再结合左垂面和右垂面分割图像获取所有左垂面轮廓和右垂面轮廓,再根据其和立方体整体轮廓确定每个上表面对应的左垂直面和右垂直面,准确实现立方物体的检测。实际应用在体积测量中至少包含上表面和一个垂直面。The beneficial effects of the present invention are as follows: the method for recognizing a cube object based on a depth image of the present invention, on the basis of quickly distinguishing the surface of the cube object by dividing the image, performs edge line detection on the edge point map, and all detected edge lines are detected. Perform clustering and merging to obtain all collinear edge line groups, the edge lines in each group are collinear, select the longest edge line to represent each group of edge lines, and only use its longest edge line in the calculation. Long edge lines can reduce the amount of calculation and improve the stability of detection; then use the intersections between the edge lines after clustering to extract corner points and pair them. The corner point pairing verifies whether there is a shared arm between the two corner points. Whether the two open arms are on the same side of their shared arms and whether the included angle between each corner point is greater than a given angle threshold, quadrilateral detection is realized according to the corner point pairing results, and then all the The upper surface contour is matched with all detected quadrilaterals to obtain the upper surface of the cube and the overall contour of the cube, and then combined with the left and right vertical planes to segment the image to obtain all left and right vertical surface contours, Then, the left vertical plane and the right vertical plane corresponding to each upper surface are determined according to the overall contour of the cube, so as to accurately realize the detection of the cubic object. Practical applications include at least an upper surface and a vertical plane in volume measurements.
本发明的立方物体识别方法应用在包裹、货物、货柜等目标的体积测量中,避免比对传输带装货前和装货后的深度图像,而是直接识别立方物体状目标,获取对应的长宽高计算目标的体积,解决了包裹体积测量局限和耗时的问题,帮助物流行业提高包裹分拣效率,具有重要的实际应用意义。本发明的立方物体识别方法,也可在图像识别领域应用。The cubic object recognition method of the present invention is applied to the volume measurement of parcels, goods, containers and other targets, avoids comparing the depth images of the conveyor belt before and after loading, but directly recognizes the cube-shaped target, and obtains the corresponding length and width. The volume of the high calculation target solves the problem of limited and time-consuming package volume measurement, and helps the logistics industry to improve the efficiency of package sorting, which has important practical application significance. The cubic object recognition method of the present invention can also be applied in the field of image recognition.
具体实施方式Detailed ways
下面对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be described clearly and completely below. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
实施例:一种基于深度图像的立方物体识别方法,包括:S1、获取目标的深度图像,根据深度图像分别获取与其大小相同的X方向和Y方向的梯度图;S2、根据梯度图对其中的像素点进行分类,获取深度图像的边缘点图;S3、根据分类结果、梯度图和边缘点图获取深度图像中目标的上表面、左垂面和右垂面的分割图像;S4、对边缘点图进行边缘线检测,将检测到的所有边缘线进行聚类与合并,获取共线边缘线组集合;S5、根据共线边缘线组集合的每组最长的边缘线提取角点;S6、对提取的角点进行配对,获取四边形;S7、根据获取的四边形和上表面的分割图像确定立方物体的上表面和整体轮廓;S8、根据左垂面的分割图像和右垂面的分割图像获取每个上表面四边形对应的左右垂直面,实现立方物体定位。像素点分类方法适用于任意场景的任意物体,实际应用在立方物体定位时,立方物体在图像中至少包含可见的上表面和一个垂直面目标所在的平面是深度图像中最低的平面或者直接在地面上,便于更加准确地实现立方物体定位。Embodiment: a method for recognizing a cube object based on a depth image, comprising: S1, acquiring a depth image of the target, and respectively obtaining gradient maps in the X direction and the Y direction of the same size according to the depth image; Classify the pixel points to obtain the edge point map of the depth image; S3, obtain the segmented images of the upper surface, left vertical plane and right vertical plane of the target in the depth image according to the classification result, gradient map and edge point map; S4, to the edge point Perform edge line detection on the graph, 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 the collinear edge line set; S6, Pairing the extracted corner points to obtain a quadrilateral; S7, determining the upper surface and overall outline of the cubic object according to the obtained quadrilateral and the segmented image of the upper surface; S8, obtaining according to the segmented image of the left vertical plane and the segmented image of the right vertical plane The left and right vertical planes corresponding to each upper surface quadrilateral realize the positioning of cubic objects. The pixel point classification method is suitable for any object in any scene. In practice, when a cubic object is positioned, the cubic object contains at least a visible upper surface and a vertical plane in the image. The plane where the target is located is the lowest plane in the depth image or directly on the ground. It is convenient to realize the positioning of the cubic object more accurately.
S2中根据梯度图对其中的像素点进行分类的具体方式为:遍历X方向的梯度图中的每个像素点值DX(r,c),Y方向的梯度图中的每个像素点值DY(r,c),其中r=0...m,c=0...n,m代表所在梯度图的行数,n代表所在梯度图的列数;给定正分割阈值p和负分割阈值q,大于等于p的 DY(r,c)对应的像素点位于垂直面,小于等于q的 DY(r,c)对应的像素点位于水平面;对于所有垂直面上的点,小于等于q的 DX(r,c)对应的像素点位于左垂面,大于等于p的DX(r,c)对应的像素点位于右垂面。The specific way of classifying the pixels in S2 according to the gradient map is: traverse each pixel value DX(r, c) in the gradient map in the X direction, and each pixel value DY in the gradient map in the Y direction (r, c), 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 pixels corresponding to DY(r, c) greater than or equal to p are located on the vertical plane, and the pixels corresponding to DY(r, c) less than or equal to q are located on the horizontal plane; for all points on the vertical plane, the pixels less than or equal to q The pixels corresponding to DX(r, c) are located on the left vertical plane, and the pixels corresponding to DX(r, c) greater than or equal to p are located on the right vertical plane.
S2中获取深度图像的边缘点图的具体方式为:计算分类后的垂直面的所有像素点的Y方向的梯度平均值Yp、水平面的所有像素点的Y方向的梯度平均值Yq、左垂面的所有像素点的X方向的梯度平均值Xp以及右垂面的所有像素点的X方向的梯度平均值Xq;根据Yp、Yq、Xp、Xq设定Y方向正阈值、Y方向负阈值、X方向正阈值、X方向负阈值;定义一个与梯度图大小相同的图像,该图像中的像素点的初始值设定为0;遍历X方向的梯度图和Y方向的梯度图的所有像素点,对于每一个像素点,如果其Y方向的梯度值的绝对值大于X方向的梯度值的绝对值,且小于Y方向负阈值或大于等于Y方向正阈值,该像素点为边缘点,将该像素点对应到定义的图像中并将其像素值更新为255,如果其Y方向的梯度值的绝对值小于X方向的梯度值的绝对值,且其X方向的梯度值的绝对值小于等于X方向负阈值或大于等于X方向正阈值,该像素点为边缘点,将该像素点对应到定义的图像中并将其像素值更新为255;得到边缘点图,边缘点图是二值图。The specific method of obtaining the edge point map of the depth image in S2 is: calculating the gradient mean value Yp in the Y direction of all the pixels in the vertical plane after classification, the gradient mean value Yq in the Y direction of all the pixels in the horizontal plane, and the left vertical plane. The gradient average value Xp of all pixels in the X direction and the gradient average value Xq of all pixels of the right vertical plane in the X direction; according to Yp, Yq, Xp, Xq set the Y direction positive threshold, Y direction negative threshold, X Positive threshold in the direction and negative threshold in the X direction; define an image with the same size as the gradient map, and the initial value of the pixels in the image is set to 0; traverse all the pixels of the gradient map in the X direction and the gradient map in the Y direction, For each pixel, if the absolute value of the gradient value in the Y direction is greater than the absolute value of the gradient value in the X direction, and less than the negative threshold value in the Y direction or greater than or equal to the positive threshold value in the Y direction, the pixel point is an edge point, the pixel The point corresponds to the defined image and its pixel value is updated to 255, if the absolute value of the 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 the gradient value in the X direction is less than or equal to the X direction. If the negative threshold is greater than or equal to the positive threshold in the X direction, the pixel is an edge point, and the pixel corresponds to the defined image and its pixel value is updated to 255; the edge point image is obtained, and the edge point image is a binary image.
S3中根据分类结果、梯度图和边缘点图获取深度图像中目标的上表面、左垂面和右垂面的分割图像的具体方式为:根据分类结果获取与梯度图大小相同的水平面、左垂面和右垂面的二值图,定义与梯度图大小相同的上表面的分割图像,设定像素点的初始值为0;从下到上遍历水平面的二值图中第一列的像素点,根据深度图获取每个像素点的可信度值,给定可信度阈值,若该像素点的可信度值小于给定的可信度阈值,则该像素点的状态为未知,处理下一像素点;否则,若对应的像素点值为255,则该像素点的状态为水平,若对应的像素点为0,则该像素点的状态为垂直,若像素点值为0的像素点的数目大于给定的高度阈值,则将其后出现的像素点值为255的像素点对应在上表面的分割图像上并将其像素值更新为255,记录每一次像素点状态发生转变的像素点所在的行数,遍历完第一列所有行的像素点后,将从记录的行数起到第1行的第一列所有像素点对应在上表面的分割图像上的位置的像素值置为0,同样的方式遍历完平行面图像的所有行列,获取初始的上表面的分割图像;对获取的初始的上表面的分割图像进行修补,具体方式为:给定图像片大小阈值t,定义与上表面的分割图像大小相同的上表面修补图像,设定像素点的初始值为0,根据上表面的分割图像更新上表面修补图像的第t列到总列数减去t列的像素点值,遍历上表面的分割图像的所有行和第1到第2*t列,将上表面修补图像的每行的第t列的每个像素点值更新为上表面的分割图像的当前行的第1到第2*t列的像素点值之和,更新上表面修补图像;遍历上表面的分割图像的所有行和第t+1列到总列数减去t列,将上表面修补图像的每个像素点值更新为当前行当前列的前一列的上表面修补图像像素点值加上当前行当前列加上t列的的上表面的分割图像的像素点值再减去当前行当前列减去t列的上表面的分割图像的像素点值,获取最终的上表面修补图像;遍历上表面修补图像的所有像素点,给定像素值总和阈值,如果当前像素点的像素值大于给定的像素值总和阈值,则将其对应在上表面的分割图像上的像素值更新为255,否则更新为0,更新上表面的分割图像;The specific method of obtaining the segmented images of the upper surface, left vertical plane and right vertical plane of the target in the depth image according to the classification result, the gradient map and the edge point map in S3 is as follows: according to the classification result, the horizontal plane, left vertical plane and left vertical plane with the same size as the gradient map are obtained according to the classification result. The binary image of the surface and the right vertical plane, define the segmented image of the upper surface with the same size as the gradient image, and set the initial value of the pixel point to 0; traverse the pixel points in the first column of the binary image of the horizontal plane from bottom to top , obtain the credibility value of each pixel point according to the depth map, and give the credibility threshold value. If the credibility value of the pixel point is less than the given credibility threshold value, the state of the pixel point is unknown, and processing 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 pixel value is 0, the state of the pixel is vertical. The number of points is greater than the given height threshold, then the pixels with the pixel value of 255 that appear later correspond to the segmented image on the upper surface and update the pixel value to 255, and record the state of each pixel point. The number of rows where the pixel points are located. After traversing the pixels of all rows in the first column, the pixel values from the number of recorded rows to the first column of the first row correspond to the position of the segmented image on the upper surface. Set to 0, traverse all the rows and columns of the parallel plane image in the same way, and obtain the initial segmented image of the upper surface; repair the obtained initial segmented image of the upper surface. The specific method is: given the image slice size threshold t, Define the upper surface patch image with the same size as the upper surface segmented image, set the initial value of the pixel point to 0, and update the upper surface patch image from the tth column to the total number of columns minus the pixels in column t according to the segmented image of the upper surface. Point value, traverse all rows and columns 1 to 2*t of the segmented image on the upper surface, update each pixel value of the t-th column of each row of the patched image on the upper surface to the current row of the segmented image on the upper surface The sum of the pixel values of the 1st to 2*t columns of the 1st to 2nd*t columns, update the upper surface patch image; traverse all the rows and t+1th columns of the upper surface segmented image to the total number of columns minus t columns, and patch the upper surface Each pixel value of the image is updated to the pixel value of the patch image on the upper surface of the previous column of the current row and the current column plus the pixel value of the segmented image on the upper surface of the current row and current column plus the t column minus the current row. Subtract the pixel value of the segmented image on the upper surface of column t from the current column to obtain the final upper surface patch image; traverse all pixels of the upper surface patch image, and give the sum threshold of pixel values, if the pixel value of the current pixel is greater than Given the threshold of the sum of pixel values, update the pixel value corresponding to the segmented image on the upper surface to 255, otherwise update it to 0, and update the segmented image on the upper surface;
将边缘点图中的边缘点分别一一对应在更新后的上表面的分割图像、左垂面的二值图和右垂面的二值图中,将更新后的上表面的分割图像中水平状态的非边缘点的像素点值更新为0,将左垂面的二值图中非边缘点的像素值为255的像素点值更新为0,将右垂面的二值图中非边缘点的像素值为255的像素点值更新为0,获取最终的上表面的分割图像、左垂面的二值图和右垂面的二值图,将左垂面的二值图和右垂面的二值图分别记作左垂面的分割图像和右垂面的分割图像。The edge points in the edge point map are respectively corresponded one-to-one in the updated upper surface segmented image, the left vertical surface binary image and the right vertical surface binary image, and the updated segmented image of the upper surface is horizontally divided. The pixel value of the non-edge point of the state is updated to 0, the pixel value of the non-edge point in the left vertical plane is updated to 0, the pixel value of the non-edge point in the left vertical plane is 255, and the non-edge point in the right vertical plane is updated. The pixel value of 255 is updated to 0, and the final segmented image of the upper surface, the binary image of the left vertical plane and the binary image of the right vertical plane are obtained, and the binary image of the left vertical plane and the right vertical plane are obtained. The binary images of are denoted as the segmented image of the left vertical plane and the segmented image of the right vertical plane, respectively.
在计算过程中,由于噪声干扰可能出现上表面上的个别点被误判为垂直面的点,导致上表面点不连续,为提高算法稳定性,对上表面的分割图像进行修补。In the calculation process, due to noise interference, individual points on the upper surface may be misjudged as points on the vertical plane, resulting in discontinuous points on the upper surface. In order to improve the stability of the algorithm, the segmented image of the upper surface is repaired.
记录每一次像素点状态发生转变的像素点所在的行数,在S1中获取目标的深度图像,目标在深度图像中完全能够看到,从下向上遍历每一列像素点,如果先后出现立方物体的垂直面和水平面,则之后的像素点类别一定会再发生改变,将最后一次记录的像素点状态发生改变的位置对应的行数到第一行的当前列的所有像素点对应在上表面的分割图像上的像素值置为0(记录行数到第一行的点值有可能是0也有可能是255,统一置为0);否则很有可能当前立方物体的上表面没有完全出现在画面中,剔除这种上表面的点,将其对应在上表面的分割图像上的像素值置为0。Record the row number of the pixel point where the state of each pixel point changes, and obtain the depth image of the target in S1. The target can be fully seen in the depth image, and traverse each column of pixel points from the bottom to the top. If the cubic object appears successively The vertical plane and the horizontal plane, then the category of the subsequent pixel points will definitely change again, the last recorded pixel point state changes the number of rows corresponding to the position of the current column of the first row corresponds to the segmentation on the upper surface The pixel value on the image is set to 0 (the point value from the record line number to the first line may be 0 or 255, and set to 0 uniformly); otherwise, it is very likely that the upper surface of the current cube object does not completely appear in the picture. , culling such points on the upper surface, and setting the pixel value corresponding to the segmented image on the upper surface to 0.
S4中对边缘点图进行边缘线检测,将检测到的所有边缘线进行聚类与合并,获取共线边缘线组集合的具体方式为:对边缘点图进行边缘线检测,获取所有边缘线并按照长到短排序成边缘线集合,定义一个空的共线边缘线组集合,共线边缘线组集合包含多组边缘线,每组内的边缘线是共线的,两组间边缘线是不共线的,首先将最长的边缘线加入到共线边缘线组集合的一组中,对于边缘线集合中的每一条A边缘线,判断其与共线边缘线组集合的每组最长的B边缘线是否共线,判断条件依次如下:C1、计算A边缘线与B边缘线的角度差,判断该角度差是否小于等于给定的角度差阈值e,该角度差大于e,A边缘线和B边缘线肯定不共线,因为共线的两条边缘线应该近似平行,角度差比较小;C2、若该角度差小于等于e计算B边缘线的起点到A边缘线的起点和终点的距离T1和T2,B边缘线的终点到A边缘线的起点和终点的T3和T4,给定点间距离阈值G,距离T1、T2、T3和T4中的最小距离是否小于等于点间距离阈值G,此部分是为了检测A边缘线和B边缘线的两个端点间的最小距离是否小于给定的点间距离阈值G,如果最小距离大于给定的点间距离阈值,说明这两条边缘线离得比较远,min(min(T1,T2),min(T3,T4))>G,则A和B边缘线肯定不共线;C3、若min(min(T1,T2),min(T3,T4))≤G,计算A边缘线的长度L和B边缘线的长度H,判断距离T1、T2、T3和T4中的最大距离是否小于G+H+L,max(max(T1,T2),max(T3,T4))≥(G+H+L),A和B边缘线不共线;C4、若max(max(T1,T2),max(T3,T4))<(G+H+L),计算B边缘线的起点和终点到A边缘线的距离S1和S2,A边缘线的起点和终点到B边缘线的距离S3和S4,给定距离阈值J,若T1和T2的最大距离小于L+G,判断S1是否小于等于J;若距离T3和T4的最大距离小于L+G,判断S2是否小于等于J;若距离T1和T3的最大距离小于L+G,判断S3是否小于等于J;若距离T2和T4的最大距离小于L+G,判断S4是否小于等于J;若任意最大距离均大于等于L+G则直接执行下一步骤;C5、满足C4中的条件,则A边缘线和B边缘线共线,将A边缘线加入到共线边缘线组集合的该组中,更新该组的边缘线;在上述C1到C6的依次判断过程中,任一个条件不满足,直接处理共线边缘线组集合中的下一组的最长边缘线,直至处理完共线边缘线组集合的所有组,每组边缘线用其最长边缘线表示,如果A边缘线与共线边缘线组集合的所有组的最长边缘线均不共线,则直接将A边缘线加入到共线边缘线组集合的新组中,更新共线边缘线组集合的组数;A边缘线和B边缘线共线后,判断A边缘线和B边缘线是否满足合并条件,若T1≤H、T2≤H、T3≤H且T4≤H,则A边缘线与B边缘线不满足合并条件,否则,将A边缘线和B边缘线合并,更新B边缘线的起点和终点,更新共线边缘线组集合;与处理A边缘线相同的方式处理边缘线集合中的下一条边缘线,不断更新共线边缘线组集合,共线边缘线组集合中的边缘线按照长短排序,获取最终的共线边缘线组集合。In S4, edge line detection is performed on the edge point map, and all detected edge lines are clustered and merged to obtain a set of collinear edge line groups. The specific method is: perform edge line detection on the edge point map, obtain all edge lines and Sort the edge line sets from longest to shortest, and define an empty collinear edge line group set. The collinear edge line group set contains multiple sets of edge lines. The edge lines in each group are collinear, and the edge lines between the two groups are If it is not collinear, first add the longest edge line to a group of collinear edge line group sets, and for each A edge line in the edge line set, judge that it is the longest with each group of the collinear edge line group set. The judgment conditions are as follows: C1. Calculate the angle difference between the A edge line and the B edge line, and judge whether the angle difference is less than or equal to the given angle difference threshold e, the angle difference is greater than e, and the A edge The line and the B edge line must not be collinear, because the two collinear edge lines should be approximately parallel, and the angle difference is relatively small; C2. If the angle difference is less than or equal to e, calculate the starting point of the B edge line to the starting point and end point of the A edge line The distances T1 and T2, the end point of B edge line to the start point and end point of A edge line T3 and T4, given the distance threshold G between points, whether the minimum distance among the distances T1, T2, T3 and T4 is less than or equal to the distance threshold between points G, this part is to detect whether the minimum distance between the two endpoints of the A edge line and the B edge line is less than the given distance threshold G between points, if the minimum distance is greater than the given distance threshold between points, it means that the two edges If the lines are far apart, min(min(T1, T2), min(T3, T4))>G, then the edge lines of A and B are definitely not collinear; C3, if min(min(T1, T2), min( T3, T4)) ≤ G, calculate the length L of the edge line of A and the length H of the edge line of B, and judge whether the maximum distance among the distances T1, T2, T3 and T4 is less than G+H+L, max(max(T1, T2), max(T3, T4)) ≥ (G+H+L), A and B edge lines are not collinear; 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 the B edge line to the A edge line, and the distances S3 and S4 from the start and end points of the A edge line to the B edge line, given the distance threshold J, if T1 and If the maximum distance of T2 is less than L+G, judge whether S1 is less than or equal to J; if the maximum distance between T3 and T4 is less than L+G, judge whether S2 is less than or equal to J; if the maximum distance between T1 and T3 is less than L+G, judge Whether S3 is less than or equal to J; if the maximum distance between T2 and T4 is less than L+G, judge 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, meet the conditions in C4 , then the A edge line and the B edge line are collinear, the A edge line is added to the group of the collinear edge line group set, and the edge line of the group is updated; in the sequential judgment process from C1 to C6, any condition Not satisfied, directly process the set of collinear edge line groups The longest edge line of the next group in the set, until all the groups of the collinear edge line group set are processed, each set of edge lines is represented by its longest edge line, if the A edge line is the same as the collinear edge line set of all groups of the set of edge lines. If the longest edge lines are not collinear, then the A edge line is directly added to the new group of the collinear edge line group set, and the group number of the collinear edge line group set is updated; after the A edge line and the B edge line are collinear, Determine whether the A edge line and the B edge line meet the merging conditions. If T1≤H, T2≤H, T3≤H, and T4≤H, then the A edge line and the B edge line do not meet the merging condition, otherwise, the A edge line and the B edge line do not meet the merge condition. Merge B edge lines, update the start and end points of B edge lines, update the set of collinear edge line groups; process the next edge line in the edge line set in the same way as processing A edge lines, and continuously update the set of collinear edge lines, The edge lines in the collinear edge line group set are sorted according to their length, and the final collinear edge line group set is obtained.
此处进行边缘线的共线聚类与合并主要是因为在边缘线检测过程中,往往会因为噪声干扰导致原本连续的边缘线断开,原本只有一条边缘线在检测时可能检测到多条近似平行距离很近但长短不一的多条边缘线,会降低算法的稳定性和精度,进行共线聚类与合并主要是为了将有可能属于同一条线的多条线段划分为同一组,并进行合并,将断开的多条共线边缘线进行合并,获取每组的最长边缘线,用最长边缘线表示该组的所有边缘线,一方面减少了计算量,另一方面提高算法的稳定性。The collinear clustering and merging of edge lines here is mainly because in the process of edge line detection, the original continuous edge lines are often disconnected due to noise interference. Originally, only one edge line may detect multiple approximations during detection. Multiple edge lines with very close parallel distances but different lengths will reduce the stability and accuracy of the algorithm. The main purpose of collinear clustering and merging is to divide multiple line segments that may belong to the same line into the same group. Merge, 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 improves the algorithm on the other hand. stability.
将A边缘线和B边缘线合并,更新B边缘线的起点和终点的方式为:B边缘线为其所在组别的最长边缘线,若A边缘线和B边缘线共线且满足合并条件,则根据A边缘线更新B边缘线的起点和终点,,如果边缘线的两端点x坐标不同,定义边缘线的左侧端点为起点,右侧端点为终点,如果两端点x坐标相同,则定义上面的端点为起点,下面的端点为终点。更新B边缘线的终点的判断方式为:C1、若T1 >H且 T2 > H,在此基础上,T3 > T4,则将B边缘线终点更新为A边缘线的起点,不满足T3 > T4的条件,将B边缘线终点更新为A边缘线的终点;C2、不满足C1中的条件T1 >H且 T2 > H,若T1 > H但T2 <=H,则将B边缘线终点更新为A边缘线的起点;C3、不满足C1和C2中的条件,如果T2 >H但T1<= H,则将B边缘线终点更新为A边缘线的终点。更新B边缘线的起点的判断方式为:C1、若T3>H且T4 > H,在此基础上,T1 > T2,则将B边缘线起点更新为A边缘线的起点,若不满足T1 > T2的条件,将B边缘线起点更新为A边缘线的终点;C2、不满足C1中的条件T3>H且T4 > H,若T3>H但T4 <=H,则将B边缘线起点更新为A边缘线的起点;C3、不满足该C1和C2中的条件,若T4 > H但T3<=H,则将B边缘线起点更新为A边缘线的终点。Merge the A edge line and the B edge line, and update the start and end points of the B edge line as follows: the B edge line is the longest edge line of the group in which it belongs. If the A edge line and the B edge line are collinear and meet the merging conditions , then update the start and end points of the B edge line according to the A edge line. If the x coordinates of the two ends 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 ends are the same, then Define the upper end point as the start point and the lower end point as the end point. The judgment method for updating the end point of the B edge line is: C1. If T1 > H and T2 > H, on this basis, T3 > T4, update the end point of the B edge line to the starting point of the A edge line, which does not satisfy T3 > T4 If T1 > H and T2 > H in C1, if T1 > H but T2 <= H, update the end point of B edge line to The starting point of the A edge line; C3, does not meet the conditions in C1 and C2, if T2 > H but T1 <= H, then update the B edge line end point to the A edge line end point. The judgment method for updating the starting point of the B edge line is: C1. If T3 > H and T4 > H, on this basis, T1 > T2, then update the starting point of the B edge line to the starting point of the A edge line. If it does not satisfy T1 > For the condition of T2, update the starting point of the B edge line to the end point of the A edge line; C2, do not meet the conditions in C1 T3>H and T4>H, if T3>H but T4 <=H, then update the starting point of the B edge line is the starting point of the edge line of A; C3, does not meet the conditions in C1 and C2, if T4 > H but T3 <= H, then update the starting point of the edge line of B to the end point of the edge line of A.
S5中根据共线边缘线组集合的每组最长的边缘线提取角点的具体方式为:C1、获取共线边缘线组集合的每组的最长边缘线,记作种子边缘线集合,将种子边缘线集合的所有边缘线按从长到短排序,遍历种子边缘线集合的所有边缘线,从其中最长的C边缘线开始计算其与其余任一条D边缘线的夹角a,a的范围是0到180度,给定弯曲度阈值b,判断min(a,180-a)是否大于b;C2、若min(a,180-a)>b,计算C边缘线与D边缘线的交点W(Wx,Wy),判断Wx或Wy是否未超出图像范围;若Wx或Wy超出图像范围,开始处理下一条边缘线;C3、若Wx或Wy未超出图像范围,判断交点W是否是角点,判断交点W是角点的条件为:先计算C边缘线的两个端点到交点W的距离d1和d2,定义最小距离min_d1,如果交点W在C边缘线的两个端点之间,则min_d1=0,否则min_d1=min(d1,d2), 若最小距离min_d1不为0或min(d1,d2)小于给定的臂长阈值Z1,再计算D边缘线的两个端点到交点W的距离d3和d4,定义最小距离min_d2,如果交点W在D边缘线的两个端点之间,则min_d2=0,否则min_d2=min(d3,d4),若最小距离min_d2不为0或 min(d3,d4)小于给定的臂长阈值Z2,判断min(d1,d2)和min(d3,d4)是否小于给定的交点半径阈值r;C4、若满足C3的条件,给定四边形臂间差距阈值v,判断max(min(d1,d2),min(d3,d4))是否小于等于v,若不满足处理下一条边缘线,若满足则交点W是四边形的角点;该条件C1到C4中依次判断,任一个条件不满足,则处理下一条边缘线;将获取的第一个角点添加到角点集合中,对于获取的其余角点,将计算其与角点集合中所有角点的距离Li,i为变量,判断与角点集合中的所有角点是否相似,若Li<r,并与其余角点不相似,将该角点添加到角点集合中;该交点W对应两条臂,第一条臂为其与C边缘线的终点的连线,第二条臂为其与D边缘线的终点的连线,C边缘线的终点为C边缘线中d1和d2中较大的对应端点,D边缘线的终点为D边缘线中d3和d4中较大的对应端点;同样的方式处理种子边缘线组集合中的其余任两条边缘线,获取所有的角点,根据种子边缘线集合扩展每个角点的两臂,得到最终的角点集合,实现角点提取。In S5, the specific method of extracting corner points according to the longest edge line of each set of collinear edge line groups is: C1. Obtain the longest edge line of each group of the collinear edge line set, and denote 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, a between it and any other D edge lines The range is 0 to 180 degrees, given the curvature threshold b, determine whether min(a, 180-a) is greater than b; C2, if min(a, 180-a)>b, calculate the C edge line and the D edge line If Wx or Wy does not exceed the image range, start processing the next edge line; C3. If Wx or Wy does not exceed the image range, judge whether the intersection point W is Corner point, the condition for judging that the intersection point 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 point W, and define the minimum distance min_d1, if the intersection point 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 two endpoints of the D edge line to the intersection point W The distances d3 and d4, 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, judge whether min(d1, d2) and min(d3, d4) are less than the given intersection radius threshold r; C4, if the conditions of C3 are met, the given quadrilateral arm Gap threshold v, judge whether max(min(d1, d2), min(d3, d4)) is less than or equal to v, if it does not satisfy the next edge line, if it is satisfied, the intersection point W is the corner of the quadrilateral; the condition C1 to Judging in turn in C4, if any of the conditions is not satisfied, the next edge line is processed; the first corner point obtained is added to the corner point set, and for the remaining corner points obtained, it and all corners in the corner point set will be calculated. The distance L i of the point, i is a variable, judge whether it is similar to all the corner points in the corner point set, if Li < r, and it is not similar to the other 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, and the end point of the C edge line is d1 and d1 in the C edge line. The larger corresponding endpoint in d2, the end point of the D edge line is the larger corresponding endpoint in d3 and d4 in the D edge line; the same way to deal with any other two edge lines in the seed edge line group set, get all the corners point, expand the two arms of each corner point according to the set of seed edge lines, and obtain the final set of corner points to realize corner point extraction.
判断两个角点是否相似的具体方式为:分别计算一个角点的每一个打开臂的角度与另一个角点的每一个打开臂的角度的差值的绝对值a11、a12、a21、a22,角度的差值的绝对值的取值范围为[0,180],选取min(a11,a12),min(a21,a22),给定角度相似阈值f,若max(min(a11,a12),min(a21,a22))<f,则两个角点相似。The specific way of judging whether two corner points are similar is: respectively calculating the absolute values a11, a12, a21, 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, The value range of the absolute value of the angle difference is [0, 180], select min (a11, a12), min (a21, a22), given the angle similarity threshold f, if max (min (a11, a12), min(a21, a22)) < f, then the two corners are similar.
两个角点相似表示两个角点各自对应的打开臂近似平行,举例说明:若两个角点分别包含一条横向打开臂和一条竖向打开臂,则两个角点的横向打开臂是近似平行,那角度差很小,两个竖向打开臂近似平行,角度差也很小,故min(a11,a12)和min(a21,a22)的最小值也应该小于给定的相似角度阈值,否则两个角点不相似。The similarity of two corner points means that the corresponding opening arms of the two corner points are approximately parallel. For example: if the two corner points respectively include a horizontal opening arm and a vertical opening arm, the horizontal opening arms of the two corner points are approximately parallel. parallel, the angle difference is very small, the two vertical open arms are approximately parallel, and the angle difference is also small, so the minimum value of min(a11, a12) and min(a21, a22) should also be smaller than the given similar angle threshold, Otherwise the two corners are not similar.
根据种子边缘线集合扩展每个角点的两臂的具体方式为:遍历种子边缘线集合的所有边缘线,对于每个角点,计算其到当前种子边缘线的距离,如果该距离小于给定的阈值,则判断该种子边缘线是否可以扩展当前角点的两臂,首先判断该种子边缘线是否可以扩展当前角点的臂1,具体方式为:The specific method of extending the two arms of each corner point according to the set of seed edge lines is: traverse all edge lines of the set of seed edge lines, and for each corner point, calculate the distance from the current seed edge line, if the distance is less than the given edge , then judge whether the seed edge line can extend the two arms of the current corner. First, judge whether the seed edge line can extend the arm 1 of the current corner. The specific method is as follows:
C1、计算当前角点到该种子边缘线的起点和终点的距离,记作dist1和C1. Calculate the distance from the current corner to the starting point and ending point of the seed edge line, denoted as dist1 and
dist2,判断当前角点是否在该种子边缘线的两端点之间;dist2, determine whether the current corner point is between the two ends of the seed edge line;
C2、若当前角点在该种子边缘线的两端点之间,将当前角点到该种子边缘C2. If the current corner point is between the two ends of the seed edge line, move the current corner point to the seed edge
线的起点所在的线段记作M,线段M的起点为当前角点,终点为该种子边缘线的起点,当前角点的臂1所在的线段记作N,线段N的起点为当前角点,计算线段M的角度angle1和线段N的角度angle2,判断angle1和angle2的差的绝对值是否小于给定的角度阈值;The line segment where the starting point of the line is located is recorded as M, the starting point of the line segment M is the current corner point, the end point is the starting point of the seed edge line, the line segment where the arm 1 of the current corner point is located is recorded as N, the starting point of the 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 judge whether the absolute value of the difference between angle1 and angle2 is less than the given angle threshold;
C3、若angle1和angle2的差的绝对值小于给定的角度阈值,则计算线M的终点到当前角点的距离rM,计算线段N的长度rN,判断rM与rN的差值是否小于给定的长度差阈值;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 the line M to the current corner point, calculate the length rN of the line segment N, and judge whether the difference between rM and rN is less than the given value The length difference threshold of ;
C4、若rM与rN的差值小于给定的长度差阈值,计算线段N的终点C4. If the difference between rM and rN is less than the given length difference threshold, calculate the end point of the line segment N
到当前种子边缘线的距离,若该距离小于给定的点到线的距离阈值且dist1大于rN,则当前种子边缘线可以扩展当前角点的臂1,当前角点的扩展后的臂1的终点为该种子边缘线的起点,扩展后的臂1的长度为dist1;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, then the current seed edge line can extend the arm 1 of the current corner, and the extended arm 1 of the current corner. The end point is the starting point of the seed edge line, and the length of the expanded arm 1 is dist1;
C5、若C2到C4的任一条件不满足,则表明当前种子边缘线不可以扩展C5. If any of the conditions from C2 to C4 are not satisfied, it means that the current seed edge line cannot be extended
当前角点的臂1,则采用同样的方法判断当前种子边缘线是否可以扩展当前角点的臂2,如果可以扩展,扩展后的臂2的终点为该种子边缘线的起点,扩展后的臂2的长度为dist1,如果不能扩展,直接执行下一步骤;For arm 1 at the current corner point, the same method is used to determine whether the current seed edge line can expand the arm 2 of the current corner point. If it can be expanded, the end point of the expanded arm 2 is the starting point of the seed edge line. The length of 2 is dist1. If it cannot be extended, go to the next step directly;
C6、将C2中的线段M的终点更新为当前种子边缘线的终点,线段N更新为当前角点的臂2所在的线段,线段N的起点为当前角点,dist1更新为dist2,采用同样的方法再次判断当前种子边缘线是否可以扩展当前角点的臂1和臂2,实现当前角点两臂的扩展;C6. Update the end point of the line segment M in C2 to the end point of the current seed edge line, update the line segment N to the line segment where the arm 2 of the current corner point is located, the starting point of the line segment N is the current corner point, dist1 is updated to dist2, using the same The method judges again whether the current seed edge line can extend the arms 1 and 2 of the current corner, and realizes the expansion of the two arms of the current corner;
C7、此时,若不满足C1中的条件,判断dist1 是否小于等于 dist2;C7. At this time, if the conditions in C1 are not met, judge whether dist1 is less than or equal to dist2;
C8、若dist1 小于等于 dist2,将C2中的线段M的起点更新为当前种子边C8. If dist1 is less than or equal to dist2, update the starting point of line segment M in C2 to the current seed edge
缘线的起点,终点更新为当前边缘线的终点,线段N为当前角点的臂1或臂2所在的线段,采用同样的方法判断当前种子边缘线是否可以扩展当前角点的臂1和臂2,实现当前角点两臂的扩展;The starting point of the edge line, the end point is updated to the end point of the current edge line, and the line segment N is the line segment where the 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 the current corner point. Arm 1 and arm 2. Realize the expansion of the two arms at the current corner;
C9、若dist1大于 dist2,将C2中的线段M的起点更新为当前种子边缘线C9. If dist1 is greater than dist2, update the starting point of line segment M in C2 to the current seed edge line
的终点,终点更新为当前边缘线的起点,线段N为当前角点的臂1或臂2所在的线段,dist1更新为dist2,采用同样的方法判断当前种子边缘线是否可以扩展当前角点的臂1和臂2,实现当前角点两臂的扩展。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, and the same method is used to determine whether the current seed edge line can extend the arm of the current corner point. 1 and arm 2, to realize the expansion of the two arms at the current corner.
S6中对提取的角点配对的具体方式为:C1、对角点集合中的所有角点进行两两配对,若配对的两个角点的坐标不同,则继续判断两个角点之间是否共享一个臂,将一个角点的两臂标记为arm11和arm12,另一个角点的两臂记为arm21和arm22,先判断arm11和arm21是否为两个角点的同一个臂;C2、判断arm11和arm21是同一臂的方式为:若两个角点之间的距离小于arm11和arm21的最小值的四分之一,则arm11和arm21不是同一臂;若两个角点之间的距离大于arm11和arm21的最小值的四分之一,先计算arm11与两个角点连线的角度差的绝对值x1,arm21与两个角点连线的角度差的绝对值x2,x1和x2的取值范围是[0,180],给定角度相似阈值f,若x1和x2均小于角度相似阈值f,给定角点间距离阈值u和长度比例阈值ratio,若arm11和arm21的长度和大于等于两个角点距离的ratio倍,并大于等于两个角点的距离与u的差值,则判定arm11和arm21是同一臂,角点配对成功;否则,采用同样的方法判断两个角点的其余任两个臂是否是同一臂,若均不是则角点配对失败,否则角点配对成功;同样的方式对其余的角点两两配对,获取所有配对成功的角点组合,每个角点组合的同一臂为共享臂,另两个臂为打开臂,计算每一个角点组合中两个打开臂与共享臂之间的夹角u1和u2,夹角u1和u2的取值范围是[0,180],将夹角u1或u2小于弯曲度阈值b的角点组合剔除;对剩余的角点组合,判断其两个打开臂是否在共享臂的同一侧,计算该角点组合的共享臂的中心点,以中心点为起点,计算共享臂的单位法向量,计算第一个角点的打开臂的终点与中心点的连线所在的向量v1和第二个角点的打开臂的终点与中心点的连线所在的向量v2,如果向量v1和v2与共享臂的单位法向量的内积一正一负,则两个打开臂不在共享臂的同一侧,将两个打开臂不在共享臂的同一侧的角点组合剔除,最后根据当前配对的角点组合确定一个四边形;同样的方式处理所有的角点组合,获取所有的四边形。The specific method of pairing the extracted corner points in S6 is as follows: C1. All corner points in the corner point set are paired in pairs. If the coordinates of the two paired corner points are different, continue to judge whether the two corner points are between them. Share one arm, mark the two arms of one corner as arm11 and arm12, and the two arms of the other corner as arm21 and arm22, first judge whether arm11 and arm21 are the same arm of the two corners; C2, judge arm11 The way that arm21 and arm21 are the same arm is: if the distance between the two corner points is less than a quarter of the minimum value of arm11 and arm21, then arm11 and arm21 are not the same arm; if the distance between the two corner points is greater than arm11 And one quarter of the minimum value of arm21, first calculate the absolute value x1 of the angle difference between arm11 and the line connecting the two corner points, the absolute value x2 of the angle difference between arm21 and the line connecting the two corner points, and take the values of x1 and x2 The value range is [0, 180], given the angular similarity threshold f, if both x1 and x2 are less than the angular similarity threshold f, given the distance threshold u between corners and the length ratio threshold ratio, if the sum of the lengths of arm11 and arm21 is greater than or equal to If the ratio of the distance between the two corner points is greater than or equal to the difference between the distance between the two corner points and u, then it is determined that arm11 and arm21 are the same arm, and the corner points are paired successfully; otherwise, the same method is used to determine the difference between the two corner points. Whether the other two arms are the same arm, if they are not, the corner point pairing fails, otherwise the corner point pairing is successful; pair the remaining corner points in the same way to obtain all the corner point combinations that are paired successfully, each corner point The same arm of the combination is the shared arm, and the other two arms are the open arms. Calculate the included angles u1 and u2 between the two open arms and the shared arm in each corner combination. The value range of the included angles u1 and u2 is [ 0, 180], remove the corner combination whose included angle u1 or u2 is less than the curvature threshold b; for the remaining corner combination, determine whether the two open arms are on the same side of the shared arm, and calculate the sharing of the corner combination. The center point of the arm, taking 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 open arm of the second corner point. The vector v2 where the line connecting the end point and the center point is located. If the inner product of the vectors v1 and v2 and the unit normal vector of the shared arm is positive and negative, the two open arms are not on the same side of the shared arm, and the two open arms are not on the same side of the shared arm. The corner combinations on the same side of the shared arm are eliminated, and finally a quadrilateral is determined according to the currently paired corner combination; all corner combinations are processed in the same way to obtain all quadrilaterals.
S7中根据获取的四边形和上表面的分割图像确定立方物体的上表面和整体轮廓,再根据左垂面的分割图像和右垂直分割图像获取每个上表面四边形对应的左右垂直面,实现立方物体定位。确定立方物体的上表面和整体轮廓具体方式为:C 1、先对获取的四边形进行处理,若进行匹配的四边形的两个臂的终点距离小于其两个角点距离的0.8倍,该四边形不符合,处理下一个四边形,获取所有符合条件的四边形,并获取每个四边形的轮廓和外接矩形,根据轮廓坐标点计算其凸包;C2、根据上表面的分割图像进行轮廓检测,获取所有的轮廓,根据轮廓坐标点计算其凸包,并获取包含每个轮廓的最小的旋转矩形以及包含旋转矩形的外接矩形,计算每个轮廓的面积,判断轮廓的面积是否大于给定的面积阈值,若轮廓的面积小于给定的面积阈值,则处理下一个轮廓;C3、若轮廓的面积大于给定的面积阈值,将当前轮廓与符合条件的四边形进行匹配,分别计算进行匹配的四边形的两个角点到当前轮廓的凸包的最小距离h1和h2,判断进行匹配的四边形的两个角点是否在进行匹配的四边形的凸包的外部以及h1和h2是否小于等于给定的距离阈值,若h1和h2中的任一个大于给定的距离阈值,则表明存在角点在该轮廓的内侧并在靠近其中心点位置处,进行下一个四边形匹配;C4、若进行匹配的四边形的两个角点在进行匹配的四边形的凸包的外部且h1和h2均小于等于该距离阈值,正在进行匹配的四边形的两个角点位于当前轮廓的外侧,判断当前轮廓外的旋转矩形的中心点是否在进行匹配的四边形的凸包内部,如果不在内部则进行下一个四边形匹配;C5、若当前轮廓外的旋转矩形的中心点位于进行匹配的四边形的凸包内部,计算其到进行匹配的四边形轮廓的最小距离的绝对值,满足该值小于等于旋转矩形的长和宽,且中心点位于进行匹配的四边形的任一个臂的下侧的条件,计算进行匹配的四边形的外接矩形与当前轮廓的外接矩形的重叠面积,若该重叠面积大于给定的比例阈值,则当前轮廓与进行匹配的四边形初步匹配成功,进行匹配的四边形记作初步匹配四边形;C6、将当前轮廓的旋转矩形的中心点到初步匹配四边形的三个臂的距离进行归一化处理,归一化处理后的值在理论范围内,且h1与h2 的和小于等于给定阈值,将该初步匹配四边形记作有效四边形;C7、判断有效四边形的两个打开臂是否朝下,将两个打开臂朝下的有效四边形记作种子四边形,判断的方式:分别以有效四边形的两个角点为起点,水平向右为X轴,在X轴上的线段角度为0度,按照顺时针转动线段角度不断增大,角度的取值范围为[0,360],利用该种定义规则计算两个打开臂的角度,若两个角度均小于15度或大于165度,则表明有效四边形的两个打开臂朝上,则处理下一个;否则,如果该有效四边形的两个打开臂的终点位于两个角点的上方,则处理下一个,否则,将两个打开臂朝下的有效四边形记作种子四边形;若获取满足上述条件的下一个种子四边形,则计算当前种子四边形的两个角点到其凸包的最小距离之和是否小于上一个种子四边形的两个角点到其凸包的最小距离之和,如果小于则用当前种子四边形替换上一个种子四边形,否则剔除当前种子四边形,再继续处理,获取当前轮廓的最终的种子四边形;C8、判断当前轮廓的最终的种子四边形是否与有效四边形存在共享角点,判断方式为,在与当前轮廓匹配的种子四边形和有效四边形中,每个轮廓只有一个种子四边形但可能存在多个有效四边形,计算最终的种子四边形的两个角点分别到有效四边形的两个角点的距离,若四个距离均大于给定的阈值,则表明种子四边形和有效四边形不存在共享角点,处理下一有效四边形;C9、若存在共享角点,判断有效四边形的共享臂和打开臂所在线段与种子四边形的共享臂所在线段是否存在重叠,若存在重叠,判断有效四边形的共享臂和打开臂所在线段与种子四边形的打开臂所在线段的重叠数目是否大于等于1,若满足则获取以种子四边形的三条臂为上表面的边,有效四边形的除重叠臂以外的臂为侧垂面的边的立方物体轮廓,获取所有的立方物体轮廓,记作立方物体轮廓集合,每个立方物体轮廓是一个多边形;C10、根据立方物体轮廓的每条边的端点获取立方物体轮廓的所有点坐标,立方物体轮廓以种子四边形为上表面;C11、遍历立方物体轮廓集合,计算每个立方物体轮廓中心点的y坐标P.y和其上表面的中心点的y坐标t.y,计算每个立方物体轮廓的面积P.area和其上表面的面积t.area,如果t.y>P.y或t.area>P.area,则剔除该立方物体轮廓,获取最终的立方物体轮廓集合。0.8是给定的距离比例阈值。15度和165度为给定的低角度阈值和高角度阈值。In S7, the upper surface and the overall outline of the cubic object are determined according to the obtained segmented images of the quadrilateral and the upper surface, and then the left and right vertical surfaces corresponding to each upper surface quadrilateral are obtained according to the segmented images of the left and right vertical surfaces to realize the cubic object. position. The specific method of determining the upper surface and overall outline of the cubic object is as follows: C 1. Process the acquired quadrilateral first. If the distance between the end points of the two arms of the matched quadrilateral is less than 0.8 times the distance between the two corner points, the quadrilateral is not Meet, process the next quadrilateral, obtain all the 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 according to the segmented image of the upper surface, and obtain all contours , calculate its convex hull 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 greater than the given area threshold, if the contour If the area of is less than the given area threshold, the next contour is processed; C3. If the area of the contour is greater than the given area threshold, the current contour is matched with the qualified quadrilateral, and the two corner points of the matched quadrilateral are calculated respectively. The minimum distances h1 and h2 to the convex hull of the current contour, determine whether the two corners 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 h1 and Any one of h2 is greater than the given distance threshold, it means that there is a corner point on the inside of the contour and close to its center point, and the next quadrilateral matching is performed; C4, if the two corners of the matched quadrilateral are in The outside of the convex hull of the matching quadrilateral and both h1 and h2 are less than or equal to the distance threshold, the two corners of the matching quadrilateral are located outside the current contour, and determine whether the center point of the rotating rectangle outside the current contour is matching. Inside the convex hull of the quadrilateral, if it is not inside, perform the next quadrilateral matching; C5. If the center point of the rotated rectangle outside the current contour is inside the convex hull of the matching quadrilateral, calculate the minimum distance to the matching quadrilateral contour The absolute value of , 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 on the lower side of any arm of the matching quadrilateral, calculate the overlap between the bounding rectangle of the matching quadrilateral and the bounding rectangle of the current contour Area, if the overlapping area is greater than the given ratio threshold, the current contour and the matching quadrilateral are initially matched successfully, and the matched quadrilateral is recorded as the preliminary matching quadrilateral; C6, the center point of the rotation rectangle of the current contour to the preliminary matching quadrilateral The distance of the three arms is normalized, the normalized value is within the theoretical range, and the sum of h1 and h2 is less than or equal to the given threshold, the preliminary matching quadrilateral is recorded as an effective quadrilateral; C7, judge valid Whether the two open arms of the quadrilateral are facing down, the effective quadrilateral with the two open arms facing down is recorded as the seed quadrilateral. The angle of the line segment on the axis is 0 degrees, and the angle of the line segment increases continuously according to the clockwise rotation. The value range of the angle is [0, 360]. Use this definition rule to calculate the angle of the two open arms. If the two angles are less than 15 degrees or greater than 165 degrees , it means that the two open arms of the effective quadrilateral are facing up, and the next one is processed; otherwise, if the end point of the two open arms of the effective quadrilateral is above the two corner points, the next one is processed, otherwise, the two open arms are processed. The effective quadrilateral with arms facing down is recorded as the seed quadrilateral; if the next seed quadrilateral that satisfies the above conditions is obtained, calculate whether the sum of the minimum distances from the two corners of the current seed quadrilateral to its convex hull is less than the two of the previous seed quadrilateral. The sum of the minimum distances from the corner point to its convex hull, if it is less than the current seed quadrilateral, replace the previous seed quadrilateral, otherwise remove the current seed quadrilateral, and continue processing to obtain the final seed quadrilateral of the current contour; C8, determine the current contour Whether the final seed quadrilateral has a shared corner point with the valid quadrilateral is judged by: among the seed quadrilaterals and valid quadrilaterals matching the current contour, each contour has only one seed quadrilateral but there may be multiple valid quadrilaterals, and calculate the final seed quadrilateral The distances between the two corner points of , respectively, to the two corner points of the effective quadrilateral, if the four distances are all greater than the given threshold, it means that there is no shared corner point between the seed quadrilateral and the effective quadrilateral, and the next effective quadrilateral is processed; C9, if If there is a shared corner point, determine whether the line segment of the shared arm and the open arm of the effective quadrilateral overlaps with the line segment of the shared arm of the seed quadrilateral. Whether the overlapping number of the line segment where the open arm is located is greater than or equal to 1, and if so, obtain the contour of the cubic object with the three arms of the seed quadrilateral as the upper surface, and the arms of the effective quadrilateral except the overlapping arms as the sides of the side vertical plane, and obtain All the contours of the cubic object are recorded as the set of contours of the cubic object, and each contour of the cubic object is a polygon; C10. Obtain all the point coordinates of the contour of the cubic object according to the endpoints of each side of the contour of the cubic object, and the contour of the cubic object takes the seed quadrilateral as Upper surface; C11. Traverse the set of cubic object contours, calculate the y-coordinate P.y of the center point of the contour of each cubic object and the y-coordinate t.y of the center point of its upper surface, and calculate the area P.area of the contour of each cubic object and its upper surface The area t.area of , if t.y>P.y or t.area>P.area, then remove the contour of the cubic object to obtain the final set of cubic object contours. 0.8 is the given distance scale threshold. 15 degrees and 165 degrees are given low and high angle thresholds.
判断两条线段重叠的方式为:给定线段E和线段F,E的长度L1和F的长度H1;计算线段E和线段F间的角度差,如果角度差大于给定的阈值,则线段E和线段F不重叠;否则,计算E的起点到F的起点和终点的距离R1和R2,E的终点到F的起点和终点的距离R3和R4,如果max(max(R1, R2), max(R3, R4)) >= (max(L1, H1) + min(L1, H1) / 2),则线段E和线段F不重叠;否则,如果max(R1, R2) <H1,线段E的起点到线段F的距离小于给定的阈值,如果max(R3, R4) <H1,线段E的终点到线段F的距离小于给定的阈值,如果max(R1, R3) <L1,线段F的起点到线段E的距离小于给定的阈值,如果max(R2, R4) <L1,线段F的终点到线段E的距离小于给定的阈值,则线段E和线段F重叠。The way to judge the overlap of two line segments is: given line segment E and line segment F, length L1 of E and length H1 of F; calculate the angle difference between line segment E and line segment F, if the angle difference is greater than the given threshold, then line segment E Does not overlap with the line segment F; 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), then line segment E and line segment F do not overlap; otherwise, if max(R1, R2) < H1, line segment E's The distance from the starting point to the line segment F is less than the given threshold. If max(R3, R4) < H1, the distance from the end point of the line segment E to the line segment F is less than the given threshold. If max(R1, R3) < L1, the distance of the line segment F The distance from the starting point to the line segment E is less than the given threshold. If max(R2, R4) < L1, and the distance from the end point of the line segment F to the line segment E is less than the given threshold, the line segment E and the line segment F overlap.
S8中根据左垂面的分割图像和右垂面的分割图像获取每个上表面四边形对应的左右垂直面,实现立方物体定位的具体方式为:遍历所有立方物体轮廓集合,根据左垂面的分割图像获取左垂直面所有的轮廓及其对应的旋转矩形和外接矩形,判断旋转矩形的中心点的y坐标是否大于等于上表面四边形中心点的y坐标,若旋转矩形的中心点的y坐标小于上表面四边形中心点的y坐标,处理下一轮廓;若旋转矩形的中心点的y坐标大于等于上表面四边形中心点的y坐标,判断上表面四边形对应的立方物体轮廓面积和外接矩形的重叠面积占立方物体轮廓面积的比例是否大于等于0.6;若大于等于0.6,寻找满足上述条件的所有左垂面轮廓中面积最大的轮廓即为当前立方物体的左垂直面轮廓;根据右垂直分割图像获取右垂直面所有轮廓及其对应的旋转矩形和外接矩形,对右垂直分割图像的所有轮廓的处理方式与左垂直面的所有轮廓的处理方式一致,以此获取每个立方物体上表面对应的左垂直面和右垂直面,每组上表面、左垂直面和右垂直面构成一个立方物体,实现立方物体检测。0.6是给定的面积比例阈值。In S8, 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 segmentation image of the right vertical plane. The image obtains all the contours of the left vertical plane and their corresponding rotated rectangles and circumscribed rectangles, and determines 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 quadrilateral on the upper surface. If the y-coordinate of the center point of the rotated rectangle is smaller than the upper The y-coordinate of the center point of the quadrilateral on the surface is used to process the next contour; if the y-coordinate of the center point of the rotating rectangle is greater than or equal to the y-coordinate of the center point of the quadrilateral on the upper surface, determine the area of the contour of the cube corresponding to the quadrilateral on the upper surface and the overlapping area of the circumscribed rectangle. Whether the ratio of the contour area of the cube object is 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 the left vertical contours that meet the above conditions, which is the left vertical contour of the current cubic object; obtain the right vertical contour according to the right vertical segmentation image All the contours of the surface and their corresponding rotated rectangles and circumscribed rectangles. The processing methods for all the contours of the right vertical segmented image are the same as the processing methods for all the contours of the left vertical surface, so as to obtain the left vertical surface corresponding to the upper surface of each cubic object. and the right vertical plane, each group of upper surface, left vertical plane and right vertical plane constitutes a cubic object to realize cubic object detection. 0.6 is the given area scale threshold.
以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the scope of the present invention. within the scope of protection.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910989775.9A CN110728246A (en) | 2019-10-17 | 2019-10-17 | A Cube Object Recognition Method Based on Depth Image |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910989775.9A CN110728246A (en) | 2019-10-17 | 2019-10-17 | A Cube Object Recognition Method Based on Depth Image |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN110728246A true CN110728246A (en) | 2020-01-24 |
Family
ID=69220262
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910989775.9A Pending CN110728246A (en) | 2019-10-17 | 2019-10-17 | A Cube Object Recognition Method Based on Depth Image |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN110728246A (en) |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111598939A (en) * | 2020-05-22 | 2020-08-28 | 中原工学院 | A method of measuring human body circumference based on multi-eye vision system |
| CN113989276A (en) * | 2021-12-23 | 2022-01-28 | 珠海视熙科技有限公司 | Detection method and detection device based on depth image and camera equipment |
| CN114690730A (en) * | 2022-06-01 | 2022-07-01 | 南通科特森新材料科技有限公司 | Automatic control method and system for process parameters in composite material production process |
| CN118036628A (en) * | 2023-08-28 | 2024-05-14 | 武汉金顿激光科技有限公司 | Work piece intelligent management method, system and storage medium |
| CN118212179A (en) * | 2024-02-05 | 2024-06-18 | 钛玛科(北京)工业科技有限公司 | Angle detection method for complex background |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20110085738A1 (en) * | 2008-05-26 | 2011-04-14 | Kazuo Kitamura | Edge extraction apparatus, surveying equipment, and program |
| US20150332474A1 (en) * | 2014-05-18 | 2015-11-19 | Edge 3 Technologies, Inc. | Orthogonal and Collaborative Disparity Decomposition |
| CN107945192A (en) * | 2017-12-14 | 2018-04-20 | 北京信息科技大学 | A kind of pallet carton pile type real-time detection method |
| CN108627092A (en) * | 2018-04-17 | 2018-10-09 | 南京阿凡达机器人科技有限公司 | A kind of measurement method, system, storage medium and the mobile terminal of package volume |
| CN109472822A (en) * | 2018-12-29 | 2019-03-15 | 上海大学 | Object size measurement method based on depth image processing |
| US20190206059A1 (en) * | 2017-12-29 | 2019-07-04 | Datalogic Usa, Inc. | Locating objects on surfaces |
-
2019
- 2019-10-17 CN CN201910989775.9A patent/CN110728246A/en active Pending
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20110085738A1 (en) * | 2008-05-26 | 2011-04-14 | Kazuo Kitamura | Edge extraction apparatus, surveying equipment, and program |
| US20150332474A1 (en) * | 2014-05-18 | 2015-11-19 | Edge 3 Technologies, Inc. | Orthogonal and Collaborative Disparity Decomposition |
| CN107945192A (en) * | 2017-12-14 | 2018-04-20 | 北京信息科技大学 | A kind of pallet carton pile type real-time detection method |
| US20190206059A1 (en) * | 2017-12-29 | 2019-07-04 | Datalogic Usa, Inc. | Locating objects on surfaces |
| CN108627092A (en) * | 2018-04-17 | 2018-10-09 | 南京阿凡达机器人科技有限公司 | A kind of measurement method, system, storage medium and the mobile terminal of package volume |
| CN109472822A (en) * | 2018-12-29 | 2019-03-15 | 上海大学 | Object size measurement method based on depth image processing |
Non-Patent Citations (1)
| Title |
|---|
| 陆鹏: "基于视觉的移动机器人三维场景感知技术研究", 《中国优秀硕士学位论文全文数据库信息科技辑》, 15 March 2017 (2017-03-15), pages 1 - 73 * |
Cited By (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111598939A (en) * | 2020-05-22 | 2020-08-28 | 中原工学院 | A method of measuring human body circumference based on multi-eye vision system |
| CN111598939B (en) * | 2020-05-22 | 2021-01-26 | 中原工学院 | Human body circumference measuring method based on multi-vision system |
| CN113989276A (en) * | 2021-12-23 | 2022-01-28 | 珠海视熙科技有限公司 | Detection method and detection device based on depth image and camera equipment |
| CN114690730A (en) * | 2022-06-01 | 2022-07-01 | 南通科特森新材料科技有限公司 | Automatic control method and system for process parameters in composite material production process |
| CN118036628A (en) * | 2023-08-28 | 2024-05-14 | 武汉金顿激光科技有限公司 | Work piece intelligent management method, system and storage medium |
| CN118212179A (en) * | 2024-02-05 | 2024-06-18 | 钛玛科(北京)工业科技有限公司 | Angle detection method for complex background |
| CN118212179B (en) * | 2024-02-05 | 2024-12-13 | 钛玛科(北京)工业科技有限公司 | Angle detection method for complex background |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN110751640B (en) | Quadrilateral detection method for depth image based on corner pairing | |
| CN110751688B (en) | Cube object volume calculation method for removing noise based on depth image | |
| CN110570471B (en) | A method for measuring the volume of cubic objects based on depth images | |
| CN110728246A (en) | A Cube Object Recognition Method Based on Depth Image | |
| CN111507390B (en) | Storage box body identification and positioning method based on contour features | |
| CN107369161B (en) | Scattered workpiece point cloud segmentation method based on improved Euclidean clustering | |
| CN102930540B (en) | Method and system for detecting contour of urban building | |
| CN110689568A (en) | Accurate calculation method for cubic object volume based on depth image | |
| CN105335973B (en) | Apply to the visual processing method of strip machining production line | |
| CN108010036A (en) | A kind of object symmetry axis detection method based on RGB-D cameras | |
| CN106372642A (en) | Rapid ellipse detection method based on contour curve segmentation arc merging and combination | |
| CN110263795B (en) | Target detection method based on implicit shape model and graph matching | |
| CN111145228A (en) | Heterogeneous image registration method based on local contour point and shape feature fusion | |
| CN110569861A (en) | An Image Matching and Localization Method Based on Fusion of Point Features and Contour Features | |
| CN114862855B (en) | Textile defect detection method and system based on template matching | |
| CN113034574B (en) | Commodity ground heap area calculation method and system based on target detection | |
| CN111860501A (en) | Image recognition method of high-speed rail height adjustment rod falling out fault based on shape matching | |
| CN111080631A (en) | Fault positioning method and system for detecting floor defects of spliced images | |
| CN110929598B (en) | Unmanned aerial vehicle-mounted SAR image matching method based on contour features | |
| CN114742789A (en) | General part picking method and system based on surface structured light and electronic equipment | |
| CN103761523A (en) | Automatic identification and tracking method for airborne remote sensing video in specific man-made area | |
| CN113689429A (en) | Wood board defect detection method based on computer vision | |
| CN115272459A (en) | A four-corner two-dimensional code directional plane target device and its calibration method | |
| CN114049380A (en) | Target object positioning and tracking method, device, computer equipment and storage medium | |
| CN113962967A (en) | Object shot image ellipse detection algorithm based on Markuling theorem constraint |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| TA01 | Transfer of patent application right | ||
| TA01 | Transfer of patent application right |
Effective date of registration: 20250507 Address after: Gao Lou Zhen Hong Di Cun, Rui'an City, Wenzhou City, Zhejiang Province, 325200 Applicant after: Wang Conghai Country or region after: China Address before: 210032 room 501A, block a, software building, No.9 Xinghuo Road, high tech Zone, Nanjing City, Jiangsu Province Applicant before: NANJING XINHEHUITONG ELECTRON TECHNOLOGY CO.,LTD. Country or region before: China |