Skip to content

Commit

Permalink
feat: add warning when no markings are beeing detected
Browse files Browse the repository at this point in the history
  • Loading branch information
itisacloud committed Aug 14, 2024
1 parent 31668ef commit 11d8783
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sketch_map_tool/upload_processing/detect_markings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import cv2
import numpy as np
from numpy.typing import NDArray
Expand Down Expand Up @@ -41,6 +43,8 @@ def detect_markings(
yolo_cls,
sam_predictor,
)
if len(colors) == 0:
logging.warning("No markings detected.")
colors = [int(c) + 1 for c in colors] # +1 because 0 is background
processed_markings = post_process(masks, bboxes, colors)
return processed_markings
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/upload_processing/test_detect_markings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import numpy as np
import pytest
from PIL import Image, ImageEnhance
Expand Down Expand Up @@ -77,3 +79,19 @@ def test_detect_markings(
for m in markings:
img = Image.fromarray(m)
ImageEnhance.Contrast(img).enhance(10).show()


def test_detectec_markings_failure(yolo_osm_cls, yolo_osm_obj, sam_predictor, caplog):
# Empty map and template should not contain any markings
empty_map = np.zeros((1024, 1024, 3), dtype=np.uint8)
empty_template = np.zeros((1024, 1024, 3), dtype=np.uint8)

with caplog.at_level(logging.WARNING):
detect_markings(
empty_map,
empty_template,
yolo_osm_obj,
yolo_osm_cls,
sam_predictor,
)
assert "No markings detected." in caplog.text

0 comments on commit 11d8783

Please sign in to comment.