Building an Intelligent Event Detection System (Argus)
Developing an intelligent surveillance system using OpenCV, Python and Amazon Rekognition
Introduction
Argus began after I purchased a TP-Link Tapo C200 IP camera for home monitoring. While the camera included its own mobile application for live viewing, recording, and event notifications, many of its advanced surveillance features required a paid subscription.
Instead of relying on proprietary software, I saw an opportunity to build a fully customizable monitoring system tailored to my own needs. My objective was not only to replace the existing functionality, but also to create a solution that could easily support additional IP cameras in the future, regardless of the manufacturer.
The project started as a simple Python script capable of connecting to the camera through its RTSP stream using OpenCV. From there, I gradually added new capabilities, including motion detection, image capture, Amazon S3 integration, object recognition with Amazon Rekognition, a custom Pattern Engine for filtering relevant detections, and Amazon SNS notifications.
Although the current version runs as a local Python application, this is only the first stage of the project. The long-term goal is to evolve Argus into a cloud-native solution running on AWS, where event processing, automation, monitoring, and system management are fully orchestrated through cloud services. This incremental approach allows each feature to be validated independently while progressively transforming the project into a scalable and production-ready architecture.
Services Used
Languages
- Python
Computer Vision
- OpenCV
AWS
- Amazon S3
- Amazon Rekognition
- Amazon SNS
- IAM
SDK
- Boto3
Infrastructure
- Terraform
Architecture
Before implementing the application architecture, several proof-of-concept experiments were carried out to validate the feasibility of the project.
The first objective was to establish a reliable RTSP connection with the TP-Link Tapo C200 camera. Different connection methods and software tools were tested to verify stream accessibility, stability, latency, and image quality. Once a stable connection was achieved, small OpenCV prototypes were developed to continuously read frames from the camera and evaluate the stream performance.
Application settings are centralized in a dedicated ‘config.py’ file, making it easier to maintain thresholds, AWS resources, RTSP settings, and other configurable parameters without modifying the application logic.
Additional experiments focused on understanding how to efficiently capture frames, compare consecutive images, and identify movement without generating an excessive number of false positives. Several motion detection techniques were evaluated before selecting a combination of grayscale conversion, Gaussian Blur, thresholding, contour detection, and minimum area filtering.
Only after these initial validations proved successful was the application divided into independent modules, leading to the current pipeline-based architecture composed of motion detection, image capture, cloud integration, object recognition, pattern filtering, and notifications.
Challenges & Solutions
Automatic RTSP Reconnection:
Maintaining a stable connection to the IP camera was essential for continuous monitoring. An automatic reconnection mechanism was implemented to recover from temporary network interruptions without requiring manual intervention.
Reduced False Positives:
Simple frame comparisons generated unnecessary detections caused by lighting changes and image noise. This was mitigated using Gaussian Blur, thresholding, contour filtering, and minimum area validation.
Memory-Only Processing:
The initial implementation stored temporary image files locally before uploading them to Amazon S3. The application was later optimized to encode images directly in memory, eliminating unnecessary disk I/O and improving performance.
Dedicated Pattern Engine:
Amazon Rekognition returns a large number of detected labels, many of which are not relevant for the project. A dedicated Pattern Engine was developed to filter detections and process only meaningful objects, such as people or the robotic vacuum cleaner.
Centralized Configuration:
As the application evolved, configuration values became difficult to maintain. A centralized configuration module was introduced to manage thresholds, AWS resources, and application settings from a single location.
Centralized Logging:
Debugging with print() statements quickly became difficult as the project grew. The logging system was refactored to use Python’s logging module, providing structured and consistent application logs.
Modular Architecture:
To improve maintainability and scalability, the application was divided into independent modules, each responsible for a single task, including motion detection, image capture, AWS integration, pattern recognition, and notifications.
Project Results
The current implementation successfully provides:
- Stable RTSP video streaming from the IP camera.
- Real-time motion detection using OpenCV.
- Automatic image upload to Amazon S3.
- Object recognition through Amazon Rekognition.
- Intelligent filtering using a custom Pattern Engine.
- Email notifications using Amazon SNS.
- A modular and extensible architecture for future cloud migration.
Future Improvements
- Face recognition.
- Video recording.
- DynamoDB.
- CloudWatch.
References
- OpenCV Documentation
- Python Documentation
- Boto3 Documentation
- AWS Identity and Access Management (IAM)
- Amazon Rekognition Documentation
- DetectLabels API Reference
- Amazon S3 Documentation
- Amazon Simple Notification Service (SNS)
- Terraform AWS Provider
Project Code
You can find the Terraform code used in this project in the following GitHub directory.
