A REST API for SFM reconstruction using Hierarchical Localization (hloc) and COLMAP.
357
A REST API for Structure from Motion (SfM) reconstruction using Hierarchical Localization (hloc) and COLMAP. This API provides an easy-to-use endpoint for generating 3D reconstructions from a set of images.
This project wraps the powerful hloc toolbox in a simple FastAPI interface, allowing you to perform SfM reconstruction through HTTP requests. The API handles the complete pipeline from feature extraction to 3D reconstruction, returning a downloadable zip file containing the COLMAP model.
/sfmPerforms Structure from Motion reconstruction on uploaded images.
Parameters:
images: List of image files to process (required)retrieval_conf_key: Configuration for image retrieval (default: "netvlad")feature_conf_key: Configuration for feature extraction (default: "superpoint_aachen")matcher_conf_key: Configuration for feature matching (default: "superpoint+lightglue")Returns:
Example using curl:
curl -X POST "http://localhost:8000/sfm" \
-F "[email protected]" \
-F "[email protected]" \
-F "[email protected]" \
-F "retrieval_conf_key=netvlad" \
-F "feature_conf_key=superpoint_aachen" \
-F "matcher_conf_key=superpoint+lightglue" \
--output sfm_result.zip
docker build -t colmap-api:latest .
docker pull jourdelune876/colmap-api:latest
docker tag jourdelune876/colmap-api:latest colmap:latest
# CPU only
docker run --ipc=host -p 8000:8000 colmap-api:latest
# With GPU support (requires nvidia-docker)
docker run --gpus all --ipc=host -p 8000:8000 colmap:latest
The API will be available at http://localhost:8000 and the docs at http://localhost:8000/docs.
git clone --recursive https://github.com/yourusername/colmap-api.git
cd colmap-api
pip install ./Hierarchical-Localization
pip install .
cd Hierarchical-Localization
fastapi run api.py
The API supports various pre-configured feature extractors and matchers from hloc:
feature_conf_key):superpoint_aachen: SuperPoint optimized for outdoor scenessuperpoint_max: SuperPoint with maximum keypointsdisk: DISK feature detector and descriptorsift: Classical SIFT featuresr2d2: R2D2 featuresmatcher_conf_key):superpoint+lightglue: SuperPoint with LightGlue matcher (fast)superglue: SuperGlue matcher (slower but more accurate)NN-ratio: Nearest neighbor matching with ratio testretrieval_conf_key):netvlad: NetVLAD global descriptorsdensevlad: DenseVLAD descriptorsimport requests
# Prepare images
files = [
('images', open('image1.jpg', 'rb')),
('images', open('image2.jpg', 'rb')),
('images', open('image3.jpg', 'rb'))
]
# Optional parameters
data = {
'retrieval_conf_key': 'netvlad',
'feature_conf_key': 'superpoint_aachen',
'matcher_conf_key': 'superpoint+lightglue'
}
# Make request
response = requests.post('http://localhost:8000/sfm', files=files, data=data)
if response.status_code == 200:
with open('reconstruction.zip', 'wb') as f:
f.write(response.content)
print("SfM reconstruction completed successfully!")
else:
print(f"Error: {response.json()}")
The API returns a ZIP file containing the COLMAP reconstruction with the following structure:
sfm_output.zip
├── database.db # COLMAP database
├── cameras.bin # Camera parameters
├── images.bin # Image poses and observations
├── points3D.bin # 3D point cloud
└── models/ # Additional model files
This API is built on top of:
Contributions are welcome! Please feel free to submit issues and pull requests.
This project builds upon hloc and COLMAP. Please refer to their respective licenses:
If you use this API in your research, please cite the original hloc paper:
@inproceedings{sarlin2019coarse,
title={From Coarse to Fine: Robust Hierarchical Localization at Large Scale},
author={Sarlin, Paul-Edouard and Cadena, Cesar and Siegwart, Roland and Dymczyk, Marcin},
booktitle={CVPR},
year={2019}
}
Content type
Image
Digest
sha256:dc9e5841e…
Size
5 GB
Last updated
over 1 year ago
docker pull jourdelune876/colmap-api