SphereSfM
repository·main·Indexed 43 days ago
https://github.com/json87/spheresfmA specialized extension of ColMap for sparse and dense 3D reconstruction from spherical (equirectangular) images. Optimized for cameras such as Insta360 and Ricoh theta, it extends the ColMap SfM engine to support spherical image orientation and provides a workflow for 3D modeling in complex urban environments.
What's inside SphereSfM
- SphereSfM is a software package designed for the sparse reconstruction of spherical images in EquiRectangular Projection (ERP) format using incremental Structure from Motion (SfM). It is specifically optimized for spherical cameras like Insta360 and Ricoh theta, making it suitable for 3D modeling in complex urban environments, such as streets and near-ground buildings. The project extends the ColMap SfM engine to support spherical image orientation and can be integrated into standard SfM-MVS (Structure from Motion - Multi-View Stereo) workflows.
Manage shared intrinsics in COLMAP
mainImages share the same intrinsics if they refer to the same camera, identified by thecamera_idproperty in the database. You can manage shared intrinsics by adding new cameras and setting these properties using the database management tool.Terminology in COLMAP
mainUnderstanding the core concepts used in COLMAP:
- Camera: Represents a physical object with a specific zoom factor and lens. It defines the intrinsic projection model. A single camera can be used for multiple images if they share the same resolution, intrinsic parameters, and distortion characteristics.
- Image: A bitmap file (e.g., JPEG, PNG) on disk.
- Keypoints: Specific points detected within an image.
- Descriptors: Numerical descriptions of the appearance of keypoints.
- Matches: Pure appearance-based correspondences between keypoints/descriptors.
- Inlier Matches: Matches that have been geometrically verified and are used for the actual reconstruction.
Understand Sparse Reconstruction file formats
mainSparse models are stored in directories containing three files:
cameras,images, andpoints3D.COLMAP supports two formats:
- Binary (
.bin): Machine-readable and fast. This is the default. If a directory contains both binary and text files, the binary format is preferred. - Text (
.txt): Human-readable but slower.
Conversion Methods:
- GUI: Use
File > Export model(binary) orFile > Export model as text(text). To convert, import the model first, then export in the desired format. - CLI: Use the
model_converterexecutable. - Other Formats: Use
File > Export as...in the GUI to export to VisualSfM's NVM, Bundler, PLY, VRML, etc.
Programmatic Access:
- Python: Use
scripts/python/read_write_model.py(supports both binary and text). - Matlab: Use
scripts/matlab/read_model.m(supports text).
- Binary (
Understand Consistency Graphs format
mainThe consistency graph defines which source images a pixel is consistent with. It is stored as a mixed text and binary file.
- Text part: Follows the same format as depth/normal maps (
with&height&channels&header +float32binary data). - Binary part: A continuous list of
int32values in the format:<row><col><N><image_idx1>...<image_idxN>.
Note that
image_idxvalues are zero-based indices relative to the ordering in theimages.txtfile.- Text part: Follows the same format as depth/normal maps (
Configure Cameras and Images in the database
mainThe relationship between cameras and images is 1-to-N. One camera (containing intrinsic parameters like focal length and distortion) can be shared by multiple images. Each image has its own unique extrinsic parameters (orientation and location).
Key Requirements:
- Identifiers: When manually inserting data, ensure
image_id > 0andcamera_id > 0. - Camera Parameters: Intrinsic parameters are stored as contiguous
float64binary blobs. The order of parameters depends on the camera model defined insrc/base/camera_models.h. - Image Paths: The
namecolumn in theimagestable must contain the unique relative path within the image folder. This allows you to move the database and image folder simultaneously as long as the relative structure remains intact.
- Identifiers: When manually inserting data, ensure
Understand Dense Reconstruction workspace structure
mainA dense reconstruction workspace follows a specific directory structure:
+── images │ +── image1.jpg │ +── image2.jpg │ +── ... +── sparse │ +── cameras.txt │ +── images.txt │ +── points3D.txt +── stereo │ +── consistency_graphs │ │ +── image1.jpg.photometric.bin │ │ +── ... │ +── depth_maps │ │ +── image1.jpg.photometric.bin │ │ +── ... │ +── normal_maps │ │ +── image1.jpg.photometric.bin │ │ +── ... │ +── patch-match.cfg │ +── fusion.cfg +── fused.ply +── meshed-poisson.ply +── meshed-delaunay.ply +── run-colmap-geometric.sh +── run-colmap-photometric.shimages/: Contains undistorted images.sparse/: Contains the sparse reconstruction (cameras, images, points3D).stereo/: Contains stereo reconstruction results (consistency graphs, depth maps, normal maps).fused.ply/mesh.ply: Results of fusion and meshing procedures.
+── images │ +── image1.jpg │ +── image2.jpg │ +── ... +── sparse │ +── cameras.txt │ +── images.txt │ +── points3D.txt +── stereo │ +── consistency_graphs │ │ +── image1.jpg.photometric.bin │ │ +── image2.jpg.photometric.bin │ │ +── ... │ +── depth_maps │ │ +── image1.jpg.photometric.bin │ │ +── image2.jpg.photometric.bin │ │ +── ... │ +── normal_maps │ │ +── image1.jpg.photometric.bin │ │ +── image2.jpg.photometric.bin │ │ +── ... │ +── patch-match.cfg │ +── fusion.cfg +── fused.ply +── meshed-poisson.ply +── meshed-delaunay.ply +── run-colmap-geometric.sh +── run-colmap-photometric.shUnderstand the COLMAP database schema
mainSphereSfM uses a single SQLite database file to store all extracted information. The database consists of the following tables:
cameras: Stores intrinsic parameters.images: Stores image metadata and extrinsic parameters.keypoints: Stores detected feature locations and geometry.descriptors: Stores feature appearance descriptors.matches: Stores feature matches between image pairs.two_view_geometries: Stores geometric verification results used for reconstruction.
You can interact with this database using the COLMAP GUI, the C++ database API (
src/base/database.h), or the Python scripting interface (scripts/python/database.py).How Multi-View Stereo (MVS) works in COLMAP
mainMulti-View Stereo (MVS) is the second major phase of reconstruction. It takes the sparse output from the SfM process and computes depth and/or normal information for every pixel in the input images.
Key steps:
- Depth/Normal Computation: Per-pixel information is derived from the SfM camera poses and sparse points.
- Fusion: Depth and normal maps from multiple images are fused in 3D to produce a dense point cloud.
- Surface Reconstruction: Using the fused point cloud, algorithms like (screened) Poisson surface reconstruction can be used to recover the final 3D surface geometry (mesh).
How Structure-from-Motion (SfM) works in COLMAP
mainStructure-from-Motion (SfM) reconstructs 3D structure and camera parameters (intrinsic and extrinsic) from a series of overlapping images. COLMAP implements an incremental SfM pipeline divided into three main stages:
- Feature detection and extraction: Identifying keypoints in images.
- Feature matching and geometric verification: Finding correspondences between keypoints and verifying them geometrically.
- Structure and motion reconstruction: Recovering the 3D points and camera poses.
SfM output serves as the input for Multi-View Stereo (MVS), which computes depth/normal information to produce a dense representation (point clouds and meshes).
Calculate and use pair_id for matches
mainThe
matchesandtwo_view_geometriestables use apair_idto identify matches between two unique images. Thispair_idis a row-major, linear index in the upper-triangular match matrix. This allows for efficient querying even with millions of entries.Pair ID Logic
To generate a
pair_idfrom two image IDs:def image_ids_to_pair_id(image_id1, image_id2): if image_id1 > image_id2: return 2147483647 * image_id2 + image_id1 else: return 2147483647 * image_id1 + image_id2To retrieve image IDs from a
pair_id:def pair_id_to_image_ids(pair_id): image_id2 = pair_id % 2147483647 image_id1 = (pair_id - image_id2) / 2147483647 return image_id1, image_id2Constraints
- Max Images: Because
pair_idrelies on signed 32-bit integer math, the maximumimage_idallowed is 2147483647.
def image_ids_to_pair_id(image_id1, image_id2): if image_id1 > image_id2: return 2147483647 * image_id2 + image_id1 else: return 2147483647 * image_id1 + image_id2 def pair_id_to_image_ids(pair_id): image_id2 = pair_id % 2147483647 image_id1 = (pair_id - image_id2) / 2147483647 return image_id1, image_id2- Max Images: Because
Quickstart with COLMAP Automatic Reconstruction
mainFor a simple reconstruction, use the COLMAP Graphical User Interface (GUI). The automatic reconstruction tool takes a folder of input images and produces both sparse and dense reconstructions in a specified workspace folder.
- Start the COLMAP GUI.
- Navigate to
Reconstruction > Automatic Reconstruction. - Specify your input images folder and a workspace folder.
- Run the tool.
Output Structure Example: If your workspace is
path/to/projectand images are inpath/to/project/images, the output will look like this:+── images │ +── image1.jpg │ +── image2.jpg │ +── ... +── sparse │ +── 0 │ │ +── cameras.bin │ │ +── images.bin │ │ +── points3D.bin │ +── ... +── dense │ +── 0 │ │ +── images │ │ +── sparse │ │ +── stereo │ │ +── fused.ply │ │ +── meshed-poisson.ply │ │ +── meshed-delaunay.ply │ +── ... +── database.db- Sparse Models: Located in
sparse/(contains.binfiles). - Dense Models: Located in
dense/(contains point clouds and meshes). - Importing: You can import the dense point cloud (
fused.ply) viaFile > Import model from ...in COLMAP. Dense meshes should be viewed in external tools like Meshlab.
# No specific command provided, but describes GUI workflow: # Reconstruction > Automatic Reconstruction ```text +── images │ +── image1.jpg +── sparse │ +── 0 │ │ +── cameras.bin │ │ +── images.bin │ │ +── points3D.bin +── dense │ +── 0 │ │ +── fused.ply +── database.db