OpenSfM开源软件使用小心得
1 常用的开源Structure-from-Motion软件
- OpenMVG 3.5k⭐
- Colmap 2.9k⭐
- OpenSfM (Python) 2.1k⭐
- Bundler 1.3k⭐
- MVE 758⭐
- TheiaSfM 652⭐
- MICMAC 292⭐
(⭐表示Github上的star数)
【注】
Bundler是由SfM创始人的华盛顿大学的Snavely教授所写。
上述7个软件,只有OpenSfM是用Python写的,其他软件语言均为C++。即使是OpenSfM也使用了Python binding。主要原因是OpenSfM也使用了C++的非线性优化包Ceres(基本上每个SfM、SLAM软件都离不开该库)。
2 OpenSfM的简易运行(基于Linux)
(我的操作系统是Ubuntu20.04LTS,OpenSfM纯粹使用CPU运行,没有显卡、显卡驱动那些玩意儿也完全没有关系)
(注:OpenSfM并不是一下载下来就能用,要按照官方文档的步骤,需要安装依赖并编译才能用。这篇博客不涉及安装OpenSfM的步骤。)
运行整个OpenSfM最方便的办法是:终端定位到OpenSfM的根目录,然后输入以下命令
//berlin是存放示例图片的文件夹。
bin/opensfm_run_all data/berlin
实际上,该命令执行了根目录的bin文件夹中的opensfm_run_all data文件,该文件就是8个命令。
$PYTHON $DIR/opensfm extract_metadata $1
$PYTHON $DIR/opensfm detect_features $1
$PYTHON $DIR/opensfm match_features $1
$PYTHON $DIR/opensfm create_tracks $1
$PYTHON $DIR/opensfm reconstruct $1
$PYTHON $DIR/opensfm mesh $1
$PYTHON $DIR/opensfm undistort $1
$PYTHON $DIR/opensfm compute_depthmaps $1
这8个命令执行完了SfM的整个流程,输出数据在根目录下的data/berlin下。
berlin/
├── config.yaml
├── images/
├── masks/
├── gcp_list.txt
├── exif/
├── camera_models.json
├── features/
├── matches/
├── tracks.csv
├── reconstruction.json
├── reconstruction.meshed.json
└── undistorted/
├── images/
├── masks/
├── tracks.csv
├── reconstruction.json
└── depthmaps/
└── merged.ply
merged.ply可以用Meshlab软件打开,查看重建效果。
reconstruction.json中含有所有重建的三维点坐标(structure),以及相机参数(motion)。格式如下:
// reconstruction.json: [RECONSTRUCTION, ...]
RECONSTRUCTION: {
"cameras": {
CAMERA_ID: CAMERA,
...
},
"shots": {
SHOT_ID: SHOT,
...
},
"points": {
POINT_ID: POINT,
...
}
}
CAMERA: {
"projection_type": "perspective", # Can be perspective, brown, fisheye or equirectangular
"width": NUMBER, # Image width in pixels
"height": NUMBER, # Image height in pixels
# Depending on the projection type more parameters are stored.
# These are the parameters of the perspective camera.
"focal": NUMBER, # Estimated focal length
"k1": NUMBER, # Estimated distortion coefficient
"k2": NUMBER, # Estimated distortion coefficient
}
SHOT: {
"camera": CAMERA_ID,
"rotation": [X, Y, Z], # Estimated rotation as an angle-axis vector
"translation": [X, Y, Z], # Estimated translation
"gps_position": [X, Y, Z], # GPS coordinates in the reconstruction reference frame
"gps_dop": METERS, # GPS accuracy in meters
"orientation": NUMBER, # EXIF orientation tag (can be 1, 3, 6 or 8)
"capture_time": SECONDS # Capture time as a UNIX timestamp
}
POINT: {
"coordinates": [X, Y, Z