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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
echo ""
|
| 3 |
+
echo "Executing colmapMatcher.sh ..."
|
| 4 |
+
|
| 5 |
+
sequence_path="$1"
|
| 6 |
+
exp_folder="$2"
|
| 7 |
+
exp_id="$3"
|
| 8 |
+
matcher_type="$4" # Options: exhaustive, sequential
|
| 9 |
+
use_gpu="$5"
|
| 10 |
+
settings_yaml="$6"
|
| 11 |
+
calibration_yaml="$7"
|
| 12 |
+
rgb_txt="$8"
|
| 13 |
+
|
| 14 |
+
exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
|
| 15 |
+
rgb_path="${sequence_path}/$(awk '{print $2}' "${rgb_txt}" | awk -F'/' 'NR==1 {print $1}')"
|
| 16 |
+
|
| 17 |
+
calibration_model=$(grep -oP '(?<=Camera\.model:\s)[\w]+' "$calibration_yaml")
|
| 18 |
+
|
| 19 |
+
fx=$(grep -oP '(?<=Camera\.fx:\s)-?\d+\.\d+' "$calibration_yaml")
|
| 20 |
+
fy=$(grep -oP '(?<=Camera\.fy:\s)-?\d+\.\d+' "$calibration_yaml")
|
| 21 |
+
cx=$(grep -oP '(?<=Camera\.cx:\s)-?\d+\.\d+' "$calibration_yaml")
|
| 22 |
+
cy=$(grep -oP '(?<=Camera\.cy:\s)-?\d+\.\d+' "$calibration_yaml")
|
| 23 |
+
|
| 24 |
+
k1=$(grep -oP '(?<=Camera\.k1:\s)-?\d+\.\d+' "$calibration_yaml")
|
| 25 |
+
k2=$(grep -oP '(?<=Camera\.k2:\s)-?\d+\.\d+' "$calibration_yaml")
|
| 26 |
+
p1=$(grep -oP '(?<=Camera\.p1:\s)-?\d+\.\d+' "$calibration_yaml")
|
| 27 |
+
p2=$(grep -oP '(?<=Camera\.p2:\s)-?\d+\.\d+' "$calibration_yaml")
|
| 28 |
+
k3=$(grep -oP '(?<=Camera\.k3:\s)-?\d+\.\d+' "$calibration_yaml")
|
| 29 |
+
k4=0.0
|
| 30 |
+
k5=0.0
|
| 31 |
+
k6=0.0
|
| 32 |
+
|
| 33 |
+
# Reading settings from yaml file
|
| 34 |
+
feature_extractor_SiftExtraction_num_octaves=$(yq '.feature_extractor.SiftExtraction_num_octaves // 4.0' $settings_yaml)
|
| 35 |
+
feature_extractor_SiftExtraction_octave_resolution=$(yq '.feature_extractor.SiftExtraction_octave_resolution // 3.0' $settings_yaml)
|
| 36 |
+
feature_extractor_SiftExtraction_peak_threshold=$(yq '.feature_extractor.SiftExtraction_peak_threshold // 0.0066666666666666671' $settings_yaml)
|
| 37 |
+
feature_extractor_SiftExtraction_edge_threshold=$(yq '.feature_extractor.SiftExtraction_edge_threshold // 10.0' $settings_yaml)
|
| 38 |
+
feature_extractor_SiftExtraction_dsp_min_scale=$(yq '.feature_extractor.SiftExtraction_dsp_min_scale // 0.1666666666666666' $settings_yaml)
|
| 39 |
+
feature_extractor_SiftExtraction_dsp_max_scale=$(yq '.feature_extractor.SiftExtraction_dsp_max_scale // 3.0' $settings_yaml)
|
| 40 |
+
feature_extractor_SiftExtraction_dsp_num_scales=$(yq '.feature_extractor.SiftExtraction_dsp_num_scales // 10.0' $settings_yaml)
|
| 41 |
+
|
| 42 |
+
matcher_SiftMatching_max_ratio=$(yq '.matcher.SiftMatching_max_ratio // 0.80000000000000004' $settings_yaml)
|
| 43 |
+
matcher_SiftMatching_max_distance=$(yq '.matcher.SiftMatching_max_distance // 0.69999999999999996' $settings_yaml)
|
| 44 |
+
matcher_TwoViewGeometry_min_num_inliers=$(yq '.matcher.TwoViewGeometry_min_num_inliers // 15.0' $settings_yaml)
|
| 45 |
+
matcher_TwoViewGeometry_max_error=$(yq '.matcher.TwoViewGeometry_max_error // 4.0' $settings_yaml)
|
| 46 |
+
matcher_TwoViewGeometry_confidence=$(yq '.matcher.TwoViewGeometry_confidence // 0.999' $settings_yaml)
|
| 47 |
+
matcher_TwoViewGeometry_min_inlier_ratio=$(yq '.matcher.TwoViewGeometry_min_inlier_ratio // 0.25' $settings_yaml)
|
| 48 |
+
matcher_SequentialMatching_overlap=$(yq '.matcher.SequentialMatching_overlap // 10.0' $settings_yaml)
|
| 49 |
+
matcher_SequentialMatching_quadratic_overlap=$(yq '.matcher.SequentialMatching_quadratic_overlap // 1.0' $settings_yaml)
|
| 50 |
+
matcher_ExhaustiveMatching_block_size=$(yq '.matcher.ExhaustiveMatching_block_size // 50.0' $settings_yaml)
|
| 51 |
+
|
| 52 |
+
# Create colmap image list
|
| 53 |
+
colmap_image_list="${exp_folder_colmap}/colmap_image_list.txt"
|
| 54 |
+
awk '{split($2, arr, "/"); print arr[2]}' "$rgb_txt" > "$colmap_image_list"
|
| 55 |
+
|
| 56 |
+
# Create Colmap Database
|
| 57 |
+
database="${exp_folder_colmap}/colmap_database.db"
|
| 58 |
+
rm -rf ${database}
|
| 59 |
+
colmap database_creator --database_path ${database}
|
| 60 |
+
|
| 61 |
+
################################################################################
|
| 62 |
+
echo " colmap feature_extractor ..."
|
| 63 |
+
|
| 64 |
+
if [ "${calibration_model}" == "UNKNOWN" ]
|
| 65 |
+
then
|
| 66 |
+
echo " camera model : $calibration_model"
|
| 67 |
+
colmap feature_extractor \
|
| 68 |
+
--database_path ${database} \
|
| 69 |
+
--image_path ${rgb_path} \
|
| 70 |
+
--image_list_path ${colmap_image_list} \
|
| 71 |
+
--ImageReader.camera_model SIMPLE_PINHOLE \
|
| 72 |
+
--ImageReader.single_camera 1 \
|
| 73 |
+
--ImageReader.single_camera_per_folder 1 \
|
| 74 |
+
--SiftExtraction.use_gpu ${use_gpu} \
|
| 75 |
+
--SiftExtraction.num_octaves ${feature_extractor_SiftExtraction_num_octaves} \
|
| 76 |
+
--SiftExtraction.octave_resolution ${feature_extractor_SiftExtraction_octave_resolution} \
|
| 77 |
+
--SiftExtraction.peak_threshold ${feature_extractor_SiftExtraction_peak_threshold} \
|
| 78 |
+
--SiftExtraction.edge_threshold ${feature_extractor_SiftExtraction_edge_threshold} \
|
| 79 |
+
--SiftExtraction.dsp_min_scale ${feature_extractor_SiftExtraction_dsp_min_scale} \
|
| 80 |
+
--SiftExtraction.dsp_max_scale ${feature_extractor_SiftExtraction_dsp_max_scale} \
|
| 81 |
+
--SiftExtraction.dsp_num_scales ${feature_extractor_SiftExtraction_dsp_num_scales}
|
| 82 |
+
fi
|
| 83 |
+
|
| 84 |
+
feature_extractor_SiftExtraction_dsp_num_scales=$(yq '.feature_extractor.SiftExtraction_dsp_num_scales // 10.0' $settings_yaml)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
if [ "${calibration_model}" == "PINHOLE" ]
|
| 88 |
+
then
|
| 89 |
+
echo " camera model : $calibration_model"
|
| 90 |
+
colmap feature_extractor \
|
| 91 |
+
--database_path ${database} \
|
| 92 |
+
--image_path ${rgb_path} \
|
| 93 |
+
--image_list_path ${colmap_image_list} \
|
| 94 |
+
--ImageReader.camera_model ${calibration_model} \
|
| 95 |
+
--ImageReader.single_camera 1 \
|
| 96 |
+
--ImageReader.single_camera_per_folder 1 \
|
| 97 |
+
--SiftExtraction.use_gpu ${use_gpu} \
|
| 98 |
+
--ImageReader.camera_params "${fx}, ${fy}, ${cx}, ${cy}" \
|
| 99 |
+
--SiftExtraction.num_octaves ${feature_extractor_SiftExtraction_num_octaves} \
|
| 100 |
+
--SiftExtraction.octave_resolution ${feature_extractor_SiftExtraction_octave_resolution} \
|
| 101 |
+
--SiftExtraction.peak_threshold ${feature_extractor_SiftExtraction_peak_threshold} \
|
| 102 |
+
--SiftExtraction.edge_threshold ${feature_extractor_SiftExtraction_edge_threshold} \
|
| 103 |
+
--SiftExtraction.dsp_min_scale ${feature_extractor_SiftExtraction_dsp_min_scale} \
|
| 104 |
+
--SiftExtraction.dsp_max_scale ${feature_extractor_SiftExtraction_dsp_max_scale} \
|
| 105 |
+
--SiftExtraction.dsp_num_scales ${feature_extractor_SiftExtraction_dsp_num_scales}
|
| 106 |
+
fi
|
| 107 |
+
|
| 108 |
+
if [ "${calibration_model}" == "OPENCV" ]
|
| 109 |
+
then
|
| 110 |
+
echo " camera model : $calibration_model"
|
| 111 |
+
colmap feature_extractor \
|
| 112 |
+
--database_path ${database} \
|
| 113 |
+
--image_path ${rgb_path} \
|
| 114 |
+
--image_list_path ${colmap_image_list} \
|
| 115 |
+
--ImageReader.camera_model ${calibration_model} \
|
| 116 |
+
--ImageReader.single_camera 1 \
|
| 117 |
+
--ImageReader.single_camera_per_folder 1 \
|
| 118 |
+
--SiftExtraction.use_gpu ${use_gpu} \
|
| 119 |
+
--ImageReader.camera_params "${fx}, ${fy}, ${cx}, ${cy}, ${k1}, ${k2}, ${p1}, ${p2}" \
|
| 120 |
+
--SiftExtraction.num_octaves ${feature_extractor_SiftExtraction_num_octaves} \
|
| 121 |
+
--SiftExtraction.octave_resolution ${feature_extractor_SiftExtraction_octave_resolution} \
|
| 122 |
+
--SiftExtraction.peak_threshold ${feature_extractor_SiftExtraction_peak_threshold} \
|
| 123 |
+
--SiftExtraction.edge_threshold ${feature_extractor_SiftExtraction_edge_threshold} \
|
| 124 |
+
--SiftExtraction.dsp_min_scale ${feature_extractor_SiftExtraction_dsp_min_scale} \
|
| 125 |
+
--SiftExtraction.dsp_max_scale ${feature_extractor_SiftExtraction_dsp_max_scale} \
|
| 126 |
+
--SiftExtraction.dsp_num_scales ${feature_extractor_SiftExtraction_dsp_num_scales}
|
| 127 |
+
fi
|
| 128 |
+
|
| 129 |
+
if [ "${calibration_model}" == "OPENCV_FISHEYE" ]
|
| 130 |
+
then
|
| 131 |
+
echo " camera model : $calibration_model"
|
| 132 |
+
colmap feature_extractor \
|
| 133 |
+
--database_path ${database} \
|
| 134 |
+
--image_path ${rgb_path} \
|
| 135 |
+
--image_list_path ${colmap_image_list} \
|
| 136 |
+
--ImageReader.camera_model ${calibration_model} \
|
| 137 |
+
--ImageReader.single_camera 1 \
|
| 138 |
+
--ImageReader.single_camera_per_folder 1 \
|
| 139 |
+
--SiftExtraction.use_gpu ${use_gpu} \
|
| 140 |
+
--ImageReader.camera_params "${fx}, ${fy}, ${cx}, ${cy}, ${k1}, ${k2}, ${k3}, ${k4}" \
|
| 141 |
+
--SiftExtraction.num_octaves ${feature_extractor_SiftExtraction_num_octaves} \
|
| 142 |
+
--SiftExtraction.octave_resolution ${feature_extractor_SiftExtraction_octave_resolution} \
|
| 143 |
+
--SiftExtraction.peak_threshold ${feature_extractor_SiftExtraction_peak_threshold} \
|
| 144 |
+
--SiftExtraction.edge_threshold ${feature_extractor_SiftExtraction_edge_threshold} \
|
| 145 |
+
--SiftExtraction.dsp_min_scale ${feature_extractor_SiftExtraction_dsp_min_scale} \
|
| 146 |
+
--SiftExtraction.dsp_max_scale ${feature_extractor_SiftExtraction_dsp_max_scale} \
|
| 147 |
+
--SiftExtraction.dsp_num_scales ${feature_extractor_SiftExtraction_dsp_num_scales}
|
| 148 |
+
fi
|
| 149 |
+
|
| 150 |
+
################################################################################
|
| 151 |
+
if [ "${matcher_type}" == "exhaustive" ]
|
| 152 |
+
then
|
| 153 |
+
echo " colmap exhaustive_matcher ..."
|
| 154 |
+
colmap exhaustive_matcher \
|
| 155 |
+
--database_path ${database} \
|
| 156 |
+
--SiftMatching.use_gpu ${use_gpu} \
|
| 157 |
+
--SiftMatching.max_ratio "${matcher_SiftMatching_max_ratio}" \
|
| 158 |
+
--SiftMatching.max_distance "${matcher_SiftMatching_max_distance}" \
|
| 159 |
+
--TwoViewGeometry.min_num_inliers "${matcher_TwoViewGeometry_min_num_inliers}" \
|
| 160 |
+
--TwoViewGeometry.max_error "${matcher_TwoViewGeometry_max_error}" \
|
| 161 |
+
--TwoViewGeometry.confidence "${matcher_TwoViewGeometry_confidence}" \
|
| 162 |
+
--TwoViewGeometry.min_inlier_ratio "${matcher_TwoViewGeometry_min_inlier_ratio}" \
|
| 163 |
+
--ExhaustiveMatching.block_size "${matcher_ExhaustiveMatching_block_size}"
|
| 164 |
+
|
| 165 |
+
fi
|
| 166 |
+
|
| 167 |
+
if [ "${matcher_type}" == "sequential" ]
|
| 168 |
+
then
|
| 169 |
+
num_rgb=$(wc -l < ${rgb_txt})
|
| 170 |
+
|
| 171 |
+
# Pick vocabulary tree based on the number of images
|
| 172 |
+
vocabulary_tree="Baselines/glomap/vocab_tree_flickr100K_words32K.bin"
|
| 173 |
+
if [ "$num_rgb" -gt 1000 ]; then
|
| 174 |
+
vocabulary_tree="Baselines/glomap/vocab_tree_flickr100K_words256K.bin"
|
| 175 |
+
fi
|
| 176 |
+
if [ "$num_rgb" -gt 10000 ]; then
|
| 177 |
+
vocabulary_tree="Baselines/glomap/vocab_tree_flickr100K_words1M.bin"
|
| 178 |
+
fi
|
| 179 |
+
|
| 180 |
+
echo " colmap sequential_matcher ..."
|
| 181 |
+
echo " Vocabulary Tree: $vocabulary_tree"
|
| 182 |
+
colmap sequential_matcher \
|
| 183 |
+
--database_path "${database}" \
|
| 184 |
+
--SequentialMatching.loop_detection 1 \
|
| 185 |
+
--SequentialMatching.vocab_tree_path ${vocabulary_tree} \
|
| 186 |
+
--SiftMatching.use_gpu "${use_gpu}" \
|
| 187 |
+
--SiftMatching.max_ratio "${matcher_SiftMatching_max_ratio}" \
|
| 188 |
+
--SiftMatching.max_distance "${matcher_SiftMatching_max_distance}" \
|
| 189 |
+
--TwoViewGeometry.min_num_inliers "${matcher_TwoViewGeometry_min_num_inliers}" \
|
| 190 |
+
--TwoViewGeometry.max_error "${matcher_TwoViewGeometry_max_error}" \
|
| 191 |
+
--TwoViewGeometry.confidence "${matcher_TwoViewGeometry_confidence}" \
|
| 192 |
+
--TwoViewGeometry.min_inlier_ratio "${matcher_TwoViewGeometry_min_inlier_ratio}" \
|
| 193 |
+
--SequentialMatching.overlap "${matcher_SequentialMatching_overlap}" \
|
| 194 |
+
--SequentialMatching.quadratic_overlap "${matcher_SequentialMatching_quadratic_overlap}"
|
| 195 |
+
fi
|