SanchitBahl/lane-pothole-detection
0
๐ Lane & Pothole Detection Web Application
A real-time computer vision application for detecting potholes and lane markings using YOLOv8n and OpenCV. Optimized for mobile browsers with WebRTC streaming and deployed on Hugging Face Spaces.
๐ฏ Features
- Real-Time Pothole Detection: YOLOv8n nano model optimized for edge inference
- Lane Tracking: Lightweight Canny edge + Hough line detection pipeline
- Mobile-First UI: Responsive Streamlit interface designed for iOS/Android
- WebRTC Streaming: Zero-latency bidirectional video from mobile device cameras
- Network Resilient: STUN/TURN servers configured for mobile carrier firewall bypass
- Synchronous Processing: No Redis/Celery dependenciesโpure Python
- Containerized: Single-stage Docker build for Hugging Face Spaces deployment
๐๏ธ Project Architecture
LanePotholeDetection/
โโโ .github/workflows/
โ โโโ deploy.yml # CI/CD pipeline for Hugging Face Spaces
โโโ src/
โ โโโ app.py # Main Streamlit UI + WebRTC setup
โ โโโ detection.py # YOLOv8n + lane detection engine
โโโ Dockerfile # Production container build
โโโ requirements.txt # Python dependencies
โโโ README.md # This file๐ ๏ธ Tech Stack
๐ Quick Start
Local Development
- Clone the repository
git clone https://github.com/yourusername/LanePotholeDetection.git
cd LanePotholeDetection- Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Run the application
streamlit run src/app.py The app will open at http://localhost:8501
- Access from mobile device
- Find your machine's local IP (e.g.,
192.168.1.100) - On mobile browser, navigate to
http://<YOUR_IP>:8501 - Grant camera permission when prompted
Docker Build & Run
# Build the image
docker build -t lane-pothole-detection .
# Run the container
docker run -p 7860:7860 lane-pothole-detectionAccess at http://localhost:7860
๐ Environment Variables
For local development, optional variables:
STREAMLIT_SERVER_PORT(default: 7860)STREAMLIT_SERVER_ADDRESS(default: 0.0.0.0)STREAMLIT_SERVER_HEADLESS(default: true)
๐ฎ Usage
- Allow Camera Access: Grant permission to your device's camera
- Choose Detection Mode:
- Toggle "Detect Potholes" for YOLOv8n inference
- Toggle "Detect Lanes" for lane line tracking
- Position Device: Aim at road ahead for optimal detection
- Monitor Alerts: Real-time statistics and pothole warnings displayed below video
๐ Model Specifications
Pothole Detection (YOLOv8n)
- Model: YOLOv8 Nano (pretrained on COCO)
- Inference Size: 320px (configurable to 640px)
- Confidence Threshold: 0.5 (adjustable)
- Expected FPS: ~10-15 FPS on CPU (varies by device)
Lane Detection
- Method: Canny edge detection + Hough line transform
- Region: Lower 50% of frame (road area)
- Edge Thresholds: 50-150
- Hough Parameters: minLineLength=30, maxLineGap=10
๐ Deployment to Hugging Face Spaces
Prerequisites
- Create a Hugging Face account: https://huggingface.co
- Create a new Space:
- Name:
lane-pothole-detection - Space type:
Docker - Get your HF token: https://huggingface.co/settings/tokens
Setup GitHub Actions
- Add secrets to your GitHub repository:
HF_TOKEN: Your Hugging Face API tokenHF_SPACE_REPO: Formatusername/lane-pothole-detection
- Push to
mainbranchโGitHub Actions will auto-deploy:
git push origin main- Monitor deployment in GitHub Actions tab
- Access your Space at:
https://huggingface.co/spaces/username/lane-pothole-detection
๐ฑ Mobile Browser Compatibility
Requirements: HTTPS connection (Hugging Face provides this automatically)
๐ง Configuration & Tuning
Adjust Model Inference Size
In src/detection.py, modify DetectionEngine initialization:
# For faster inference (lower accuracy)
engine = DetectionEngine(model_size=320)
# For better accuracy (slower inference)
engine = DetectionEngine(model_size=640)Adjust Confidence Threshold
engine = DetectionEngine(conf_threshold=0.6) # Higher = fewer false positivesAdjust Lane Detection Sensitivity
In src/detection.py, modify detect_lanes():
edges = cv2.Canny(blurred, 50, 150) # Edge thresholds
threshold=50, # Hough votes required
minLineLength=30, # Minimum line length
maxLineGap=10 # Maximum gap in lineโก Performance Optimization
- Model Size 320px: Fastest, lower accuracy (~15 FPS)
- Model Size 640px: Better accuracy, slower (~8 FPS)
- Lane Detection Only: 25-30 FPS
- Potholes Only: 10-15 FPS
- Both Enabled: 5-8 FPS
Toggle detection modes in the UI to balance accuracy vs responsiveness.
๐ Troubleshooting
Camera Not Connecting
- Check HTTPS is being used (required for WebRTC)
- Verify STUN servers are accessible (may be blocked by carrier)
- Test on WiFi instead of mobile data initially
Low FPS
- Reduce inference resolution (320px instead of 640px)
- Disable one detection type
- Reduce frame resolution in constraints
Model Not Downloading
- First run downloads YOLOv8n (~36MB)
- Ensure internet connection available
- Check disk space (minimum 500MB free)
๐ References
๐ License
MIT License - feel free to use and modify for your projects.
๐ค Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
๐ง Support
For issues and questions:
- Open a GitHub issue
- Check existing documentation
- Review troubleshooting section
Built with โค๏ธ for road safety using Computer Vision
