55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
//! Infer COLMAP cameras from a folder of images using only their headers (size + EXIF).
|
|
//!
|
|
//! Run with:
|
|
//! ```text
|
|
//! cargo run --example infer_camera -- ../images
|
|
//! ```
|
|
//! If no path is given it defaults to `../images` (the South Building sample set).
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use colmap::image::{infer_shared_cameras_in_dir, read_exif, read_image_size};
|
|
|
|
fn main() -> colmap::Result<()> {
|
|
let dir: PathBuf = std::env::args()
|
|
.nth(1)
|
|
.map(PathBuf::from)
|
|
.unwrap_or_else(|| PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/../images")));
|
|
|
|
println!("Scanning {}", dir.display());
|
|
|
|
let images = colmap::image::list_images_in_dir(&dir)?;
|
|
println!("Found {} images\n", images.len());
|
|
|
|
if let Some(first) = images.first() {
|
|
let (w, h) = read_image_size(first)?;
|
|
println!("First image: {}", first.file_name().unwrap().to_string_lossy());
|
|
println!(" size: {w} x {h}");
|
|
if let Some(exif) = read_exif(first)? {
|
|
println!(" make/model: {:?} / {:?}", exif.make, exif.model);
|
|
println!(" focal length: {:?} mm", exif.focal_length_mm);
|
|
println!(
|
|
" focal-plane res: {:?} (unit {:?})",
|
|
exif.focal_plane_x_resolution, exif.focal_plane_resolution_unit
|
|
);
|
|
}
|
|
let cam = colmap::image::infer_camera_from_image(first, 1)?;
|
|
println!(
|
|
" inferred camera: {} {}x{} params={:?} prior_focal={}",
|
|
cam.model_name(),
|
|
cam.width,
|
|
cam.height,
|
|
cam.params,
|
|
cam.has_prior_focal_length
|
|
);
|
|
}
|
|
|
|
let (cameras, assignment) = infer_shared_cameras_in_dir(&dir)?;
|
|
println!(
|
|
"\nDeduplicated to {} camera(s) across {} images.",
|
|
cameras.len(),
|
|
assignment.len()
|
|
);
|
|
Ok(())
|
|
}
|