A production-ready real-time object detection and tracking system built with Python, YOLOv8, and OpenCV. The system provides advanced motion analysis, object interaction tracking, and comprehensive visualization features.
trainit/
│
├── src/ # Source code
│ ├── core/ # Core functionality
│ │ ├── detector.py # YOLOv8 detector
│ │ ├── tracker.py # ByteTrack tracker
│ │ └── camera.py # Camera handling
│ │
│ ├── analysis/ # Analysis modules
│ │ ├── motion.py # Motion analysis
│ │ ├── interaction.py # Object interaction
│ │ └── patterns.py # Pattern recognition
│ │
│ └── visualization/ # Visualization modules
│ ├── display.py # Main display handling
│ ├── heatmap.py # Heatmap generation
│ └── annotator.py # Frame annotation
│
├── configs/ # Configuration files
│ ├── default.yaml # Default settings
│ └── advanced.yaml # Advanced settings
│
├── data/ # Data directory
│ ├── models/ # Model weights
│ └── output/ # Output files
│
├── tests/ # Test files
│ ├── unit/ # Unit tests
│ └── integration/ # Integration tests
│
├── utils/ # Utility functions
│ ├── logger.py # Logging setup
│ └── helpers.py # Helper functions
│
├── scripts/ # Scripts
│ ├── install.sh # Installation script
│ └── download_weights.sh # Model download
│
├── docs/ # Documentation
│ ├── api/ # API documentation
│ ├── guides/ # User guides
│ └── examples/ # Code examples
│
├── requirements.txt # Project dependencies
├── setup.py # Package setup
└── README.md # Project documentation
-
System Requirements:
- Python 3.8 or higher
- CUDA-capable GPU (recommended)
- Webcam with 720p or higher resolution
- 8GB RAM minimum (16GB recommended)
-
Directory Structure:
src/: Core implementation filesdata/: Model weights and output storageconfigs/: Configuration filestests/: Test suitesutils/: Helper utilitiesscripts/: Installation and setup scripts
-
Development Tools:
- VS Code/PyCharm for development
- Git for version control
- pytest for testing
- black for code formatting
- mypy for type checking
-
COCO Dataset:
- 80+ object classes
- Over 200K labeled images
- Instance segmentation
- Used for YOLOv8 training
-
Model Weights:
- YOLOv8n.pt (default)
- YOLOv8s.pt (small)
- YOLOv8m.pt (medium)
- YOLOv8l.pt (large)
- YOLOv8x.pt (xlarge)
-
Runtime Data:
- Real-time webcam feed
- Video file input support
- Analytics data in JSON format
- Performance metrics logs
-
Computer Vision:
- OpenCV 4.8.0+
- YOLOv8 by Ultralytics
- ByteTrack for object tracking
- NumPy for numerical operations
-
Deep Learning:
- PyTorch 2.0+
- CUDA for GPU acceleration
- TorchVision for image processing
- Supervision for detection utils
-
Data Processing:
- Pandas for analytics
- Matplotlib for plotting
- SciPy for scientific computing
- PyYAML for configuration
-
Development Tools:
- pytest for testing
- black for formatting
- mypy for type checking
- logging for debug info
-
Starting the System:
# Activate environment source venv/bin/activate # Linux/Mac venv\Scripts\activate # Windows # Run application python -m src.main
-
Operation Modes:
# Normal mode python -m src.main --mode normal # Video recording python -m src.main --mode save_video # Analytics collection python -m src.main --mode analytics # Advanced features python -m src.main --mode advanced
-
Configuration Options:
# Use custom config python -m src.main --config configs/custom.yaml # Override settings python -m src.main --confidence 0.6 --device cuda
-
Custom Analysis:
# Enable specific features python -m src.main --enable-heatmap --enable-tracking # Set analysis parameters python -m src.main --trajectory-length 50 --prediction-horizon 1.0
-
Output Options:
# Specify output directory python -m src.main --output-dir /path/to/output # Set video format python -m src.main --video-format mp4 --video-fps 30
-
Performance Tuning:
# Adjust thread count python -m src.main --num-threads 4 # Set GPU memory fraction python -m src.main --gpu-memory-fraction 0.8
- Real-time object detection using YOLOv8
- Advanced object tracking with ByteTrack
- Motion prediction and pattern analysis
- Object interaction detection and visualization
- Dynamic heatmap generation
- Multi-threaded processing for optimal performance
- 8-directional motion prediction
- Real-time velocity and acceleration analysis
- Interaction matrix and proximity detection
- Gradient-colored trajectory visualization
- Performance monitoring and analytics
- Multiple operation modes (Normal, Save Video, Analytics, Advanced)
- Clone the repository:
git clone https://github.com/sahoo-tech/Object-tracking-and-detection.git
cd Object-tracking-and-detection- Run the installation script:
# Linux/Mac
./scripts/install.sh
# Windows
scripts\install.bat- Start the application:
python -m src.mainThe system can be configured through YAML files in the configs/ directory:
# configs/default.yaml
detector:
model: yolov8n
confidence: 0.5
device: cuda
tracker:
max_age: 30
min_hits: 3
iou_threshold: 0.3
visualization:
trajectory_length: 30
heatmap_alpha: 0.3- Create a virtual environment:
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows- Install development dependencies:
pip install -r requirements-dev.txt- Run tests:
pytest tests/- Follow PEP 8 guidelines
- Use type hints
- Write docstrings in Google format
- Keep functions focused and small
- YOLOv8 by Ultralytics
- ByteTrack implementation
- OpenCV community
- PyTorch framework
Your Name - [@SayantanSahoo] Project Link: (https://github.com/sahoo-tech/Object-tracking-and-detection.git)