{"library":"pycolmap","title":"pycolmap: Python Bindings for COLMAP","description":"pycolmap provides robust Python bindings for COLMAP, an open-source Structure-from-Motion (SfM) and Multi-View Stereo (MVS) pipeline. It allows programmatic control over COLMAP's feature extraction, matching, and 3D reconstruction functionalities directly from Python. The current version is 4.0.3, with releases typically synchronized with major COLMAP C++ releases, focusing on performance, new features, and bug fixes.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pycolmap","pip install pycolmap[cuda]"],"cli":null},"imports":["from pycolmap import Sfm","from pycolmap import Camera","from pycolmap import Image","from pycolmap import Point3D","from pycolmap import extract_features","from pycolmap import match_features","from pycolmap import reconstruct"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport pycolmap\nimport numpy as np\nfrom PIL import Image\n\n# Create a dummy image directory\nimage_dir = \"pycolmap_quickstart_images\"\noutput_dir = \"pycolmap_quickstart_output\"\n\nos.makedirs(image_dir, exist_ok=True)\nos.makedirs(output_dir, exist_ok=True)\n\n# Create two dummy images (COLMAP typically needs more and with overlap)\nimg_size = (100, 100)\nfor i in range(2):\n    dummy_image = Image.fromarray(np.random.randint(0, 255, img_size + (3,), dtype=np.uint8))\n    dummy_image.save(os.path.join(image_dir, f\"image_{i+1:02d}.jpg\"))\n\nprint(f\"Dummy images created in {image_dir}\")\n\n# Run the high-level SfM reconstruction\n# Note: With only two random images, this is expected to fail or produce an empty model.\n# A real scenario requires actual images with sufficient overlap and features.\ntry:\n    sfm_pipeline = pycolmap.Sfm(image_dir, output_dir)\n    reconstruction = sfm_pipeline.run()\n    if reconstruction:\n        print(f\"Reconstruction successful! Found {len(reconstruction.images)} images and {len(reconstruction.points3D)} 3D points.\")\n    else:\n        print(\"Reconstruction did not produce a valid model (expected for random, non-overlapping images).\")\nexcept Exception as e:\n    print(f\"Reconstruction failed (expected for random images without overlap/features): {e}\")\n\n# Optional: Clean up created directories\n# import shutil\n# shutil.rmtree(image_dir, ignore_errors=True)\n# shutil.rmtree(output_dir, ignore_errors=True)\n","lang":"python","description":"This quickstart demonstrates the high-level `pycolmap.Sfm` class to run a full Structure-from-Motion pipeline. It creates dummy images and attempts a reconstruction, which is expected to fail with only two random images, but illustrates the basic API usage.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}