Skip to content

Commit 0572c04

Browse files
itisacloudmatthiasschaub
authored andcommitted
refactor: log a warning if no markings has been detected
1 parent 8babe1d commit 0572c04

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

sketch_map_tool/upload_processing/detect_markings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import logging
2+
13
import cv2
24
import numpy as np
35
from numpy.typing import NDArray
@@ -41,6 +43,8 @@ def detect_markings(
4143
yolo_cls,
4244
sam_predictor,
4345
)
46+
if len(colors) == 0:
47+
logging.warning("No markings detected.")
4448
colors = [int(c) + 1 for c in colors] # +1 because 0 is background
4549
processed_markings = post_process(masks, bboxes, colors)
4650
return processed_markings

tests/integration/upload_processing/test_detect_markings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import logging
2+
13
import numpy as np
24
import pytest
35
from PIL import Image, ImageEnhance
@@ -77,3 +79,19 @@ def test_detect_markings(
7779
for m in markings:
7880
img = Image.fromarray(m)
7981
ImageEnhance.Contrast(img).enhance(10).show()
82+
83+
84+
def test_detectec_markings_failure(yolo_osm_cls, yolo_osm_obj, sam_predictor, caplog):
85+
# Empty map and template should not contain any markings
86+
empty_map = np.zeros((1024, 1024, 3), dtype=np.uint8)
87+
empty_template = np.zeros((1024, 1024, 3), dtype=np.uint8)
88+
89+
with caplog.at_level(logging.WARNING):
90+
detect_markings(
91+
empty_map,
92+
empty_template,
93+
yolo_osm_obj,
94+
yolo_osm_cls,
95+
sam_predictor,
96+
)
97+
assert "No markings detected." in caplog.text

0 commit comments

Comments
 (0)