Files
momentry_core/scripts/visualize_stamp.py
Warren e75c4d6f07 cleanup: remove dead code and duplicate docs
- Remove session-ses_2f27.md (161KB raw session log)
- Remove 49 ROOT_* duplicate files across REFERENCE/
- Remove 14 duplicate files between REFERENCE/ root and history/
- Remove asr_legacy.rs (dead code, replaced by asr.rs)
- Remove src/core/worker/ (duplicate JobWorker)
- Remove src/core/layers/ (empty directory)
- Remove 4 .bak files in src/
- Remove 7 dead private methods in worker/processor.rs
- Remove backup directory from git tracking
2026-05-04 01:31:21 +08:00

46 lines
1.3 KiB
Python

#!/opt/homebrew/bin/python3.11
"""
Draw Detection Result on Image
"""
import cv2
import os
UUID = "384b0ff44aaaa1f1"
OUTPUT_DIR = f"output/{UUID}/florence2_results"
INPUT_IMG = os.path.join(OUTPUT_DIR, "raw_6846.jpg")
OUTPUT_IMG = os.path.join(OUTPUT_DIR, "raw_6846_detected.jpg")
# Florence-2 Result from previous run: [x_min, y_min, x_max, y_max]
# Note: Florence-2 usually returns coordinates in normalized 0-1000 scale.
box_raw = [1721.28, 23.22, 1813.44, 173.34]
# Image dimensions
img_width, img_height = 1920, 1080
print(f"🎨 Drawing box on {INPUT_IMG}...")
img = cv2.imread(INPUT_IMG)
if img is None:
print("❌ Failed to load image.")
exit()
# Convert normalized coordinates to pixel coordinates
# Florence-2 uses 1000x1000 normalized coordinates
x1 = int((box_raw[0] / 1000.0) * img_width)
y1 = int((box_raw[1] / 1000.0) * img_height)
x2 = int((box_raw[2] / 1000.0) * img_width)
y2 = int((box_raw[3] / 1000.0) * img_height)
print(f"📍 Pixel Coordinates: ({x1}, {y1}) to ({x2}, {y2})")
# Draw Rectangle (Color: Green, Thickness: 4)
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 4)
# Add Label
cv2.putText(img, "STAMP", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
# Save
cv2.imwrite(OUTPUT_IMG, img)
print(f"✅ Saved result to {OUTPUT_IMG}")