Siddharthk1/Drone-Detection-Tracking
๐ Drone Tracking Web Application
A full-stack real-time drone detection and tracking system built with FastAPI backend and React frontend.
Features
- Real-time Video Feed: Live camera stream with drone detection overlay
- YOLO + DeepSORT Integration: Advanced object detection and tracking
- Real-time Notifications: WebSocket-based instant alerts for new detections
- Interactive Dashboard: Modern React UI with Material-UI components
- Detection Database: SQLite storage for all detection records
- Interactive Map: Leaflet map showing drone detection locations
- Statistics Tracking: Daily detection counts and analytics
System Requirements
- Python 3.8+
- Node.js 16+
- Camera/Webcam
- YOLO model file (
best.pt)
Quick Start
1. Clone and Setup Backend
# Navigate to backend directory
cd backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt2. Add Your YOLO Model
Place your trained YOLO model file (best.pt) in the backend directory, or update the MODEL_PATH in main.py:
MODEL_PATH = "path/to/your/model.pt"3. Start Backend Server
# Start FastAPI server
uvicorn main:app --reload --host 0.0.0.0 --port 8000The backend will be available at: http://localhost:8000
4. Setup Frontend
# Navigate to frontend directory
cd ../frontend
# Install dependencies
npm install
# Start development server
npm run devThe frontend will be available at: http://localhost:3000
Usage
- Start the Application: Open
http://localhost:3000in your browser - Start Camera: Click the "Start Camera" button to begin detection
- View Live Feed: Watch the real-time video with detection overlays
- Monitor Detections: See new drone alerts and view detection statistics
- Check Map: View detection locations on the interactive map
- Review Data: Browse today's detections in the data table
API Endpoints
Camera Control
POST /camera/start- Start camera trackingPOST /camera/stop- Stop camera trackingGET /camera/status- Get camera status
Detections
GET /detections/today- Get today's detectionsGET /detections/- Get all detections (with pagination)GET /detections/date/{date}- Get detections for specific dateDELETE /detections/{id}- Delete detection
Real-time
GET /video- Video stream endpointWebSocket /ws- Real-time updates
System
GET /health- Health checkGET /- API documentation
Project Structure
drone-tracking/
โโโ backend/
โ โโโ main.py # FastAPI application
โ โโโ tracker.py # DroneTracker class
โ โโโ models.py # Database models
โ โโโ database.py # Database configuration
โ โโโ requirements.txt # Python dependencies
โ โโโ static/
โ โโโ index.html # Backend test page
โโโ frontend/
โโโ src/
โ โโโ components/ # React components
โ โโโ hooks/ # Custom hooks
โ โโโ services/ # API services
โ โโโ utils/ # Utilities
โ โโโ App.jsx # Main app component
โ โโโ main.jsx # React entry point
โโโ package.json # Node dependencies
โโโ vite.config.js # Vite configurationDeploying to Hugging Face Spaces
This repo is set up for a Docker Space (sdk: docker in the README header). Typical failures were:
- Docker build error โ
libgl1-mesa-glxis not available on current Debian images. TheDockerfileuseslibgl1and related runtime libraries instead. - Runtime: no weights โ
backend/best.ptis not in the repository (often too large for Git). Use one of: - Space / container variables (Settings โ Variables and secrets):
HF_MODEL_REPOโ Hugging Face model repo id, e.g.your-username/your-drone-yoloHF_MODEL_FILEโ optional, defaults tobest.ptHF_TOKENโ only if the model repo is private or gated- Or `MODEL_PATH` โ absolute path to a weights file inside the container if you bake it into the image.
- Or add
best.ptunderbackend/and ensure it is included in what you push to the Space.
GitHub โ Hugging Face sync (optional)
If you use `.github/workflows/sync-to-hub.yml`, add repository secrets (Settings โ Secrets and variables โ Actions). Do not paste line breaks inside secret values (a trailing Enter is a common cause of Repo id must use alphanumeric chars errors).
Recommended (one id):
HF_TOKENโ Hugging Face token with write accessHF_SPACE_REPO_IDโ exactlyYourUsername/YourSpaceName(same as inhttps://huggingface.co/spaces/YourUsername/YourSpaceName)
Alternative (two parts):
HF_TOKENHF_USERNAMEโ namespace only (e.g.SIDDk1)SPACE_NAMEโ Space slug only (e.g.Drone-Detection-Tracking), no slash
Create the Space on Hugging Face first (Docker). After a successful sync, the Space rebuilds from the uploaded files.
Configuration
Backend Configuration
Edit backend/main.py to configure:
- Model path:
MODEL_PATH = "your-model.pt" - Confidence threshold:
confidence_threshold=0.5 - Database URL: Set
DATABASE_URLenvironment variable
Frontend Configuration
Edit frontend/src/utils/constants.js to configure:
- API base URL
- WebSocket URL
- Map settings
- Notification settings
Troubleshooting
Common Issues
Camera not working:
- Check camera permissions
- Verify camera is not in use by another application
- Try different camera index in
tracker.py
Model not found:
- Ensure
best.ptfile exists in backend directory - Check file permissions
- Verify model format is compatible
Connection issues:
- Check if backend is running on port 8000
- Verify frontend proxy configuration in
vite.config.js - Check firewall settings
WebSocket connection failed:
- Ensure both frontend and backend are running
- Check browser console for connection errors
- Verify WebSocket URL in constants
Performance Tips
- Reduce video resolution in
tracker.pyfor better performance - Adjust confidence threshold to reduce false positives
- Limit frame rate for lower CPU usage
- Use GPU acceleration if available with CUDA
Development
Adding New Features
- Backend: Add new endpoints in
main.py - Frontend: Create new components in
src/components/ - Database: Update models in
models.py - Real-time: Extend WebSocket handlers
Testing
# Backend tests
cd backend
python -m pytest
# Frontend tests
cd frontend
npm testBuilding for Production
# Build frontend
cd frontend
npm run build
# Deploy backend
cd backend
pip install gunicorn
gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorkerLicense
This project is licensed under the MIT License.
Contributing
- Fork the repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
Support
For issues and questions:
- Check the troubleshooting section
- Review API documentation at
http://localhost:8000/docs - Create an issue on GitHub
Note: Make sure to replace best.pt with your actual YOLO model file trained for drone detection.
