Spaces:
Sleeping
Sleeping
Commit ·
8beea23
1
Parent(s): dfe265a
Thinner, more precise detection lines and compact labels
Browse files- app/detection_engine.py +7 -7
app/detection_engine.py
CHANGED
|
@@ -624,7 +624,7 @@ def visualize_changes(img1, img2, change_mask, regions=None, total_pixels=None):
|
|
| 624 |
|
| 625 |
if regions:
|
| 626 |
diag = np.sqrt(img2.shape[0]**2 + img2.shape[1]**2)
|
| 627 |
-
line_thickness = max(
|
| 628 |
|
| 629 |
for r in regions:
|
| 630 |
x, y, w, h = r["bbox"]
|
|
@@ -638,22 +638,22 @@ def visualize_changes(img1, img2, change_mask, regions=None, total_pixels=None):
|
|
| 638 |
y2c = min(overlay_uint8.shape[0], y + h)
|
| 639 |
roi = overlay_uint8[y1c:y2c, x1c:x2c]
|
| 640 |
fill = np.full_like(roi, color, dtype=np.uint8)
|
| 641 |
-
cv2.addWeighted(fill, 0.
|
| 642 |
|
| 643 |
cv2.rectangle(overlay_uint8, (x, y), (x + w, y + h), color, line_thickness)
|
| 644 |
|
| 645 |
rid = r.get("id", 0)
|
| 646 |
label = str(rid)
|
| 647 |
font = cv2.FONT_HERSHEY_SIMPLEX
|
| 648 |
-
font_scale = max(0.
|
| 649 |
-
thickness =
|
| 650 |
(tw, th), _ = cv2.getTextSize(label, font, font_scale, thickness)
|
| 651 |
lx = x
|
| 652 |
-
ly = max(th +
|
| 653 |
cv2.rectangle(overlay_uint8,
|
| 654 |
-
(lx, ly - th -
|
| 655 |
color, cv2.FILLED)
|
| 656 |
-
cv2.putText(overlay_uint8, label, (lx +
|
| 657 |
font, font_scale, (255, 255, 255), thickness, cv2.LINE_AA)
|
| 658 |
|
| 659 |
return overlay_uint8
|
|
|
|
| 624 |
|
| 625 |
if regions:
|
| 626 |
diag = np.sqrt(img2.shape[0]**2 + img2.shape[1]**2)
|
| 627 |
+
line_thickness = max(1, int(diag / 900))
|
| 628 |
|
| 629 |
for r in regions:
|
| 630 |
x, y, w, h = r["bbox"]
|
|
|
|
| 638 |
y2c = min(overlay_uint8.shape[0], y + h)
|
| 639 |
roi = overlay_uint8[y1c:y2c, x1c:x2c]
|
| 640 |
fill = np.full_like(roi, color, dtype=np.uint8)
|
| 641 |
+
cv2.addWeighted(fill, 0.07, roi, 0.93, 0, roi)
|
| 642 |
|
| 643 |
cv2.rectangle(overlay_uint8, (x, y), (x + w, y + h), color, line_thickness)
|
| 644 |
|
| 645 |
rid = r.get("id", 0)
|
| 646 |
label = str(rid)
|
| 647 |
font = cv2.FONT_HERSHEY_SIMPLEX
|
| 648 |
+
font_scale = max(0.35, min(0.55, w / 180))
|
| 649 |
+
thickness = 1
|
| 650 |
(tw, th), _ = cv2.getTextSize(label, font, font_scale, thickness)
|
| 651 |
lx = x
|
| 652 |
+
ly = max(th + 4, y - 4)
|
| 653 |
cv2.rectangle(overlay_uint8,
|
| 654 |
+
(lx, ly - th - 3), (lx + tw + 6, ly + 1),
|
| 655 |
color, cv2.FILLED)
|
| 656 |
+
cv2.putText(overlay_uint8, label, (lx + 3, ly - 1),
|
| 657 |
font, font_scale, (255, 255, 255), thickness, cv2.LINE_AA)
|
| 658 |
|
| 659 |
return overlay_uint8
|