Threat Detection System

Machine Learning
Computer Vision
Systems
Threat Detection System

Tech Stack

Python
YOLOv6
OpenCV
MongoDB
Twilio
Raspberry Pi

Description

The Threat Detection System is a Python-based security application designed to perform real-time video surveillance and automated threat alerts. It integrates advanced computer vision with practical systems engineering to deliver reliable detection on resource-constrained hardware like the Raspberry Pi.

At its core, the system uses a custom-trained YOLOv6 model for object detection, wrapped inside an OpenCV-powered pipeline optimized for embedded environments. To reduce false positives, the detection service maintains a rolling 60-second video buffer, enabling temporal analysis and contextual decision-making rather than relying on isolated frames.

Performance optimization was a major focus. Techniques such as downscaling frames, converting to grayscale, and sampling every nth frame ensured the system could run effectively on the Pi without sacrificing detection accuracy. All detections and buffered video evidence are persisted in MongoDB for reliability and post-event analysis.

The architecture follows a microservice-like separation of concerns: a Detection Service processes live video streams and writes alerts, while a Notification Service asynchronously handles distribution of those alerts via email (with video attachments) and SMS using Twilio. This decoupling improves resilience and ensures detection is never blocked by notification overhead.

Error handling and recovery mechanisms are built in across both services, including exponential backoff for MongoDB reconnections and codec fallback chains for video writing inside Docker. The design emphasizes not only core computer vision but also distributed systems resilience, observability, and fault tolerance.

  • Implemented a custom-trained YOLOv6 object detection model integrated with OpenCV for real-time video analysis.
  • Engineered a rolling 60-second video buffer to contextualize detections and reduce false positives.
  • Optimized for Raspberry Pi by applying frame downscaling, grayscale conversion, and selective frame sampling.
  • Designed microservice architecture: Detection Service for analysis and Notification Service for email/SMS delivery.
  • Leveraged MongoDB for persistence of alerts, threat metadata, and evidence videos.
  • Built robust notification pipelines with SMTP for email and Twilio API for SMS alerts, including video attachments.
  • Implemented resilience features: MongoDB reconnection with exponential backoff and codec fallbacks for video writing in Dockerized environments.
  • Achieved reliable end-to-end threat detection and notification on constrained edge hardware, combining AI, systems engineering, and distributed design principles.