A computer vision-based intrusion detection system that uses YOLOv11 object detection and implements zone-based alerting for security monitoring.
- Region of Interest (ROI) Detection: Optimized object detection that only processes within user-defined zones
- Multiple Detection Methods: YOLOv11 object detection with motion detection fallback
- Real-time Tracking: Tracks objects across video frames with unique IDs
- Zone-based Intrusion Alerts: Define restricted zones and get alerts when objects enter
- Logging & Reporting: CSV and YAML logging of intrusion events with timestamps
- Automatic Screenshots: Captures images when intrusions are detected
- Interactive UI: Real-time visualization with status information
motion_detection/
├── detect.py # Main entry point
├── requirements.txt # Project dependencies
├── lib/ # Module library
│ ├── core/ # Core functionality
│ │ ├── intrusion_detector.py
│ │ └── zone_manager.py
│ ├── detectors/ # Detection algorithms
│ │ ├── yolo_detector.py
│ │ └── motion_detector.py
│ ├── trackers/ # Object tracking
│ │ └── simple_tracker.py
│ ├── ui/ # Visualization
│ │ └── visualizer.py
│ └── utils/ # Utilities
│ ├── config.py
│ └── logger.py
├── models/ # YOLO model files
├── logs/ # Application logs
└── intrusions/ # Saved intrusion images
-
Clone the repository
git clone [email protected]:zg0ul/motion-detection.git cd motion-detection
-
Set up a Python virtual environment (recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
Main dependencies include:
- OpenCV (cv2)
- Ultralytics (YOLO)
- NumPy
- Shapely (for polygon operations)
- PyYAML (for configuration)
Run the detector with default settings (using webcam):
python detect.py
python detect.py --source <VIDEO_SOURCE> --config <CONFIG_PATH> --model <MODEL_PATH>
--source
: Video source (0 for webcam, or path to video file)--config
: Path to configuration file (optional)--model
: Path to YOLOv11 model file (default: models/yolo11n.pt)
During operation, the following keyboard controls are available:
q
orESC
: Quit the applicationd
: Toggle between YOLO detection and motion detectionr
: Reset background model (for motion detection)s
: Save current configuration to file
When you first run the application (or if no zone is defined):
- You'll enter zone definition mode
- Use left-clicks to place points defining your restricted zone
- Right-click to complete the zone definition
- Press
q
to save and continue
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request