def test_jaccard_index_3d_euler_angles(): a = BBox3D(3.163, z=2.468, y=34.677, height=1.529, width=1.587, length=3.948, euler_angles=[0, 0, 1.59]) b = BBox3D(3.18, z=2.27, y=34.38, height=1.41, width=1.58, length=4.36, euler_angles=[0, 0, 1.58]) assert jaccard_index_3d(a, b) == 0.71636
def test_jaccard_index_3d(): a = BBox3D(x=3.163, z=2.468, y=34.677, height=1.529, width=1.587, length=3.948, rw=0.7002847660410397, rx=-0, ry=-0, rz=-0.7138636049350369) b = BBox3D(x=3.18, z=2.27, y=34.38, height=1.41, width=1.58, length=4.36, rx=-0, ry=-0, rz=-0.7103532724176078, rw=0.7038453156522361) assert jaccard_index_3d(a, b) == 0.71232
def test_polygon_no_collision(): # randomly generated values a = BBox3D(0.9, 0.5, 0.5, 1, 1, 1) b = BBox3D(0.1, 0.1, 0.1, 0.1, 1, 1) p1, p2 = a.p[0:4, 0:2], b.p[0:4, 0:2] assert polygon_collision(p1, p2) == False
def test_jaccard_index_3d_rotation_height(): a = BBox3D(3.163, z=2.468, y=34.677, height=1.529, width=1.587, length=3.948, rw=0.7002847660410397, rx=-0, ry=-0, rz=-0.7138636049350369) b = BBox3D(3.163, z=1.468, y=34.677, height=1.529, width=1.587, length=3.948, rw=0.8253356149096783, rx=-0, ry=-0, rz=-0.5646424733950354) assert jaccard_index_3d(a, b) == 0.15428
def test_non_overlapping_boxes(self): a = BBox3D(x=-2.553668269106177, y=-63.56305079381365, z=1.988316894113887, length=4.7, width=1.8420955618567376, height=1.4, q=(-0.7123296970493456, 0.0, 0.0, 0.7018449990571904)) b = BBox3D(x=-60.00052106600015, y=-4.111285291215302, z=0.7497459084120979, length=4.7, width=1.8, height=1.819601518010064, q=(0.999845654958524, 0.0, 0.0, 0.017568900379933073))
def test_polygon_intersection(): a = BBox3D(0.5, 0.5, 0.5, 1, 1, 1) b = BBox3D(1, 1, 1, 1, 1, 1) i1 = clip(a.p[0:4, 0:2], b.p[0:4, 0:2]) i1 = np.array(i1) i2 = polygon_intersection(a.p[0:4, 0:2], b.p[0:4, 0:2]) assert np.array_equal(i1, i2)
def test_jaccard_index_3d_rotation_only(): """ Since we take the data from KITTI, we need to swap the Y and Z axes. """ a = BBox3D(3.163, z=2.468, y=34.677, height=1.529, width=1.587, length=3.948, euler_angles=[0, 0, -1.59]) b = BBox3D(3.163, z=2.468, y=34.677, height=1.529, width=1.587, length=3.948, euler_angles=[0, 0, -1.2]) assert jaccard_index_3d(a, b) == 0.62952
def dddIOU(d, g): # d = ddd_to_dd_box(d) ious = np.zeros((len(d), len(g))) for di in range(len(d)): box_d = BBox3D(d[di][0], d[di][1], d[di][2], d[di][3], d[di][4], d[di][5]) for gi in range(len(g)): box_g = BBox3D(g[gi][0], g[gi][1], g[gi][2], g[gi][3], g[gi][4], g[gi][5]) ious[di, gi] = iou_3d(box_d, box_g) return ious
def test_is_separating_axis(): # randomly generated values a = BBox3D(0.9, 0.5, 0.5, 1, 1, 1) b = BBox3D(0.1, 0.1, 0.1, 0.1, 1, 1) p1, p2 = a.p[0:4, 0:2], b.p[0:4, 0:2] edges = edges_of(p1) edges += edges_of(p2) # positive case separates, pv = is_separating_axis(orthogonal(edges[0]), p1, p2) assert separates == False and pv is not None separates, pv = is_separating_axis(orthogonal(edges[1]), p1, p2) assert separates == True and pv is None
def setup_class(cls): # sample cuboid cuboid = { 'center': { 'x': -49.19743041908411, 'y': 12.38666074615689, 'z': 0.782056864653507 }, 'dimensions': { 'length': 5.340892485711914, 'width': 2.457703972075464, 'height': 1.9422248281533563 }, 'rotation': { 'w': 0.9997472337219893, 'x': 0.0, 'y': 0.0, 'z': 0.022482630300529462 } } center = cuboid['center'] dim = cuboid['dimensions'] rotation = cuboid['rotation'] cls.box = BBox3D(center['x'], center['y'], center['z'], length=dim['length'], width=dim['width'], height=dim['height'], rw=rotation['w'], rx=rotation['x'], ry=rotation['y'], rz=rotation['z']) cls.cuboid = cuboid
def test_quaternion(self): q = np.array([0.9997472337219893, 0.0, 0.0, 0.022482630300529462]) assert np.array_equal(self.box.q, q) # alternative attribute for the quaternion assert np.array_equal(self.box.quaternion, q) box = BBox3D(self.box.cx, self.box.cy, self.box.cz, q=self.box.q) assert np.array_equal(self.box.q, box.q)
def create_3D_box(env_object, objdim): #DOPE objpos = env_object.get_position() objorient = env_object.get_orientation() #objdim = env_object.get_cuboid_dimensions() box = BBox3D(objpos[0], objpos[1], objpos[2], objdim[0], objdim[1], objdim[2], objorient[3], objorient[0], objorient[1], objorient[2]) return box.p, box.center
def test_init_non_center(self): cx, cy, cz = self.box.cx, self.box.cy, self.box.cz box = BBox3D(cx - self.box.length / 2, cy - self.box.width / 2, cz - self.box.height / 2, self.box.length, self.box.width, self.box.height, is_center=False) assert np.array_equal(box.center, self.box.center)
def test_euler_angles(self): box = BBox3D(3.163, z=2.468, y=34.677, height=1.529, width=1.587, length=3.948, euler_angles=[0, 0, -1.59]) q = np.array([0.7002847660410397, -0.0, -0.0, -0.7138636049350369]) assert np.array_equal(box.q, q)
def test_jaccard_index_3d_identity(): bb = BBox3D(3.163, z=2.468, y=34.677, height=1.529, width=1.587, length=3.948, rw=0.7002847660410397, rx=-0, ry=-0, rz=-0.7138636049350369) assert jaccard_index_3d(bb, bb) == 1
def test_invalid_jaccard_index_3d(): # H=0,W=0,L=0, so the IoU should be nan bb = BBox3D(3.163, z=2.468, y=34.677, height=0, width=0, length=0, rw=0.7002847660410397, rx=-0, ry=-0, rz=-0.7138636049350369) assert jaccard_index_3d(bb, bb) == 0
def test_jaccard_index_3d_polygon_collision(): # these two boxes should not overlap a = BBox3D(x=3.163, z=2.468, y=34.677, height=1.529, width=1.587, length=3.948, rw=0.7002847660410397, rx=-0, ry=-0, rz=-0.7138636049350369) b = BBox3D(x=30.18, z=20.27, y=90.38, height=1.41, width=1.58, length=4.36, rx=-0, ry=-0, rz=-0.7103532724176078, rw=0.7038453156522361) assert jaccard_index_3d(a, b) == 0
def test_center_init(self): box = BBox3D(*[self.box.cx, self.box.cy, self.box.cz]) assert np.array_equal(box.center, self.box.center)
def test_init_center(self): box = BBox3D(*[self.box.cx, self.box.cy, self.box.cz], is_center=True) assert np.array_equal(box.center, self.box.center)