A real-time web application for object detection and tracking using YOLOv8 and Deep SORT algorithms. This application streams live webcam feed with detected objects, bounding boxes, confidence scores, and unique tracking IDs.
- Real-time Object Detection: Uses YOLOv8 (You Only Look Once) for fast and accurate object detection
- Multi-Object Tracking: Implements Deep SORT algorithm to track multiple objects with unique IDs
- Live Video Streaming: MJPEG streaming directly to web browser
- Trajectory Visualization: Shows movement paths of tracked objects
- Web Interface: Clean, responsive web interface with real-time controls
- 80+ Object Classes: Supports all COCO dataset classes (person, car, bicycle, etc.)
- Performance Monitoring: Real-time statistics display
yolo-v8-live-tracker/
├── app.py # Flask web application server
├── detect_and_track.py # YOLOv8 + Deep SORT processing logic
├── requirements.txt # Python dependencies
├── README.md # This file
├── static/
│ └── style.css # CSS styling for web interface
└── templates/
├── index.html # Main web page template
├── 404.html # 404 error page
└── 500.html # 500 error page
- Python 3.8 or higher
- Webcam/Camera connected to your computer
- Windows/Linux/macOS
Download this project to your local machine or clone the repository.
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On Linux/macOS:
source venv/bin/activatepip install -r requirements.txtNote: The first time you run the application, YOLOv8 will automatically download the model weights (~6MB for YOLOv8n).
python app.pyNavigate to: http://localhost:5000
- Start the Application: Run
python app.py - Open Browser: Go to
http://localhost:5000 - Grant Camera Permission: Allow browser to access your webcam
- View Live Detection: See real-time object detection and tracking
- Control Interface: Use the web interface buttons to start/stop detection
- Start Detection: Initialize camera and begin object detection
- Stop Detection: Stop processing and release camera resources
- Refresh Status: Update connection and system status
You can modify camera settings in detect_and_track.py:
# Change camera index (0 for default, 1 for external camera, etc.)
detector.start_webcam(camera_index=0)
# Modify camera resolution and FPS
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
self.cap.set(cv2.CAP_PROP_FPS, 30)Adjust detection parameters in detect_and_track.py:
# Change YOLOv8 model (yolov8n.pt, yolov8s.pt, yolov8m.pt, yolov8l.pt, yolov8x.pt)
detector = ObjectDetectorTracker(model_name='yolov8n.pt', confidence_threshold=0.5)
# Modify Deep SORT parameters
self.tracker = DeepSort(
max_age=50, # Frames to keep alive track without detections
n_init=3, # Detections needed before track confirmation
nms_max_overlap=1.0, # Non-maxima suppression threshold
max_cosine_distance=0.4, # Cosine distance threshold for matching
)The application can detect and track 80 different object classes from the COCO dataset:
- People: person
- Vehicles: bicycle, car, motorcycle, airplane, bus, train, truck, boat
- Animals: bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe
- Objects: backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard, sports ball, kite, baseball bat, baseball glove, skateboard, surfboard, tennis racket
- Food & Kitchen: bottle, wine glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange, broccoli, carrot, hot dog, pizza, donut, cake
- Furniture: chair, couch, potted plant, bed, dining table, toilet
- Electronics: tv, laptop, mouse, remote, keyboard, cell phone, microwave, oven, toaster, sink, refrigerator
- Other: book, clock, vase, scissors, teddy bear, hair drier, toothbrush
- Color-coded: Each tracked object gets a unique color
- Labels: Show object class, confidence score, and track ID
- Real-time: Updated at 30 FPS for smooth tracking
- Movement Paths: Colored lines showing object movement history
- History Length: Last 30 positions are displayed
- Unique Colors: Each track has its own color for easy identification
- Object Count: Number of currently detected objects
- Active Tracks: Number of confirmed tracking targets
- Real-time Updates: Statistics update with each frame
Camera not working:
- Ensure no other applications are using the camera
- Try different camera indices (0, 1, 2, etc.)
- Check camera permissions in your operating system
Slow performance:
- Use a smaller YOLOv8 model (yolov8n.pt instead of yolov8x.pt)
- Reduce camera resolution in the code
- Close other resource-intensive applications
Module import errors:
- Ensure all dependencies are installed:
pip install -r requirements.txt - Check Python version compatibility (3.8+)
- Try reinstalling PyTorch:
pip install torch torchvision --force-reinstall
Web page not loading:
- Check if Flask server is running on port 5000
- Try accessing
http://127.0.0.1:5000instead - Check firewall settings
-
Model Selection: Use appropriate YOLOv8 model for your hardware
yolov8n.pt: Fastest, lowest accuracyyolov8s.pt: Balanced speed/accuracyyolov8m.pt: Better accuracy, sloweryolov8l.pt: High accuracy, slowyolov8x.pt: Best accuracy, slowest
-
Hardware Acceleration: If you have a CUDA-compatible GPU, PyTorch will automatically use it for faster inference.
-
Camera Resolution: Lower resolutions will process faster but may reduce detection accuracy.
- The application runs a web server accessible on your local network
- By default, it binds to
0.0.0.0:5000(all interfaces) - For production use, implement proper authentication and HTTPS
- Consider firewall rules if running on a shared network
- Flask Server (
app.py): Handles web requests, streaming, and API endpoints - Detection Engine (
detect_and_track.py): Processes video frames with YOLOv8 and Deep SORT - Threading: Separate threads for video processing and web serving
- MJPEG Streaming: Efficient video streaming to web browsers
- Flask: Web framework for the server
- Ultralytics: YOLOv8 implementation
- OpenCV: Computer vision and camera access
- Deep SORT: Multi-object tracking algorithm
- NumPy: Numerical computations
- PyTorch: Deep learning framework
- Frame Rate: ~30 FPS on modern hardware
- Latency: <100ms from camera to web display
- Memory Usage: ~500MB-1GB depending on model size
- CPU Usage: Moderate (can utilize GPU if available)
Feel free to submit issues, feature requests, or pull requests to improve this application.
This project is for educational and research purposes. Please respect the licenses of the underlying libraries (YOLOv8, Deep SORT, etc.).
- Ultralytics: For the excellent YOLOv8 implementation
- Deep SORT: For the multi-object tracking algorithm
- OpenCV: For computer vision capabilities
- Flask: For the web framework
Happy Object Tracking!