How anthony-faria-dos-santos/project-motion-detection-system works
Project Type & Purpose
• Full-stack Python “edge” application for 24/7 motion detection
• Uses OpenCV for image capture/processing, Slack for alerts, and Google Cloud Storage (GCS) for long-term storage
High-Level Architectural Components
a. Hardware/Input Layer
• Webcam (video feed)
b. Core Application Layer
• main.py – orchestrator
• Motion Detection module (OpenCV code inside main.py)
• Manager (handles interval & area threshold logic)
c. Utility/Integration Layer
• utils/slack_utils.py – Slack API wrapper
• utils/gcs_utils.py – GCS API wrapper
d. Local Storage
• captures/ directory (temporary local image storage)
e. External Services
• Slack API (chat.postMessage & files.upload endpoints)
• Google Cloud Storage (bucket for captured images)
f. Configuration & Environment
• .env (environment variables via python-dotenv)
• reload_venv.sh (ensures .env is loaded in virtualenv)
g. Test & Validation
• test_connections.py – verifies Slack & GCS connectivity
Interactions & Data Flow
1. Startup
– main.py loads .env → config object
2. Frame Capture
– main.py opens webcam (OpenCV VideoCapture)
– Streams frames into Motion Detection subroutine
3. Detection Logic
– Compute difference between frames → threshold + contour area
– If motion detected & capture interval elapsed:
a. Save frame locally → captures/<timestamp>.jpg
b. Call slack_utils.upload_image() → Slack channel
c. Call gcs_utils.upload_blob() → GCS bucket
4. Continuous Loop
– Repeat 2–3 until user quits (Q key)
5. Error Handling & Logging
– try/except around camera, API calls, upload tasks → console logs
Architectural Patterns & Principles
• Single-process, modular design
• Layered separation: Capture & Detection → Notification → Storage
• Utility modules isolate 3rd-party API logic (SRP)
• Environment-driven configuration (12-factor principle)