Spaces:
Running on Zero
Running on Zero
File size: 1,498 Bytes
c46c3d9 6cc84ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | from PIL import Image
import detection_utils as utils
DETECTIONS = [
{
"class_id": 0,
"class_name": "person",
"confidence": 0.9,
"x1": 1.0,
"y1": 2.0,
"x2": 10.0,
"y2": 20.0,
},
{
"class_id": 2,
"class_name": "car",
"confidence": 0.7,
"x1": 12.0,
"y1": 4.0,
"x2": 30.0,
"y2": 18.0,
},
{
"class_id": 2,
"class_name": "car",
"confidence": 0.5,
"x1": 32.0,
"y1": 5.0,
"x2": 45.0,
"y2": 17.0,
},
]
def test_detection_summary_groups_and_sorts_classes():
assert utils.build_detection_summary(DETECTIONS) == [
["car", 2, 0.6, 0.7],
["person", 1, 0.9, 0.9],
]
def test_street_indicators_are_transparent_counts():
assert utils.build_street_indicators(DETECTIONS) == {
"people": 1,
"active_mobility": 1,
"motor_vehicles": 2,
"all_transport": 2,
}
def test_detection_overlay_matches_input_size():
image = Image.new("RGB", (60, 40), "white")
rendered = utils.render_detection(image, DETECTIONS)
assert rendered.size == image.size
assert rendered.getpixel((1, 2)) != (255, 255, 255)
def test_label_boxes_avoid_existing_labels():
first = utils._label_box([20, 30, 30, 40], 20, 10, (100, 100), [])
second = utils._label_box([22, 30, 32, 40], 20, 10, (100, 100), [first])
assert not utils._boxes_overlap(first, second)
|