A comprehensive Python-based surveillance and monitoring application that combines YOLOv8 object detection with advanced features like zone monitoring, object tracking, image enhancement, and real-time analytics.
- YOLOv8 Integration: Pre-trained COCO model for general object detection
- Multi-format Support: Images, video files, and live webcam feeds
- Real-time Processing: Optimized for live video streams
- Custom Model Support: Use your own trained YOLO models
- Real-time Counting: Count objects by class per frame
- DeepSORT Tracking: Assign unique IDs and track objects across frames
- Movement Analysis: Detect stationary, slow-moving, and fast-moving objects
- Loitering Detection: Identify objects staying in one area
- Restricted Areas: Define rectangular or polygonal restricted zones
- Real-time Alerts: Instant notifications when objects enter restricted areas
- Interactive Zone Selection: Draw zones directly on video feed
- Sound & Visual Alerts: Audio and visual notification system
- Low-light Enhancement: CLAHE and gamma correction for dark conditions
- Noise Reduction: Advanced denoising algorithms
- Adaptive Enhancement: Automatically adjust parameters based on image content
- Real-time Processing: Enhance video frames on-the-fly
- Streamlit Dashboard: Modern web interface for monitoring
- Real-time Statistics: Live object counts and detection metrics
- Historical Analytics: Time-series analysis and trend visualization
- Export Capabilities: CSV, JSON, and Excel report generation
- Comprehensive Logging: Detailed detection logs with timestamps
- Activity Tracking: System events and zone violations
- Data Export: Multiple format support for analysis
- Performance Metrics: FPS, processing time, and accuracy statistics
-
Clone the repository
git clone <repository-url> cd object-monitoring-system
-
Install dependencies
pip install -r requirements.txt
-
Run the Streamlit dashboard
python run_streamlit.py
-
Or run basic detection
python examples/basic_detection.py
- Python: 3.8 or higher
- RAM: 4GB minimum, 8GB recommended
- GPU: Optional but recommended for real-time processing
- Camera: USB webcam or built-in camera for live monitoring
object-monitoring-system/
├── config.py # Configuration settings
├── object_detector.py # Core YOLOv8 detection
├── zone_monitor.py # Zone monitoring and alerts
├── object_tracker.py # DeepSORT tracking
├── image_enhancer.py # Image enhancement algorithms
├── monitoring_system.py # Main system integration
├── logger.py # Logging and data export
├── streamlit_app.py # Web dashboard
├── run_streamlit.py # Dashboard launcher
├── requirements.txt # Dependencies
├── README.md # This file
├── examples/ # Example scripts
│ ├── basic_detection.py
│ ├── webcam_monitoring.py
│ ├── video_processing.py
│ ├── image_enhancement_demo.py
│ └── zone_monitoring_demo.py
├── output/ # Generated outputs
├── logs/ # Log files
└── models/ # Model files
from object_detector import ObjectDetector
import cv2
# Initialize detector
detector = ObjectDetector()
# Load image
image = cv2.imread("sample.jpg")
# Detect objects
detections, annotated_image = detector.detect_objects(image)
# Count objects
counts = detector.count_objects(detections)
print(f"Detected objects: {counts}")
# Save result
cv2.imwrite("result.jpg", annotated_image)from monitoring_system import MonitoringSystem
# Initialize system
system = MonitoringSystem(
enable_tracking=True,
enable_enhancement=True,
enable_logging=True
)
# Add restricted zones
system.add_restricted_zone('rectangle', [(100, 100), (300, 200)], "Restricted Area")
system.add_restricted_zone('polygon', [(400, 100), (500, 150), (450, 250)], "Parking Zone")
# Start monitoring
system.monitor_webcam(camera_index=0)from monitoring_system import MonitoringSystem
# Initialize system
system = MonitoringSystem()
# Process video file
system.monitor_video("input_video.mp4", "output_video.mp4")
# Get statistics
stats = system.get_system_statistics()
print(f"Processed {stats['frame_count']} frames")
print(f"Found {stats['total_detections']} objects")from image_enhancer import ImageEnhancer
import cv2
# Initialize enhancer
enhancer = ImageEnhancer()
# Load low-light image
image = cv2.imread("dark_image.jpg")
# Enhance image
enhanced = enhancer.enhance_image(image, 'low_light')
# Save enhanced image
cv2.imwrite("enhanced_image.jpg", enhanced)# In config.py
MODEL_PATH = "yolov8n.pt" # Model file
CONFIDENCE_THRESHOLD = 0.5 # Detection confidence
IOU_THRESHOLD = 0.45 # Intersection over Union
MAX_DETECTIONS = 1000 # Maximum detections per frame# Zone settings
RESTRICTED_ZONE_COLOR = (0, 0, 255) # Red color for zones
ALERT_COOLDOWN = 2.0 # Seconds between alerts
MONITORED_CLASSES = ['person', 'car', 'truck'] # Classes to monitor# Image enhancement
DENOISE_STRENGTH = 10 # Noise reduction strength
CLAHE_CLIP_LIMIT = 2.0 # Contrast enhancement
GAMMA_CORRECTION = 1.2 # Brightness adjustment- Real-time camera feed
- Object detection visualization
- Zone violation alerts
- Live statistics display
- Image and video processing
- Batch processing capabilities
- Download processed results
- Detection analysis
- Historical data visualization
- Object class distribution
- Time-series analysis
- Performance metrics
- Zone violation history
- System activity logs
- Data export options
- Log management
- Model configuration
- Enhancement parameters
- Tracking settings
- Zone monitoring options
- Prepare dataset in YOLO format
- Train model using Ultralytics
- Update config.py with model path
- Set custom_model=True in ObjectDetector
# Define custom polygon zones
custom_points = [(x1, y1), (x2, y2), (x3, y3), ...]
system.add_restricted_zone('polygon', custom_points, "Custom Zone")# Custom alert handler
def custom_alert_handler(violation):
# Send email, SMS, or API call
send_notification(violation)
# Override default alert method
system.zone_monitor._trigger_alert = custom_alert_handler- Install CUDA-compatible PyTorch
- Set device to 'cuda' in config
- Use larger YOLO models for better accuracy
- Adjust batch sizes for video processing
- Use smaller models for real-time applications
- Enable frame skipping for long videos
- Reduce input resolution for faster processing
- Use YOLOv8n for maximum speed
- Disable unnecessary features for speed
-
Camera not detected
- Check camera permissions
- Try different camera indices (0, 1, 2)
- Verify camera is not used by other applications
-
Low detection accuracy
- Increase confidence threshold
- Use larger YOLO model
- Enable image enhancement
-
Performance issues
- Reduce input resolution
- Use GPU acceleration
- Disable tracking for faster processing
-
Zone alerts not working
- Check zone coordinates
- Verify monitored classes
- Check alert cooldown settings
- "Error loading model": Check model file path and format
- "Camera not accessible": Verify camera permissions and availability
- "Out of memory": Reduce batch size or input resolution
detector = ObjectDetector(model_path, custom_model=False)
detections, annotated_image = detector.detect_objects(image)
counts = detector.count_objects(detections)monitor = ZoneMonitor()
monitor.add_rectangular_zone(x1, y1, x2, y2, name)
violations = monitor.check_zone_violations(detections)tracker = ObjectTracker()
tracked_objects = tracker.update_tracks(detections, frame)enhancer = ImageEnhancer()
enhanced_image = enhancer.enhance_image(image, 'auto')- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Ultralytics for YOLOv8
- DeepSORT for object tracking
- OpenCV for computer vision
- Streamlit for the web dashboard
For questions, issues, or contributions:
- Create an issue on GitHub
- Check the documentation
- Review example scripts
Made with ❤️ for the computer vision community