68 lines
2.5 KiB
Rust
68 lines
2.5 KiB
Rust
//! End-to-end reconstruction pipeline skeleton.
|
|
//!
|
|
//! This mirrors the full-program example of the reference `colmap` crate, using
|
|
//! this crate's actual API. The implemented step (camera inference) runs for
|
|
//! real; the scaffolded steps report that they are not ported yet instead of
|
|
//! aborting, so you can see the intended flow end to end.
|
|
//!
|
|
//! ```text
|
|
//! cargo run --example reconstruct -- ../images
|
|
//! ```
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use colmap::feature::{FeatureExtractionOptions, FeatureMatchingOptions};
|
|
use colmap::mvs::{patch_match_stereo, stereo_fusion, PatchMatchOptions, StereoFusionOptions};
|
|
use colmap::sfm::{incremental_mapping, IncrementalPipelineOptions};
|
|
|
|
fn report(step: &str, result: colmap::Result<()>) {
|
|
match result {
|
|
Ok(()) => println!(" ✓ {step}"),
|
|
Err(err) => println!(" … {step}: {err}"),
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let image_dir: PathBuf = std::env::args()
|
|
.nth(1)
|
|
.map(PathBuf::from)
|
|
.unwrap_or_else(|| PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/../images")));
|
|
let database = Path::new("/tmp/colmap-rs/database.db");
|
|
let workspace = Path::new("/tmp/colmap-rs/sparse");
|
|
|
|
println!("Reconstructing from {}", image_dir.display());
|
|
|
|
// 1. Camera inference from image headers (implemented).
|
|
match colmap::image::infer_shared_cameras_in_dir(&image_dir) {
|
|
Ok((cameras, assignment)) => println!(
|
|
" ✓ inferred {} camera(s) for {} images",
|
|
cameras.len(),
|
|
assignment.len()
|
|
),
|
|
Err(err) => {
|
|
eprintln!(" ✗ camera inference failed: {err}");
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 2. Feature extraction & matching (scaffolded).
|
|
report(
|
|
"feature extraction",
|
|
colmap::feature::extract_features(database, &image_dir, &FeatureExtractionOptions::default()),
|
|
);
|
|
report(
|
|
"exhaustive matching",
|
|
colmap::feature::match_exhaustive(database, &FeatureMatchingOptions::default()),
|
|
);
|
|
|
|
// 3. Sparse SfM reconstruction (scaffolded).
|
|
match incremental_mapping(database, &image_dir, workspace, &IncrementalPipelineOptions::default()) {
|
|
Ok(recs) => println!(" ✓ sparse reconstruction: {} model(s)", recs.len()),
|
|
Err(err) => println!(" … sparse SfM: {err}"),
|
|
}
|
|
|
|
// 4. Dense MVS reconstruction (scaffolded).
|
|
report("patch-match stereo", patch_match_stereo(workspace, &PatchMatchOptions::default()));
|
|
report("stereo fusion", stereo_fusion(workspace, &StereoFusionOptions::default()));
|
|
}
|