Beispiel #1
0
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)
Beispiel #2
0
def jaccard_index_3d(a: BBox3D, b: BBox3D):
    """
    Compute the Jaccard Index / Intersection over Union (IoU) of a pair of 3D bounding boxes.
    We compute the IoU using the top-down bird's eye view of the boxes.

    **Note**: We follow the KITTI format and assume only yaw rotations (along z-axis).

    Parameters
    ----------
    a : BBox3D
        3D bounding box.
    b : BBox3D
        3D bounding box.
    Returns
    -------
    float
        The IoU of the 2 bounding boxes.
    """
    # check if the two boxes don't overlap
    if not polygon_collision(a.p[0:4, 0:2], b.p[0:4, 0:2]):
        return np.round_(0, decimals=5)

    intersection_points = polygon_intersection(a.p[0:4, 0:2], b.p[0:4, 0:2])
    inter_area = polygon_area(intersection_points)

    zmax = np.minimum(a.cz, b.cz)
    zmin = np.maximum(a.cz - a.h, b.cz - b.h)

    inter_vol = inter_area * np.maximum(0, zmax - zmin)

    a_vol = a.l * a.w * a.h
    b_vol = b.l * b.w * b.h

    union_vol = (a_vol + b_vol - inter_vol)

    iou = inter_vol / union_vol

    # set nan and +/- inf to 0
    if np.isinf(iou) or np.isnan(iou):
        iou = 0

    return np.round_(iou, decimals=5)