Skip to content

Instantly share code, notes, and snippets.

@cashiwamochi
Created April 28, 2019 10:53
Show Gist options
  • Save cashiwamochi/89d2b43b69f2e7d025f9e94cd45e6ca3 to your computer and use it in GitHub Desktop.
Save cashiwamochi/89d2b43b69f2e7d025f9e94cd45e6ca3 to your computer and use it in GitHub Desktop.
An easy script for sfm using colmap
#!/bin/bash
# Extract frames from video
mkdir images
ffmpeg -i $1 -r 24 -q:v 1 images/%06d.jpg
# ffmpeg -i $1 -ss start[sec] -t end[sec] [framerate] -q:v 1 %06d.jpg
# start to colmap process
DATASET_PATH=$(pwd)
echo $DATASET_PATH
# feature extractor
colmap feature_extractor \
--database_path $DATASET_PATH/database.db \
--image_path $DATASET_PATH/images \
--ImageReader.camera_model OPENCV \
--ImageReader.single_camera 1 \
--SiftExtraction.use_gpu 1 \
--SiftExtraction.gpu_index 0 \
--SiftExtraction.num_octaves 5 \
--SiftExtraction.estimate_affine_shape 1
# Other options
# --ImageReader.camera_model FULL_OPENCV \
# feature matcher
colmap sequential_matcher \
--database_path $DATASET_PATH/database.db \
--SiftMatching.use_gpu true \
--SiftMatching.gpu_index 0,1 \
--SiftMatching.cross_check 1 \
--SiftMatching.guided_matching 1 \
--SequentialMatching.overlap 20 \
--SequentialMatching.loop_detection 1
mkdir sparse
# 3D reconstruction
colmap mapper --database_path $DATASET_PATH/database.db \
--image_path $DATASET_PATH/images \
--output_path $DATASET_PATH/sparse \
--Mapper.ba_refine_extra_params 0 \
--Mapper.filter_max_reproj_error 0.900 \
--Mapper.ba_global_use_pba 0
# BA 1st
colmap bundle_adjuster \
--input_path $DATASET_PATH/sparse/0 \
--output_path $DATASET_PATH/sparse/0 \
--BundleAdjustment.refine_focal_length 1 \
--BundleAdjustment.refine_principal_point 0 \
--BundleAdjustment.refine_extra_params 1 \
--BundleAdjustment.refine_extrinsics 1
# BA final
colmap bundle_adjuster \
--input_path $DATASET_PATH/sparse/0 \
--output_path $DATASET_PATH/sparse/0 \
--BundleAdjustment.refine_focal_length 1 \
--BundleAdjustment.refine_principal_point 1 \
--BundleAdjustment.refine_extra_params 1 \
--BundleAdjustment.refine_extrinsics 1
# Export sparse model
colmap model_converter --input_path sparse/0/ --output_path sparse/0/output_sparse.ply --output_type PLY
mkdir $DATASET_PATH/dense
colmap image_undistorter \
--image_path $DATASET_PATH/images \
--input_path $DATASET_PATH/sparse/0 \
--output_path $DATASET_PATH/dense \
--output_type COLMAP \
--max_image_size 2000
colmap patch_match_stereo \
--workspace_path $DATASET_PATH/dense \
--workspace_format COLMAP \
--PatchMatchStereo.geom_consistency true
colmap stereo_fusion \
--workspace_path $DATASET_PATH/dense \
--workspace_format COLMAP \
--input_type geometric \
--output_path $DATASET_PATH/dense/fused.ply
colmap poisson_mesher \
--input_path $DATASET_PATH/dense/fused.ply \
--output_path $DATASET_PATH/dense/meshed-poisson.ply
colmap delaunay_mesher \
--input_path $DATASET_PATH/dense \
--output_path $DATASET_PATH/dense/meshed-delaunay.ply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment