Пример #1
0
def test_box_from_xyxy_vertical_line():
    """Test to see assertion thrown with invalid points (vertical line)"""
    xy1 = np.array([2369, 2975])
    xy2 = np.array([2369 + 70, 2975])

    with pytest.raises(AssertionError):
        _ = BoundingBox.from_xyxy(xy2, xy1)

    with pytest.raises(AssertionError):
        _ = BoundingBox.from_xyxy(xy1, xy2)
Пример #2
0
def test_bounding_to_yolo_small_box():
    """Make sure YOLO conversion works correctly with a small bounding box"""
    image_dim = np.array([3648, 5472])
    xy1 = np.array([4360, 971])
    xy2 = np.array([4397, 998])
    bbox = BoundingBox.from_xyxy(xy1, xy2)
    yolo = bbox.to_yolo(image_dim)
    assert np.allclose(
        yolo, np.array([0.8000731, 0.26973684, 0.0067617, 0.00740132]))

    image_dim = np.array([3456, 4608])
    xy1 = np.array([3155, 3432])
    xy2 = np.array([3234, 3455])
    bbox = BoundingBox.from_xyxy(xy1, xy2)
    yolo = bbox.to_yolo(image_dim)
    assert np.allclose(
        yolo, np.array([0.69314236, 0.99623843, 0.0171441, 0.00665509]))
Пример #3
0
def test_box_from_xyxy():
    """Test to see if bounding box can be created from XYXY format"""
    xy1 = np.array([2369, 2975])
    xy2 = np.array([2369 + 40, 2975 + 70])
    bbox = BoundingBox.from_xyxy(xy1, xy2)
    xy, w, h = bbox.to_xywh()
    assert np.array_equal(xy, xy1)
    assert w == 40
    assert h == 70
Пример #4
0
def test_bounding_to_yolo_tl_at_zero():
    """Make sure YOLO conversion works correctly with a small bounding box"""
    image_dim = np.array([3648, 5472])
    xy1 = np.array([4360, 0])
    xy2 = np.array([4397, 998])
    bbox = BoundingBox.from_xyxy(xy1, xy2)
    yolo = bbox.to_yolo(image_dim)
    assert np.allclose(
        yolo, np.array([0.8000731, 0.13678728, 0.0067617, 0.27357456]))
Пример #5
0
def test_box_from_xyxy_swapped_order():
    """Test to see if bounding box can be created from XYXY
    format when top_left and bottom_right are swapped"""
    xy1 = np.array([2369, 2975])
    xy2 = np.array([2369 + 40, 2975 + 70])
    bbox = BoundingBox.from_xyxy(xy2, xy1)
    xy, w, h = bbox.to_xywh()
    assert np.array_equal(xy, xy1)
    assert w == 40
    assert h == 70
Пример #6
0
def test_bounding_to_yolo_invalid_points():
    """Test assertion is thrown when creating YOLO
    coordinates with out of bound point"""
    image_dim = np.array([5472, 3648])
    xy1 = np.array([3640, 78])
    xy2 = np.array([3650, 100])
    bbox = BoundingBox.from_xyxy(xy1, xy2)

    with pytest.raises(AssertionError):
        _ = bbox.to_yolo(image_dim)
Пример #7
0
def test_box_from_xyxy_same_point():
    """Test to see assertion thrown with invalid points (points equal)"""
    xy1 = np.array([2369, 2975])

    with pytest.raises(AssertionError):
        _ = BoundingBox.from_xyxy(xy1, xy1)