coderuday21 commited on
Commit
8beea23
·
1 Parent(s): dfe265a

Thinner, more precise detection lines and compact labels

Browse files
Files changed (1) hide show
  1. 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(2, int(diag / 400))
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.12, roi, 0.88, 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.45, min(0.8, w / 120))
649
- thickness = max(1, line_thickness - 1)
650
  (tw, th), _ = cv2.getTextSize(label, font, font_scale, thickness)
651
  lx = x
652
- ly = max(th + 6, y - 6)
653
  cv2.rectangle(overlay_uint8,
654
- (lx, ly - th - 6), (lx + tw + 10, ly + 2),
655
  color, cv2.FILLED)
656
- cv2.putText(overlay_uint8, label, (lx + 5, ly - 2),
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