CoolFace
Apppublic

SanchitBahl/lane-pothole-detection

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

๐Ÿš— 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

ComponentTechnology
FrontendStreamlit + streamlit-webrtc
CV EnginePython OpenCV + Ultralytics YOLOv8n
Video CodecPyAV (libav)
DeploymentDocker + Hugging Face Spaces
ML ModelYOLOv8n (pretrained COCO)

๐Ÿš€ Quick Start

Local Development

  1. 1.Clone the repository
bash
   git clone https://github.com/yourusername/LanePotholeDetection.git
   cd LanePotholeDetection
  1. 1.Create a virtual environment
bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. 1.Install dependencies
bash
   pip install -r requirements.txt
  1. 1.Run the application
bash
   streamlit run src/app.py

The app will open at http://localhost:8501

  1. 1.Access from mobile device
  2. 2.Find your machine's local IP (e.g., 192.168.1.100)
  3. 3.On mobile browser, navigate to http://<YOUR_IP>:8501
  4. 4.Grant camera permission when prompted

Docker Build & Run

bash
# Build the image
docker build -t lane-pothole-detection .

# Run the container
docker run -p 7860:7860 lane-pothole-detection

Access 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

  1. 1.Allow Camera Access: Grant permission to your device's camera
  2. 2.Choose Detection Mode:
  3. 3.Toggle "Detect Potholes" for YOLOv8n inference
  4. 4.Toggle "Detect Lanes" for lane line tracking
  5. 5.Position Device: Aim at road ahead for optimal detection
  6. 6.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

  1. 1.Create a Hugging Face account: https://huggingface.co
  2. 2.Create a new Space:
  3. 3.Name: lane-pothole-detection
  4. 4.Space type: Docker
  5. 5.Get your HF token: https://huggingface.co/settings/tokens

Setup GitHub Actions

  1. 1.Add secrets to your GitHub repository:
  2. 2.HF_TOKEN: Your Hugging Face API token
  3. 3.HF_SPACE_REPO: Format username/lane-pothole-detection
  1. 1.Push to main branchโ€”GitHub Actions will auto-deploy:
bash
   git push origin main
  1. 1.Monitor deployment in GitHub Actions tab
  1. 1.Access your Space at: https://huggingface.co/spaces/username/lane-pothole-detection

๐Ÿ“ฑ Mobile Browser Compatibility

BrowseriOSAndroid
Safariโœ…N/A
Chromeโœ…โœ…
Firefoxโœ…โœ…
Edgeโœ…โœ…

Requirements: HTTPS connection (Hugging Face provides this automatically)

๐Ÿ”ง Configuration & Tuning

Adjust Model Inference Size

In src/detection.py, modify DetectionEngine initialization:

python
# For faster inference (lower accuracy)
engine = DetectionEngine(model_size=320)

# For better accuracy (slower inference)
engine = DetectionEngine(model_size=640)

Adjust Confidence Threshold

python
engine = DetectionEngine(conf_threshold=0.6)  # Higher = fewer false positives

Adjust Lane Detection Sensitivity

In src/detection.py, modify detect_lanes():

python
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:

  1. 1.Fork the repository
  2. 2.Create a feature branch
  3. 3.Make your changes
  4. 4.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