Spaces:
Running
Running
File size: 3,693 Bytes
8a74c03 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
#!/usr/bin/env python3
"""
Test the simplified Person on Track Detector output
"""
import sys
import os
from io import BytesIO
# Add current directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_simplified_output():
"""Test the simplified output format"""
print("TESTING SIMPLIFIED PERSON ON TRACK DETECTOR OUTPUT")
print("=" * 60)
print("Now shows only: Analysis + People Count + Confidence")
print()
try:
from local_models import get_local_model_manager
from app import extract_frames_from_video, process_image_locally
print("+ Components loaded")
except ImportError as e:
print(f"- Import error: {e}")
return
# Test with first video
video_path = "test\\1.mp4"
if not os.path.exists(video_path):
print(f"- Video not found: {video_path}")
return
print(f"+ Testing with: {video_path}")
try:
local_manager = get_local_model_manager()
print("+ Person on Track Detector ready")
except Exception as e:
print(f"- Model error: {e}")
return
# Extract one frame for testing
try:
with open(video_path, 'rb') as f:
video_data = f.read()
video_file = BytesIO(video_data)
frames = extract_frames_from_video(video_file, fps=0.5)
if not frames:
print("- No frames extracted")
return
frame_data = frames[0]
print(f"+ Testing frame at {frame_data['timestamp']:.1f}s")
except Exception as e:
print(f"- Frame extraction error: {e}")
return
# Test the simplified detector
try:
result = process_image_locally(
frame_data['frame'],
"Track Safety Analysis",
'Person on Track Detector',
local_manager
)
if 'person_on_track_detection' in result:
detection = result['person_on_track_detection']
print(f"\n" + "=" * 50)
print("SIMPLIFIED OUTPUT")
print("=" * 50)
# Show the three key pieces of information
analysis = detection.get('analysis', 'No analysis')
people_count = detection.get('people_count', 0)
confidence = detection.get('confidence', 0)
person_on_track = detection.get('person_on_track', False)
# Display like in Streamlit
if person_on_track:
print(f"π¨ ALERT: {analysis}")
else:
print(f"β
SAFE: {analysis}")
print(f"π₯ People on Track: {people_count}")
print(f"π Confidence: {confidence:.0%}")
print(f"\n" + "=" * 50)
print("SUCCESS - CLEAN, SIMPLE OUTPUT!")
print("=" * 50)
print("The detector now shows only the essential information:")
print(f"1. Clear analysis message: '{analysis}'")
print(f"2. Number of people on track: {people_count}")
print(f"3. Confidence level: {confidence:.0%}")
print("4. Color-coded status (red for danger, green for safe)")
else:
print(f"ERROR: Unexpected result format")
except Exception as e:
print(f"ERROR: {e}")
print(f"\n" + "=" * 60)
print("READY TO USE!")
print("=" * 60)
print("Open http://localhost:8502")
print("Select 'Person on Track Detector'")
print("Upload test videos to see the simplified output")
if __name__ == "__main__":
test_simplified_output() |