【三维目标检测】VoteNet:Deep Hough Voting for 3D Object Detection in Point Clouds
1 def box3d_iou(corners1, corners2): 2 ''' Compute 3D bounding box IoU. 3 Input: 4 corners1: numpy array (8,3), assume up direction is negative Y 5 corners2: numpy array (8,3), assume up direction is negative Y 6 Output: 7 iou: 3D bounding box IoU 8 iou_2d: bird's eye view 2D bounding box IoU 9 todo (rqi): add more description on corner points' orders. 10 ''' 11 # corner points are in counter clockwise order 12 rect1 = [(corners1[i,0], corners1[i,2]) for i in range(3,-1,-1)] 13 rect2 = [(corners2[i,0], corners2[i,2]) for i in range(3,-1,-1)] 14 area1 = poly_area(np.array(rect1)[:,0], np.array(rect1)[:,1]) 15 area2 = poly_area(np.array(rect2)[:,0], np.array(rect2)[:,1]) 16 inter, inter_area = convex_hull_intersection(rect1, rect2) 17 iou_2d = inter_area/(area1+area2-inter_area) 18 ymax = min(corners1[0,1], corners2[0,1]) 19 ymin = max(corners1[4,1], corners2[4,1]) 20 inter_vol = inter_area * max(0.0, ymax-ymin) 21 vol1 = box3d_vol(corners1) 22 vol2 = box3d_vol(corners2) 23 iou = inter_vol / (vol1 + vol2 - inter_vol) 24 return iou, iou_2d
1 def get_iou(bb1, bb2): 2 """ 3 Calculate the Intersection over Union (IoU) of two 2D bounding boxes. 4 Parameters 5 ---------- 6 bb1 : dict 7 Keys: {'x1', 'x2', 'y1', 'y2'} 8 The (x1, y1) position is at the top left corner, 9 the (x2, y2) position is at the bottom right corner 10 bb2 : dict 11 Keys: {'x1', 'x2', 'y1', 'y2'} 12 The (x, y) position is at the top left corner, 13 the (x2, y2) position is at the bottom right corner 14 Returns 15 ------- 16 float 17 in [0, 1] 18 """ 19 assert bb1['x1'] < bb1['x2'] 20 assert bb1['y1'] < bb1['y2'] 21 assert bb2['x1'] < bb2['x2'] 22 assert bb2['y1'] < bb2['y2'] 23 24 # determine the coordinates of the intersection rectangle 25 x_left = max(bb1['x1'], bb2['x1']) 26 y_top = max(bb1['y1'], bb2['y1']) 27 x_right = min(bb1['x2'], bb2['x2']) 28 y_bottom = min(bb1['y2'], bb2['y2']) 29 30 if x_right < x_left or y_bottom < y_top: 31 return 0.0 32 33 # The intersection of two axis-aligned bounding boxes is always an 34 # axis-aligned bounding box 35 intersection_area = (x_right - x_left) * (y_bottom - y_top) 36 37 # compute the area of both AABBs 38 bb1_area = (bb1['x2'] - bb1['x1']) * (bb1['y2'] - bb1['y1']) 39 bb2_area = (bb2['x2'] - bb2['x1']) * (bb2['y2'] - bb2['y1']) 40 41 # compute the intersection over union by taking the intersection 42 # area and dividing it by the sum of prediction + ground-truth 43 # areas - the interesection area 44 iou = intersection_area / float(bb1_area + bb2_area - intersection_area) 45 assert iou >= 0.0 46 assert iou <= 1.0 47 return iou
posted on 2020-04-28 19:12 Attack-DrHao 阅读(817) 评论(0) 编辑 收藏 举报