We've integrated your person-tracking sentry system directly into FastAPI with Option B - the complete, production-ready solution!
FastAPI Server (port 5000)
|
+-- Sentry Service (background thread)
| +-- OpenCV camera capture
| +-- YOLO person detection
| +-- DeepSORT tracking
| +-- Servo control
| └-- Frame annotation (bounding boxes, crosshairs, stats)
|
+-- /video_feed endpoint
| └-- MJPEG streaming of annotated frames
|
+-- /control endpoint
| └-- Send commands to sentry (pan, tilt, lock, center)
|
└-- /sentry/stats endpoint
└-- Get real-time stats (FPS, tracking status, servo angles)
Single Camera Source - No conflicts, one system
Real-time MJPEG Streaming - Works with HTML <img> tags
Full Annotations - See tracking boxes, crosshairs, stats overlaid
Remote Control - Frontend buttons directly control servos
Background Processing - Runs as a thread, doesn't block API
Graceful Degradation - Shows placeholder if sentry unavailable
./start_all.shTerminal 1 - Backend (includes sentry):
./start_backend.shTerminal 2 - Frontend:
./start_frontend.shNOTE: You do NOT need to run start_sentry.sh anymore - the sentry is now integrated into the backend!
- Refactored
PersonTrackingSentryinto a reusable service - Runs as background thread instead of standalone script
- No
cv2.imshow()- designed for headless operation - Command queue for external control
- Thread-safe frame access
- Imports
SentryService - Starts sentry on FastAPI startup
- Stops sentry on shutdown
- MJPEG streaming via
generate_frames()generator /controlendpoint now sends commands to sentry- New
/sentry/statsendpoint for real-time data
VideoFeed.jsxpoints to/video_feedCameraControls.jsxsends commands to/control- No changes needed!
MJPEG stream of annotated camera frames.
Usage:
<img src="http://localhost:5000/video_feed" alt="Camera Feed" />Response: Multipart MJPEG stream Frame Rate: ~30 FPS Annotations: Bounding boxes, tracking IDs, crosshair, FPS, servo angles
Send control commands to the sentry.
Request:
{
"command": "toggle_lock"
}Commands:
toggle_lock- Enable/disable auto-trackingcenter- Reset camera to center positionpan_left- Pan 5° leftpan_right- Pan 5° righttilt_up- Tilt 5° uptilt_down- Tilt 5° down
Response:
{
"status": "success",
"command": "toggle_lock"
}Get real-time sentry statistics.
Response:
{
"fps": 28.5,
"tracking_status": "LOCKED ID:1",
"pan_angle": 95.2,
"tilt_angle": 88.7,
"people_count": 1
}Open in browser: http://localhost:5000/video_feed
You should see:
- Live camera feed
- Green bounding box around tracked person (if locked)
- Blue boxes around other people
- Red crosshair in center
- FPS, servo angles, tracking status overlays
Open: http://localhost:5173
You should see:
- Video feed in top-left panel
- Camera controls in bottom-left panel
- Anomaly log on right side
Click the camera control buttons:
- Pan left/right - camera should move
- Tilt up/down - camera should move
- Center - camera returns to default position
- Lock toggle - enables/disables auto-tracking
Cause: Missing dependencies (YOLO, OpenCV, servos) Solution:
- On Jetson: All dependencies should be available
- On Mac/PC: Sentry runs in simulation mode (no actual servos, but streaming works)
Cause: Camera already in use or wrong index Solution:
- Check
CAMERA_INDEX = 0insentry/sentry_service.py - Make sure no other process is using the camera
Cause: Sentry failed to initialize Solution: Check backend logs for errors
Cause: Sentry not running or in simulation mode Solution:
- Check backend logs
- On non-Jetson systems, servos won't move but commands are logged
Production Ready - Single integrated system Scalable - Easy to add more features Maintainable - One codebase, not two separate scripts Remote Access - Control camera from anywhere on your network Real-time - Low latency streaming Annotated - See exactly what the AI sees
- Add WebRTC for even lower latency (more complex)
- Add recording - save video clips of anomalies
- Add PTZ presets - save favorite camera positions
- Add zones - define restricted areas
- Add notifications - push alerts when tracking locks
- The old
person_tracking_sentry.pystill exists for standalone use - The new
sentry_service.pyis the integrated version - Frontend automatically handles both connected and disconnected states
- MJPEG works in all modern browsers with
<img>tags - No JavaScript media APIs needed!
Happy tracking! 🎥📹