Repository navigation
Expand file tree
/
Copy pathtrigger_detection.py
More file actions
61 lines (52 loc) · 2.16 KB
/
Copy pathtrigger_detection.py
File metadata and controls
61 lines (52 loc) · 2.16 KB
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
#!/usr/bin/env python3
"""Trigger person detection in the bridge to test audio playback."""
import requests
import json
import time
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s [%(levelname)s] %(message)s')
logger = logging.getLogger(__name__)
BRIDGE_URL = "http://localhost:8081"
def trigger_victim_detection():
"""Send a command to trigger victim detection."""
logger.info("Triggering victim detection...")
try:
# Try to fetch camera feed to keep the bridge active
resp = requests.get(f"{BRIDGE_URL}/camera.mjpeg", timeout=2)
logger.info("Camera stream status: %s", resp.status_code)
except Exception as e:
logger.debug("Camera stream check: %s", e)
# The detector runs automatically on camera frames, but let's wait
# and check the status to see if anything was detected
for i in range(20):
try:
resp = requests.get(f"{BRIDGE_URL}/status", timeout=2)
if resp.status_code == 200:
status = resp.json()
logger.info("Bridge status: victims=%d, active_survivors=%s",
len(status.get('victims', [])),
status.get('survivor_active'))
if status.get('survivor_active'):
logger.info("✓ Survivor interaction active!")
return True
except Exception as e:
logger.debug("Status check failed: %s", e)
logger.info("Waiting for person detection... (%d/20)", i+1)
time.sleep(1)
logger.warning("No person detected after 20 seconds")
return False
if __name__ == "__main__":
logger.info("Connecting to bridge at %s", BRIDGE_URL)
trigger_victim_detection()
logger.info("\nWaiting for interaction to complete...")
for i in range(30):
try:
resp = requests.get(f"{BRIDGE_URL}/status", timeout=2)
if resp.status_code == 200:
status = resp.json()
if not status.get('survivor_active'):
logger.info("Interaction complete")
break
except:
pass
time.sleep(1)