An AI-powered web application for detecting and extracting building footprints from satellite imagery
Building Detector is a sophisticated tool that leverages deep learning to identify and extract building geometries from satellite imagery. The application provides an intuitive web interface where users can:
✅ Select areas of interest on an interactive map
✅ Download high-resolution satellite imagery
✅ Place reference points on specific buildings to guide the detection algorithm
✅ Process images to identify marked buildings
✅ Export results in GeoJSON format or OpenStreetMap-compatible format
The system uses a two-tier architecture:
- Frontend (Flask Web App): Provides the user interface and handles satellite imagery downloads
- Backend (Colab ML Server): Runs the machine learning model using Segment Anything Model 2 (SAM2)
- 🗺️ Interactive map-based interface for area selection
- 📡 One-click satellite image download for any region
- 🎯 Point-based detection control - users specify exactly which buildings to detect
- 🔧 Building regularization for clean, precise geometries
- 📊 Dual export options:
- Standard GeoJSON with building metadata
- OpenStreetMap-compatible GeoJSON for easy OSM contributions
building-detector/
├── main.py # Main entry point
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore rules
├── LICENSE # MIT License
│
├── app/ # Main application directory
│ ├── app.py # Flask server & routing logic
│ ├── config.py # Configuration settings
│ ├── config.py.template # Configuration template
│ ├── static/ # Static assets (CSS, JS, images)
│ ├── templates/ # HTML templates
│ └── utils/ # Utility functions
│
├── local_backend/ # 🆕 Local ML backend (SAM2)
│ ├── local_server.py # Local SAM2 server
│ ├── requirements.txt # ML dependencies
│ └── README.md # Setup instructions
│
├── uploads/ # Temporary storage (auto-created)
├── UML/ # System documentation
├── building-detector.ipynb # Colab notebook
└── .env.example # Environment template
- Backend: Flask, Python 3.8+
- Frontend: HTML5, CSS3, JavaScript, Leaflet.js
- AI/ML: Segment Anything Model 2 (SAM2)
- Geospatial: leafmap, GeoJSON
- Deployment: ngrok (for Colab connectivity)
- Python 3.8 or higher
- Modern web browser with JavaScript enabled
- Internet connection for satellite imagery and ML processing
- Google Colab account (for ML backend)
git clone https://github.com/yourusername/building-detector.git
cd building-detector
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
python main.py
Open your browser and navigate to: http://127.0.0.1:5000/
- Access the Colab notebook: Building Detector ML Server
- Make a copy to your Google Drive
- Get ngrok token: Register at ngrok.com and copy your auth token
- Run the notebook: Enter your ngrok token when prompted
- Update configuration: Copy the ngrok URL to
app/config.py
:COLAB_SERVER_URL = 'https://your-ngrok-url.ngrok.io'
NEW! Run the complete AI pipeline locally using the same SAM2 model as Colab:
-
Install local backend:
cd local_backend pip install -r requirements.txt
-
Start local ML server:
python local_server.py # Runs on port 5001
-
Configure main app:
export COLAB_SERVER_URL='http://127.0.0.1:5001' python main.py
Benefits: No cloud dependencies, data privacy, no session timeouts Requirements: 8GB+ RAM, Python 3.8+, optional GPU for speed
See local_backend/README.md for detailed setup instructions.
- 📍 Select Area: Navigate to your area of interest on the interactive map
- 📡 Download Imagery: Click "Download Satellite Image" for the visible region
- 🎯 Place Points: Click on buildings you want to detect (each click marks a building)
- ⚙️ Process: Click "Detect Buildings" to start the AI processing
- 💾 Export Results: Download detected buildings as GeoJSON files
- API keys and credentials are externalized to environment variables
- Sensitive data is excluded from version control via
.gitignore
- Upload directory is automatically cleaned between sessions
Contributions are welcome! Please feel free to submit issues and enhancement requests.
This project is licensed under the MIT License - see the LICENSE file for details.
Silas Pignotti