示例#1
0
def test_bounding_box_center():
    xywh = np.array([2369, 2975, 74, 201])
    xy = xywh[:2]
    w = xywh[2]
    h = xywh[3]
    bbox = BoundingBox.from_xywh(xy, w, h)
    assert np.array_equal(bbox.center, np.array([2406, 3075]))
示例#2
0
def test_box_from_xywh():
    """Test to see if bounding box can be created from XYWH format"""
    xywh = np.array([2369, 2975, 74, 78])
    xy = xywh[:2]
    w = xywh[2]
    h = xywh[3]
    bbox = BoundingBox.from_xywh(xy, w, h)
    xyxy = bbox.to_xyxy()
    assert np.array_equal(xyxy, np.array([[2369, 2975], [2369 + w, 2975 + h]]))
示例#3
0
def test_bounding_to_yolo():
    """Test to see if bounding box can be converted to YOLO"""
    image_dim = np.array([5472, 3648])
    xywh = np.array([2369, 2975, 74, 78])
    xy = xywh[:2]
    w = xywh[2]
    h = xywh[3]
    bbox = BoundingBox.from_xywh(xy, w, h)
    correct = np.array([0.65953947, 0.55080409, 0.02028509, 0.01425439])
    yolo = bbox.to_yolo(image_dim)
    assert np.allclose(yolo, correct)