From ca6dd291143348ef7c38ca60e7e0011369d7976b Mon Sep 17 00:00:00 2001 From: Paul-Edouard Sarlin Date: Sun, 14 Jan 2024 23:57:46 +0100 Subject: [PATCH] Add example --- .gitignore | 1 + example.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 example.py diff --git a/.gitignore b/.gitignore index 9f610d1f..eea1b9fc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.egg-info/ build/ .cache/ +example/ diff --git a/example.py b/example.py new file mode 100644 index 00000000..7cc422e7 --- /dev/null +++ b/example.py @@ -0,0 +1,43 @@ +import shutil +import urllib.request +import zipfile +from pathlib import Path + +import pycolmap +from pycolmap import logging + + +def run(): + output_path = Path("example/") + image_path = output_path / "Fountain/images" + database_path = output_path / "database.db" + sfm_path = output_path / "sfm" + + output_path.mkdir(exist_ok=True) + logging.set_log_destination(logging.INFO, output_path / "INFO.log.") # + time + + data_url = "https://cvg-data.inf.ethz.ch/local-feature-evaluation-schoenberger2017/Strecha-Fountain.zip" + if not image_path.exists(): + logging.info("Downloading the data.") + zip_path = output_path / "data.zip" + urllib.request.urlretrieve(data_url, zip_path) + with zipfile.ZipFile(zip_path, "r") as fid: + fid.extractall(output_path) + logging.info(f"Data extracted to {output_path}.") + + if database_path.exists(): + database_path.unlink() + pycolmap.extract_features(database_path, image_path) + + pycolmap.match_exhaustive(database_path) + + if sfm_path.exists(): + shutil.rmtree(sfm_path) + sfm_path.mkdir(exist_ok=True) + recs = pycolmap.incremental_mapping(database_path, image_path, sfm_path) + for idx, rec in recs.items(): + logging.info(f"#{idx} {rec.summary()}") + + +if __name__ == "__main__": + run()