What You’ll Learn
- Building custom video processors
- Real-time face detection and recognition
- Object tracking across frames
- Event-driven workflows with async tasks
- Video overlay composition
- Creating visual outputs (wanted posters)
- Integrating with external APIs (X/Twitter)
Features
- Real-time Face Detection: Uses the
face_recognitionlibrary for accurate detection - Face Recognition: Match faces against known individuals
- Named Face Registration: Users can say “remember me as [name]”
- Package Detection: YOLOv11-based detection for packages and boxes
- Package Theft Detection: Identifies suspects when packages disappear
- Wanted Poster Generation: Automatically creates posters for package thieves
- X Integration: Posts wanted posters to Twitter/X automatically
- Visual Overlay: Shows visitor count, package count, and thumbnail grid
- Activity Log: Tracks arrivals, departures, and package events
- LLM Integration: Ask questions like “What happened while I was away?”
Architecture
The system uses a customSecurityCameraProcessor that:
- Subscribes to the video stream via
VideoForwarder - Runs face detection at configurable intervals
- Runs YOLO model to detect packages
- Matches faces against known faces to identify individuals
- Tracks visitors and packages with timestamps
- Detects theft when packages disappear while someone is present
- Creates video overlay with thumbnails and statistics
- Publishes annotated video via
QueuedVideoTrack
Prerequisites
You’ll need:- Python 3.13+
- Webcam/camera access
- Stream account for video transport
- Gemini API key
- Deepgram API key for STT
- ElevenLabs API key for TTS
- (Optional) X Developer API credentials for posting posters
- YOLO Model: You need to provide your own
weights_custom.ptfile (see below)
Setup
Provide a YOLO model
This example requires a custom YOLOv11 model trained to detect packages. We don’t distribute the model, so you need to provide your own.Options:
- Train your own: Use Roboflow to label a dataset and train a YOLOv11 model (training guide)
- Find a pre-trained model: Search Roboflow Universe for “package detection” datasets
weights_custom.pt in the example directory, or update the model_path parameter in the code.Complete Code
Here’s the main example code:Key Features Explained
Face Detection and Recognition
Uses the face_recognition library (built on dlib):- Provides state-of-the-art accuracy
- Generates 128-dimensional face encodings
- Can identify the same person across different angles and lighting
- Supports named face registration
Package Theft Workflow
When a package disappears:- System identifies who was present when the package disappeared
- Waits 3 seconds to confirm the package is truly gone (not a detection blip)
- Generates a “WANTED” poster with the suspect’s face
- Displays the poster in the video call for 8 seconds
- Posts the poster to X with a caption
- Agent announces the theft
Video Overlay
The right side of the video shows:- Header: “SECURITY CAMERA”
- Visitor Count: Currently visible / total unique visitors
- Package Count: Currently visible / total packages seen
- Legend: Color coding for people (green) and packages (blue)
- Thumbnail Grid: Up to 12 most recent faces and packages
- Detection Badges: Show how many times each person/package was seen
- Timestamp: Current date and time
LLM Functions
The agent has access to several functions:Interacting with the AI
Once connected, you can say:- “How many people have visited?”
- “What happened while I was away?”
- “Did anyone come by?”
- “Have any packages been delivered?”
- “Who picked up the package?”
- “Remember me as John”
- “Who do you know?”
Package Theft Demo
To trigger the theft workflow:- Place a package (box, parcel) in view of the camera
- Wait for it to be detected (blue bounding box appears)
- Have someone pick up the package while their face is visible
- The system will:
- Detect the package disappearance
- Wait 3 seconds to confirm
- Generate a wanted poster
- Display it in the video
- Post it to X (if configured)
Configuration Options
Event System
The processor emits events that you can subscribe to:About the Custom YOLO Model
Theweights_custom.pt file is a YOLOv11 model trained to detect:
- Box
- Box_broken
- Open_package
- Package
Next Steps
- Try the Football Commentator Example for event-driven detection
- Explore the Golf Coach Example for pose detection
- Read the Processors Guide for building custom processors
- Learn about Event Systems for event-driven architectures