# AI Camera-Based Road Damage Monitoring System

A comprehensive web application for detecting and monitoring road damage (potholes and cracks) using AI-powered computer vision.

## Features

- 📤 **Image Upload**: Upload road images for analysis
- 🤖 **AI Detection**: Automatic detection of potholes and cracks
- 📍 **GPS Mapping**: Interactive map showing damage locations
- 📊 **Dashboard**: Comprehensive statistics and severity analysis
- 🎯 **Severity Scoring**: Quantitative assessment for maintenance prioritization

## Project Structure

```
hackathon/
├── backend/                 # Flask API server
│   ├── app.py              # Main Flask application
│   ├── damage_detection.py  # AI model for damage detection
│   └── requirements.txt     # Python dependencies
├── frontend/               # React web application
│   ├── src/
│   │   ├── components/     # React components
│   │   ├── pages/          # Application pages
│   │   ├── App.js          # Main App component
│   │   └── index.js        # Entry point
│   ├── package.json        # Node.js dependencies
│   └── public/             # Static files
└── uploads/                # Uploaded images storage
```

## Tech Stack

### Backend
- **Flask**: Web framework
- **Python**: Backend language
- **OpenCV**: Image processing
- **NumPy**: Numerical computing

### Frontend
- **React**: UI library
- **Bootstrap**: CSS framework
- **React Leaflet**: Map integration
- **Axios**: HTTP client

## Installation

### Backend Setup

```bash
cd backend
pip install -r requirements.txt
```

### Frontend Setup

```bash
cd frontend
npm install
```

## Running the Application

### Start Backend Server

```bash
cd backend
python app.py
```

Server will run on `http://localhost:5000`

### Start Frontend Server (in a new terminal)

```bash
cd frontend
npm start
```

Application will open on `http://localhost:3000`

## Usage Demo Flow

1. **Open Application**: Navigate to `http://localhost:3000`
2. **Upload Image**: Go to Upload page and select a road image
3. **Click Upload**: Submit the image for AI analysis
4. **Wait for Processing**: The AI model analyzes the image (takes a few seconds)
5. **View Results**: Check the detection results with severity scores
6. **Open Dashboard**: Navigate to Dashboard page
7. **View Map**: See all detected damages on an interactive GPS map
8. **Analyze Statistics**: Review severity distribution and detection statistics

## API Endpoints

### POST `/api/upload`
Upload and analyze a road image
- Returns: Detection results with severity scores and GPS coordinates

### GET `/api/detections`
Retrieve all detected damages
- Returns: List of all detection records

### GET `/api/detections/<id>`
Get a specific detection record
- Returns: Single detection record details

### DELETE `/api/detections`
Clear all detections (demo purposes)
- Returns: Success message

## Detection Model

The AI model detects:
- **Potholes**: Dark circular/oval depressions in the road
- **Cracks**: Linear fractures in the asphalt surface

Each detection includes:
- Type (pothole or crack)
- Severity score (0-100)
- GPS coordinates
- Area in pixels
- Confidence level

## Severity Levels

- **Critical** (70-100): Requires immediate attention
- **Moderate** (40-70): Schedule maintenance soon
- **Minor** (0-40): Monitor and assess

## File Upload Requirements

- **Formats**: PNG, JPG, GIF, BMP
- **Max Size**: 10 MB
- **Recommended**: High-resolution images with good lighting

## Future Enhancements

- Real-time camera feed analysis
- Mobile app version
- Automated maintenance request generation
- Integration with municipal databases
- Advanced ML model training
- Historical trend analysis

## License

This project is for demonstration purposes.

## Support

For issues or questions, please contact the development team.
