Spaces:
Running on Zero
Running on Zero
| 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) | |