1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//! COLMAP Rust 库
//!
//! 这是一个用 Rust 实现的 COLMAP(Structure-from-Motion 和 Multi-View Stereo)库。
//! 提供了完整的 3D 重建管道,从图像特征提取到最终的密集 3D 模型生成。
//!
//! # 主要功能
//!
//! - **特征提取和匹配**:支持 SIFT、ORB、FAST 等多种特征检测算法
//! - **Structure from Motion (SfM)**:增量式稀疏 3D 重建
//! - **Multi-View Stereo (MVS)**:密集重建和点云生成
//! - **相机标定**:支持针孔、鱼眼等多种相机模型和畸变校正
//! - **几何验证**:RANSAC、本质矩阵估计等几何约束验证
//! - **束调整优化**:全局优化相机参数和 3D 点位置
//!
//! # 架构设计
//!
//! 库采用模块化设计,主要包含以下模块:
//!
//! - [`core`] - 核心数据结构和类型定义
//! - [`feature`] - 特征提取、描述符计算和匹配
//! - [`sfm`] - Structure from Motion 稀疏重建
//! - [`mvs`] - Multi-View Stereo 密集重建
//! - [`math`] - 数学工具和算法
//! - [`io`] - 数据输入输出
//! - [`utils`] - 通用工具函数
//!
//! # 快速开始
//!
//! ## 基本使用流程
//!
//! ```rust,ignore
//! use colmap::*;
//!
//! // 1. 创建相机模型
//! let intrinsics = CameraIntrinsics::pinhole(800.0, 800.0, 320.0, 240.0);
//! let camera = Camera::new(1, intrinsics, (640, 480), "Camera1".to_string());
//!
//! // 2. 特征提取
//! let pipeline = FeaturePipeline::new(PipelineConfig::default());
//! // let features = pipeline.extract_features(&images)?;
//!
//! // 3. SfM 重建
//! let sfm_config = SfmConfig::default();
//! let mut reconstructor = IncrementalSfm::new(sfm_config);
//! // let sparse_reconstruction = reconstructor.reconstruct(&images, &matches)?;
//!
//! // 4. MVS 密集重建
//! let mvs_config = MvsConfig::default();
//! let mvs_reconstructor = MvsReconstructor::new(mvs_config);
//! // let dense_reconstruction = mvs_reconstructor.reconstruct(&views)?;
//!
//! println!("重建完成!");
//! # Ok::<(), ColmapError>(())
//! ```
//!
//! ## 完整的重建示例
//!
//! ```rust,ignore
//! use colmap::*;
//! use std::path::Path;
//!
//! fn reconstruct_from_images(image_dir: &Path) -> Result<()> {
//! // 1. 加载图像
//! let images = load_images_from_directory(image_dir)?;
//!
//! // 2. 特征提取和匹配
//! let feature_config = PipelineConfig {
//! detector_type: DetectorType::Sift,
//! max_features: 8000,
//! ..Default::default()
//! };
//!
//! let pipeline = FeaturePipeline::new(feature_config);
//! let extraction_result = pipeline.extract_and_match_all(&images)?;
//!
//! println!("提取了 {} 个图像的特征", extraction_result.features.len());
//! println!("找到 {} 个匹配对", extraction_result.matches.len());
//!
//! // 3. SfM 稀疏重建
//! let sfm_config = SfmConfig {
//! min_track_length: 2,
//! max_reprojection_error: 4.0,
//! ..Default::default()
//! };
//!
//! let mut sfm_reconstructor = IncrementalSfm::new(sfm_config);
//! sfm_reconstructor.set_features(extraction_result.features);
//! sfm_reconstructor.set_matches(extraction_result.matches);
//!
//! let sparse_reconstruction = sfm_reconstructor.reconstruct()?;
//!
//! println!("稀疏重建统计:");
//! println!(" - 注册图像: {}", sparse_reconstruction.registered_images());
//! println!(" - 3D 点数量: {}", sparse_reconstruction.points.len());
//! println!(" - 平均重投影误差: {:.2}", sparse_reconstruction.mean_reprojection_error());
//!
//! // 4. MVS 密集重建
//! let mvs_config = MvsConfig {
//! min_num_views: 3,
//! max_image_size: 1600,
//! depth_range: (0.1, 100.0),
//! ..Default::default()
//! };
//!
//! let mvs_reconstructor = MvsReconstructor::new(mvs_config);
//! let views = prepare_views_from_reconstruction(&sparse_reconstruction)?;
//! let dense_reconstruction = mvs_reconstructor.reconstruct(&views)?;
//!
//! println!("密集重建统计:");
//! println!(" - 点云大小: {}", dense_reconstruction.point_cloud.points.len());
//! println!(" - 网格三角形: {}", dense_reconstruction.mesh.triangles.len());
//!
//! // 5. 保存结果
//! save_reconstruction(&sparse_reconstruction, "sparse_reconstruction")?;
//! save_point_cloud(&dense_reconstruction.point_cloud, "dense_point_cloud.ply")?;
//! save_mesh(&dense_reconstruction.mesh, "mesh.obj")?;
//!
//! Ok(())
//! }
//!
//! # fn load_images_from_directory(dir: &Path) -> Result<Vec<Image>> { todo!() }
//! # fn prepare_views_from_reconstruction(recon: &Reconstruction) -> Result<Vec<ViewInfo>> { todo!() }
//! # fn save_reconstruction(recon: &Reconstruction, path: &str) -> Result<()> { todo!() }
//! # fn save_point_cloud(cloud: &FusionResult, path: &str) -> Result<()> { todo!() }
//! # fn save_mesh(mesh: &TriangleMesh, path: &str) -> Result<()> { todo!() }
//! ```
//!
//! # 性能优化建议
//!
//! - 使用适当的图像尺寸(推荐 1600x1200 以下)
//! - 调整特征点数量以平衡质量和速度
//! - 对于大规模数据集,考虑分块处理
//! - 使用多线程处理独立的图像对
//!
//! # 错误处理
//!
//! 库使用统一的错误类型 [`ColmapError`],支持详细的错误信息:
//!
//! ```rust,no_run
//! use colmap::*;
//!
//! match reconstruct_scene() {
//! Ok(reconstruction) => {
//! println!("重建成功!");
//! }
//! Err(ColmapError::FeatureExtraction(msg)) => {
//! eprintln!("特征提取失败: {}", msg);
//! }
//! Err(ColmapError::SfmReconstruction(msg)) => {
//! eprintln!("SfM 重建失败: {}", msg);
//! }
//! Err(e) => {
//! eprintln!("其他错误: {}", e);
//! }
//! }
//!
//! # fn reconstruct_scene() -> Result<Reconstruction> { todo!() }
//! ```
// 重新导出主要类型和函数
pub use *;
pub use *;
pub use *;
pub use *;
/// 库版本信息
pub const VERSION: &str = env!;
/// 库名称
pub const NAME: &str = env!;
/// 获取库信息