COLMAP pipeline (SfM + dense)
Photo upload, extraction, matching, reconstruction.
from google.colab import files
import shutil, subprocess
def run(cmd):
print("▶", " ".join(cmd))
subprocess.run(cmd, check=True)
# 1) Upload images into IMAGES_DIR
print("Upload your photos (20–100 images recommended)...")
uploaded = files.upload()
for name, data in uploaded.items():
dest = os.path.join(IMAGES_DIR, name)
with open(dest, "wb") as f:
f.write(data)
print("Saved:", dest)
# 2) Feature extraction
run([
"colmap", "feature_extractor",
"--database_path", DB_PATH,
"--image_path", IMAGES_DIR,
"--SiftExtraction.use_gpu", "0",
])
# 3) Exhaustive matcher
run([
"colmap", "exhaustive_matcher",
"--database_path", DB_PATH,
"--SiftMatching.use_gpu", "0",
])
# 4) Reconstruction (mapper)
run([
"colmap", "mapper",
"--database_path", DB_PATH,
"--image_path", IMAGES_DIR,
"--output_path", SPARSE_DIR,
])
# 5) Undistortion for dense reconstruction
SPARSE_MODEL = os.path.join(SPARSE_DIR, "0")
run([
"colmap", "image_undistorter",
"--image_path", IMAGES_DIR,
"--input_path", SPARSE_MODEL,
"--output_path", DENSE_DIR,
])