update: first auxiliary files
Browse files- .gitignore +3 -0
- colmap_mapper.sh +43 -0
- colmap_matcher.sh +144 -0
- colmap_reconstruction.sh +69 -0
- colmap_to_vslamlab.py +102 -0
- create_colmap_image_list.py +21 -0
- get_calibration.py +33 -0
- vslamlab_colmap_settings.yaml +79 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
vocab_tree_flickr100K_words1M.bin
|
| 2 |
+
vocab_tree_flickr100K_words256K.bin
|
| 3 |
+
vocab_tree_flickr100K_words32K.bin
|
colmap_mapper.sh
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
echo "Executing colmap_mapper.sh ..."
|
| 3 |
+
|
| 4 |
+
sequence_path="$1"
|
| 5 |
+
exp_folder="$2"
|
| 6 |
+
exp_id="$3"
|
| 7 |
+
settings_yaml="$4"
|
| 8 |
+
calibration_yaml="$5"
|
| 9 |
+
rgb_csv="$6"
|
| 10 |
+
camera_name="$7"
|
| 11 |
+
|
| 12 |
+
exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
|
| 13 |
+
rgb_dir="${camera_name}"
|
| 14 |
+
rgb_path="${sequence_path}/${rgb_dir}"
|
| 15 |
+
|
| 16 |
+
read -r calibration_model more_ <<< $(python3 Baselines/colmap/get_calibration.py "$calibration_yaml" "$camera_name")
|
| 17 |
+
echo " camera model : $calibration_model"
|
| 18 |
+
ba_refine_focal_length="0"
|
| 19 |
+
ba_refine_principal_point="0"
|
| 20 |
+
ba_refine_extra_params="0"
|
| 21 |
+
if [ "${calibration_model}" == "unknown" ]
|
| 22 |
+
then
|
| 23 |
+
ba_refine_focal_length="1"
|
| 24 |
+
ba_refine_principal_point="1"
|
| 25 |
+
ba_refine_extra_params="1"
|
| 26 |
+
fi
|
| 27 |
+
|
| 28 |
+
echo " colmap mapper ..."
|
| 29 |
+
database="${exp_folder_colmap}/colmap_database.db"
|
| 30 |
+
|
| 31 |
+
colmap mapper \
|
| 32 |
+
--database_path ${database} \
|
| 33 |
+
--image_path ${rgb_path} \
|
| 34 |
+
--output_path ${exp_folder_colmap} \
|
| 35 |
+
--Mapper.ba_refine_focal_length ${ba_refine_focal_length} \
|
| 36 |
+
--Mapper.ba_refine_principal_point ${ba_refine_principal_point} \
|
| 37 |
+
--Mapper.ba_refine_extra_params ${ba_refine_extra_params}
|
| 38 |
+
|
| 39 |
+
echo " colmap model_converter ..."
|
| 40 |
+
colmap model_converter \
|
| 41 |
+
--input_path ${exp_folder_colmap}/0 --output_path ${exp_folder_colmap} --output_type TXT
|
| 42 |
+
|
| 43 |
+
|
colmap_matcher.sh
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
echo ""
|
| 3 |
+
echo "Executing colmap_matcher.sh ..."
|
| 4 |
+
|
| 5 |
+
sequence_path="$1"
|
| 6 |
+
exp_folder="$2"
|
| 7 |
+
exp_id="$3"
|
| 8 |
+
settings_yaml="$4"
|
| 9 |
+
calibration_yaml="$5"
|
| 10 |
+
rgb_csv="$6"
|
| 11 |
+
matcher_type="$7"
|
| 12 |
+
use_gpu="$8"
|
| 13 |
+
camera_name="$9"
|
| 14 |
+
|
| 15 |
+
exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
|
| 16 |
+
rgb_dir=$(awk -F, 'NR==2 { split($2,a,"/"); print a[1]; exit }' "$rgb_csv")
|
| 17 |
+
rgb_path="${sequence_path}/${rgb_dir}"
|
| 18 |
+
|
| 19 |
+
# Get calibration model
|
| 20 |
+
read -r calibration_model more_ <<< $(python3 Baselines/colmap/get_calibration.py "$calibration_yaml" "$camera_name")
|
| 21 |
+
|
| 22 |
+
# Create colmap image list
|
| 23 |
+
colmap_image_list="${exp_folder_colmap}/colmap_image_list.txt"
|
| 24 |
+
python3 Baselines/colmap/create_colmap_image_list.py "$rgb_csv" "$colmap_image_list" "$camera_name"
|
| 25 |
+
|
| 26 |
+
# Create Colmap Database
|
| 27 |
+
database="${exp_folder_colmap}/colmap_database.db"
|
| 28 |
+
rm -rf ${database}
|
| 29 |
+
colmap database_creator --database_path ${database}
|
| 30 |
+
|
| 31 |
+
# Feature extractor
|
| 32 |
+
echo " colmap feature_extractor ..."
|
| 33 |
+
|
| 34 |
+
if [ "${calibration_model}" == "unknown" ]
|
| 35 |
+
then
|
| 36 |
+
echo " camera model : $calibration_model"
|
| 37 |
+
colmap feature_extractor \
|
| 38 |
+
--database_path ${database} \
|
| 39 |
+
--image_path ${rgb_path} \
|
| 40 |
+
--image_list_path ${colmap_image_list} \
|
| 41 |
+
--ImageReader.camera_model SIMPLE_PINHOLE \
|
| 42 |
+
--ImageReader.single_camera 1 \
|
| 43 |
+
--ImageReader.single_camera_per_folder 1 \
|
| 44 |
+
--FeatureExtraction.use_gpu ${use_gpu}
|
| 45 |
+
fi
|
| 46 |
+
|
| 47 |
+
if [ "${calibration_model}" == "pinhole" ]
|
| 48 |
+
then
|
| 49 |
+
read -r calibration_model fx fy cx cy <<< $(python3 Baselines/colmap/get_calibration.py "$calibration_yaml" "$camera_name")
|
| 50 |
+
echo " camera model : $calibration_model"
|
| 51 |
+
echo " fx: $fx , fy: $fy , cx: $cx , cy: $cy"
|
| 52 |
+
colmap feature_extractor \
|
| 53 |
+
--database_path ${database} \
|
| 54 |
+
--image_path ${rgb_path} \
|
| 55 |
+
--image_list_path ${colmap_image_list} \
|
| 56 |
+
--ImageReader.camera_model PINHOLE \
|
| 57 |
+
--ImageReader.single_camera 1 \
|
| 58 |
+
--ImageReader.single_camera_per_folder 1 \
|
| 59 |
+
--FeatureExtraction.use_gpu ${use_gpu} \
|
| 60 |
+
--ImageReader.camera_params "${fx},${fy},${cx},${cy}"
|
| 61 |
+
fi
|
| 62 |
+
|
| 63 |
+
if [ "${calibration_model}" == "radtan4" ]
|
| 64 |
+
then
|
| 65 |
+
read -r calibration_model fx fy cx cy k1 k2 p1 p2 <<< $(python3 Baselines/colmap/get_calibration.py "$calibration_yaml" "$camera_name")
|
| 66 |
+
echo " camera model : $calibration_model"
|
| 67 |
+
echo " fx: $fx , fy: $fy , cx: $cx , cy: $cy"
|
| 68 |
+
echo " k1: $k1 , k2: $k2 , p1: $p1 , p2: $p2"
|
| 69 |
+
colmap feature_extractor \
|
| 70 |
+
--database_path ${database} \
|
| 71 |
+
--image_path ${rgb_path} \
|
| 72 |
+
--image_list_path ${colmap_image_list} \
|
| 73 |
+
--ImageReader.camera_model "OPENCV" \
|
| 74 |
+
--ImageReader.single_camera 1 \
|
| 75 |
+
--ImageReader.single_camera_per_folder 1 \
|
| 76 |
+
--FeatureExtraction.use_gpu ${use_gpu} \
|
| 77 |
+
--ImageReader.camera_params "${fx},${fy},${cx},${cy},${k1},${k2},${p1},${p2}"
|
| 78 |
+
fi
|
| 79 |
+
|
| 80 |
+
if [ "${calibration_model}" == "radtan5" ]
|
| 81 |
+
then
|
| 82 |
+
read -r calibration_model fx fy cx cy k1 k2 p1 p2 k3 <<< $(python3 Baselines/colmap/get_calibration.py "$calibration_yaml" "$camera_name")
|
| 83 |
+
echo " camera model : $calibration_model"
|
| 84 |
+
echo " fx: $fx , fy: $fy , cx: $cx , cy: $cy"
|
| 85 |
+
echo " k1: $k1 , k2: $k2 , p1: $p1 , p2: $p2, k3: $k3"
|
| 86 |
+
colmap feature_extractor \
|
| 87 |
+
--database_path ${database} \
|
| 88 |
+
--image_path ${rgb_path} \
|
| 89 |
+
--image_list_path ${colmap_image_list} \
|
| 90 |
+
--ImageReader.camera_model "FULL_OPENCV" \
|
| 91 |
+
--ImageReader.single_camera 1 \
|
| 92 |
+
--ImageReader.single_camera_per_folder 1 \
|
| 93 |
+
--FeatureExtraction.use_gpu ${use_gpu} \
|
| 94 |
+
--ImageReader.camera_params "${fx},${fy},${cx},${cy},${k1},${k2},${p1},${p2},${k3},0,0,0"
|
| 95 |
+
fi
|
| 96 |
+
|
| 97 |
+
if [ "${calibration_model}" == "equid4" ]
|
| 98 |
+
then
|
| 99 |
+
read -r calibration_model fx fy cx cy k1 k2 k3 k4 <<< $(python3 Baselines/colmap/get_calibration.py "$calibration_yaml" "$camera_name")
|
| 100 |
+
echo " camera model : $calibration_model"
|
| 101 |
+
echo " fx: $fx , fy: $fy , cx: $cx , cy: $cy"
|
| 102 |
+
echo " k1: $k1 , k2: $k2 , k3: $k3 , k4: $k4"
|
| 103 |
+
colmap feature_extractor \
|
| 104 |
+
--database_path ${database} \
|
| 105 |
+
--image_path ${rgb_path} \
|
| 106 |
+
--image_list_path ${colmap_image_list} \
|
| 107 |
+
--ImageReader.camera_model "OPENCV_FISHEYE"\
|
| 108 |
+
--ImageReader.single_camera 1 \
|
| 109 |
+
--ImageReader.single_camera_per_folder 1 \
|
| 110 |
+
--FeatureExtraction.use_gpu ${use_gpu} \
|
| 111 |
+
--ImageReader.camera_params "${fx},${fy},${cx},${cy},${k1},${k2},${k3},${k4}"
|
| 112 |
+
fi
|
| 113 |
+
|
| 114 |
+
# Exhaustive Feature Matcher
|
| 115 |
+
if [ "${matcher_type}" == "exhaustive" ]
|
| 116 |
+
then
|
| 117 |
+
echo " colmap exhaustive_matcher ..."
|
| 118 |
+
colmap exhaustive_matcher \
|
| 119 |
+
--database_path ${database} \
|
| 120 |
+
--FeatureMatching.use_gpu ${use_gpu}
|
| 121 |
+
fi
|
| 122 |
+
|
| 123 |
+
# Sequential Feature Matcher
|
| 124 |
+
if [ "${matcher_type}" == "sequential" ]
|
| 125 |
+
then
|
| 126 |
+
num_rgb=$(( $(wc -l < "$rgb_csv") - 1 ))
|
| 127 |
+
|
| 128 |
+
# Pick vocabulary tree based on the number of images
|
| 129 |
+
vocabulary_tree="Baselines/colmap/vocab_tree_flickr100K_words32K.bin"
|
| 130 |
+
if [ "$num_rgb" -gt 1000 ]; then
|
| 131 |
+
vocabulary_tree="Baselines/colmap/vocab_tree_flickr100K_words256K.bin"
|
| 132 |
+
fi
|
| 133 |
+
if [ "$num_rgb" -gt 10000 ]; then
|
| 134 |
+
vocabulary_tree="Baselines/colmap/vocab_tree_flickr100K_words1M.bin"
|
| 135 |
+
fi
|
| 136 |
+
|
| 137 |
+
echo " colmap sequential_matcher ..."
|
| 138 |
+
echo " Vocabulary Tree: $vocabulary_tree"
|
| 139 |
+
colmap sequential_matcher \
|
| 140 |
+
--database_path "${database}" \
|
| 141 |
+
--SequentialMatching.loop_detection 1 \
|
| 142 |
+
--SequentialMatching.vocab_tree_path ${vocabulary_tree} \
|
| 143 |
+
--FeatureMatching.use_gpu "${use_gpu}"
|
| 144 |
+
fi
|
colmap_reconstruction.sh
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Default values
|
| 4 |
+
matcher_type="exhaustive"
|
| 5 |
+
use_gpu="1"
|
| 6 |
+
verbose="0"
|
| 7 |
+
settings_yaml=""
|
| 8 |
+
sequence_path=""
|
| 9 |
+
exp_folder=""
|
| 10 |
+
exp_id=""
|
| 11 |
+
calibration_yaml=""
|
| 12 |
+
rgb_csv=""
|
| 13 |
+
camera_name="rgb_0"
|
| 14 |
+
|
| 15 |
+
# Function to split key-value pairs and assign them to variables
|
| 16 |
+
split_and_assign() {
|
| 17 |
+
local input=$1
|
| 18 |
+
local key=$(echo $input | cut -d':' -f1)
|
| 19 |
+
local value=$(echo $input | cut -d':' -f2-)
|
| 20 |
+
eval $key=$value
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# Read Inputs
|
| 24 |
+
for ((i=1; i<=$#; i++)); do
|
| 25 |
+
split_and_assign "${!i}"
|
| 26 |
+
done
|
| 27 |
+
|
| 28 |
+
exp_id=$(printf "%05d" ${exp_id})
|
| 29 |
+
|
| 30 |
+
echo -e "\n================= Experiment Configuration ================="
|
| 31 |
+
echo " Sequence Path : $sequence_path"
|
| 32 |
+
echo " Experiment Folder : $exp_folder"
|
| 33 |
+
echo " Experiment ID : $exp_id"
|
| 34 |
+
echo " Verbose : $verbose"
|
| 35 |
+
echo " Matcher Type : $matcher_type"
|
| 36 |
+
echo " Use GPU : $use_gpu"
|
| 37 |
+
echo " Settings YAML : $settings_yaml"
|
| 38 |
+
echo " Calibration YAML : $calibration_yaml"
|
| 39 |
+
echo " RGB CSV : $rgb_csv"
|
| 40 |
+
echo " Camera Name : $camera_name"
|
| 41 |
+
echo "============================================================"
|
| 42 |
+
|
| 43 |
+
# Create folder to save colmap files
|
| 44 |
+
exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
|
| 45 |
+
rm -rf "$exp_folder_colmap"
|
| 46 |
+
mkdir "$exp_folder_colmap"
|
| 47 |
+
|
| 48 |
+
# Run COLMAP scripts for matching and mapping
|
| 49 |
+
export QT_QPA_PLATFORM_PLUGIN_PATH="$CONDA_PREFIX/plugins/platforms"
|
| 50 |
+
colmap_args="$sequence_path $exp_folder $exp_id $settings_yaml $calibration_yaml $rgb_csv"
|
| 51 |
+
./Baselines/colmap/colmap_matcher.sh $colmap_args $matcher_type $use_gpu $camera_name
|
| 52 |
+
./Baselines/colmap/colmap_mapper.sh $colmap_args $camera_name
|
| 53 |
+
|
| 54 |
+
# Convert COLMAP outputs to a format suitable for VSLAM-LAB
|
| 55 |
+
python Baselines/colmap/colmap_to_vslamlab.py $sequence_path $exp_folder $exp_id $verbose $rgb_csv $camera_name
|
| 56 |
+
|
| 57 |
+
# Visualization with colmap gui
|
| 58 |
+
if [ "$verbose" -eq 1 ]; then
|
| 59 |
+
exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
|
| 60 |
+
rgb_dir=$(awk -F, 'NR==2 { split($2,a,"/"); print a[1]; exit }' "$rgb_csv")
|
| 61 |
+
rgb_path="${sequence_path}/${rgb_dir}"
|
| 62 |
+
database="${exp_folder_colmap}/colmap_database.db"
|
| 63 |
+
colmap gui --import_path "${exp_folder_colmap}/0" --database_path ${database} --image_path ${rgb_path}
|
| 64 |
+
fi
|
| 65 |
+
|
| 66 |
+
# # Remove colmap data
|
| 67 |
+
# rm -rf ${exp_folder_colmap}
|
| 68 |
+
|
| 69 |
+
|
colmap_to_vslamlab.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from scipy.spatial.transform import Rotation as R
|
| 3 |
+
import sys
|
| 4 |
+
import os
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
def get_colmap_keyframes(images_file, number_of_header_lines, verbose=False):
|
| 8 |
+
print(f"get_colmap_keyframes: {images_file}")
|
| 9 |
+
|
| 10 |
+
image_id = []
|
| 11 |
+
q_wc_xyzw = []
|
| 12 |
+
t_wc = []
|
| 13 |
+
|
| 14 |
+
with open(f"{images_file}", 'r') as file:
|
| 15 |
+
# Skip the header lines
|
| 16 |
+
for _ in range(number_of_header_lines):
|
| 17 |
+
file.readline()
|
| 18 |
+
|
| 19 |
+
while True:
|
| 20 |
+
line1 = file.readline()
|
| 21 |
+
if not line1:
|
| 22 |
+
break
|
| 23 |
+
elements = line1.split()
|
| 24 |
+
|
| 25 |
+
IMAGE_ID = int(elements[0])
|
| 26 |
+
image_id.append(IMAGE_ID)
|
| 27 |
+
|
| 28 |
+
QW = float(elements[1])
|
| 29 |
+
QX = float(elements[2])
|
| 30 |
+
QY = float(elements[3])
|
| 31 |
+
QZ = float(elements[4])
|
| 32 |
+
|
| 33 |
+
TX = float(elements[5])
|
| 34 |
+
TY = float(elements[6])
|
| 35 |
+
TZ = float(elements[7])
|
| 36 |
+
|
| 37 |
+
t_cw_i = np.array([TX, TY, TZ])
|
| 38 |
+
q_wc_i = R.from_quat([QX, QY, QZ, QW]).inv()
|
| 39 |
+
R_wc_i = q_wc_i.as_matrix()
|
| 40 |
+
|
| 41 |
+
q_wc_xyzw.append([q_wc_i.as_quat()[0], q_wc_i.as_quat()[1], q_wc_i.as_quat()[2], q_wc_i.as_quat()[3]])
|
| 42 |
+
t_wc.append(-R_wc_i @ t_cw_i)
|
| 43 |
+
|
| 44 |
+
file.readline()
|
| 45 |
+
|
| 46 |
+
image_id = np.array(image_id)
|
| 47 |
+
q_wc_xyzw = np.array(q_wc_xyzw)
|
| 48 |
+
t_wc = np.array(t_wc)
|
| 49 |
+
|
| 50 |
+
sorted_indices = image_id.argsort()
|
| 51 |
+
image_id = image_id[sorted_indices]
|
| 52 |
+
q_wc_xyzw = q_wc_xyzw[sorted_indices]
|
| 53 |
+
t_wc = t_wc[sorted_indices]
|
| 54 |
+
|
| 55 |
+
q_wc_xyzw_corrected = q_wc_xyzw.copy()
|
| 56 |
+
for i in range(1, len(q_wc_xyzw_corrected)):
|
| 57 |
+
dot_product = np.dot(q_wc_xyzw_corrected[i - 1], q_wc_xyzw_corrected[i])
|
| 58 |
+
if dot_product < 0:
|
| 59 |
+
q_wc_xyzw_corrected[i] = -q_wc_xyzw_corrected[i]
|
| 60 |
+
|
| 61 |
+
return image_id, t_wc, q_wc_xyzw_corrected
|
| 62 |
+
|
| 63 |
+
def write_trajectory_tum_format(file_name, image_ts, t_wc, q_wc_xyzw):
|
| 64 |
+
print(f"writeTrajectoryTUMformat: {file_name}")
|
| 65 |
+
|
| 66 |
+
data = np.hstack((image_ts.reshape(-1, 1), t_wc, q_wc_xyzw))
|
| 67 |
+
data = data[data[:, 0].argsort()]
|
| 68 |
+
|
| 69 |
+
with open(file_name, 'w', newline='') as file:
|
| 70 |
+
file.write('ts (ns),tx (m),ty (m),tz (m),qx,qy,qz,qw\n')
|
| 71 |
+
for row in data:
|
| 72 |
+
file.write(','.join(f'{x:.15f}' for x in row) + '\n')
|
| 73 |
+
|
| 74 |
+
def get_timestamps(files_path, rgb_file, camera_name):
|
| 75 |
+
print(f"getTimestamps: {os.path.join(files_path, rgb_file)}")
|
| 76 |
+
df = pd.read_csv(rgb_file)
|
| 77 |
+
ts = df[f'ts_{camera_name} (ns)'].to_list()
|
| 78 |
+
return ts
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
|
| 82 |
+
sequence_path = sys.argv[1]
|
| 83 |
+
exp_folder = sys.argv[2]
|
| 84 |
+
exp_id = sys.argv[3]
|
| 85 |
+
verbose = bool(int(sys.argv[4]))
|
| 86 |
+
rgb_file = sys.argv[5]
|
| 87 |
+
camera_name = sys.argv[6]
|
| 88 |
+
|
| 89 |
+
images_file = os.path.join(exp_folder, f'colmap_{exp_id}', 'images.txt')
|
| 90 |
+
|
| 91 |
+
number_of_header_lines = 4
|
| 92 |
+
image_id, t_wc, q_wc_xyzw = get_colmap_keyframes(images_file, number_of_header_lines, verbose)
|
| 93 |
+
|
| 94 |
+
image_ts = np.array(get_timestamps(sequence_path, rgb_file, camera_name))
|
| 95 |
+
timestamps = []
|
| 96 |
+
for id in image_id:
|
| 97 |
+
timestamps.append(float(image_ts[id-1]))
|
| 98 |
+
|
| 99 |
+
timestamps = np.array(timestamps)
|
| 100 |
+
|
| 101 |
+
keyFrameTrajectory_txt = os.path.join(exp_folder, exp_id + '_KeyFrameTrajectory' + '.csv')
|
| 102 |
+
write_trajectory_tum_format(keyFrameTrajectory_txt, timestamps, t_wc, q_wc_xyzw)
|
create_colmap_image_list.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
+
def create_colmap_image_list(rgb_csv, colmap_image_list_txt, cam_name):
|
| 5 |
+
|
| 6 |
+
df = pd.read_csv(rgb_csv)
|
| 7 |
+
image_list = df[f'path_{cam_name}'].to_list()
|
| 8 |
+
|
| 9 |
+
with open(colmap_image_list_txt, 'w') as f:
|
| 10 |
+
for name in image_list:
|
| 11 |
+
file_name = os.path.basename(name)
|
| 12 |
+
f.write(f"{file_name}\n")
|
| 13 |
+
|
| 14 |
+
if __name__ == "__main__":
|
| 15 |
+
parser = argparse.ArgumentParser()
|
| 16 |
+
parser.add_argument("rgb_csv", help="Path to the rgb_csv")
|
| 17 |
+
parser.add_argument("colmap_image_list", help="Path to the colmap_image_list")
|
| 18 |
+
parser.add_argument("camera_name", help="camera_name")
|
| 19 |
+
|
| 20 |
+
args = parser.parse_args()
|
| 21 |
+
create_colmap_image_list(args.rgb_csv, args.colmap_image_list, args.camera_name)
|
get_calibration.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import yaml
|
| 2 |
+
import sys
|
| 3 |
+
import argparse
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
def get_camera_intrinsics(calibration_yaml, cam_name):
|
| 7 |
+
with open(calibration_yaml, 'r') as file:
|
| 8 |
+
data = yaml.safe_load(file)
|
| 9 |
+
cameras = data.get('cameras', [])
|
| 10 |
+
for cam_ in cameras:
|
| 11 |
+
if cam_['cam_name'] == cam_name:
|
| 12 |
+
cam = cam_;
|
| 13 |
+
break;
|
| 14 |
+
|
| 15 |
+
has_dist = ('distortion_type' in cam) and ('distortion_coefficients' in cam)
|
| 16 |
+
K = np.array([[cam['focal_length'][0], 0, cam['principal_point'][0]],
|
| 17 |
+
[0, cam['focal_length'][1], cam['principal_point'][1]],
|
| 18 |
+
[0, 0, 1]], dtype=np.float32)
|
| 19 |
+
|
| 20 |
+
if has_dist:
|
| 21 |
+
dist= " ".join(map(str, cam['distortion_coefficients']))
|
| 22 |
+
print(f"{cam['distortion_type']} {K[0,0]} {K[1,1]} {K[0,2]} {K[1,2]} {dist}")
|
| 23 |
+
else:
|
| 24 |
+
print(f"{cam['cam_model']} {K[0,0]} {K[1,1]} {K[0,2]} {K[1,2]}")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
parser = argparse.ArgumentParser()
|
| 29 |
+
parser.add_argument("calibration_yaml", help="Path to the calibration YAML")
|
| 30 |
+
parser.add_argument("camera_name", help="camera_name")
|
| 31 |
+
args = parser.parse_args()
|
| 32 |
+
|
| 33 |
+
get_camera_intrinsics(args.calibration_yaml, args.camera_name)
|
vslamlab_colmap_settings.yaml
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
feature_extractor:
|
| 2 |
+
SiftExtraction_num_octaves: 4
|
| 3 |
+
SiftExtraction_octave_resolution: 3
|
| 4 |
+
SiftExtraction_peak_threshold: 0.0066666666666666671
|
| 5 |
+
SiftExtraction_edge_threshold: 10.0
|
| 6 |
+
SiftExtraction_dsp_min_scale: 0.1666666666666666
|
| 7 |
+
SiftExtraction_dsp_max_scale: 3.0
|
| 8 |
+
SiftExtraction_dsp_num_scales: 10
|
| 9 |
+
|
| 10 |
+
matcher:
|
| 11 |
+
SiftMatching_max_ratio: 0.80000000000000004
|
| 12 |
+
SiftMatching_max_distance: 0.69999999999999996
|
| 13 |
+
TwoViewGeometry_min_num_inliers: 15
|
| 14 |
+
TwoViewGeometry_max_error: 4.0
|
| 15 |
+
TwoViewGeometry_confidence: 0.999
|
| 16 |
+
TwoViewGeometry_min_inlier_ratio: 0.25
|
| 17 |
+
SequentialMatching_overlap: 10
|
| 18 |
+
SequentialMatching_quadratic_overlap: 1
|
| 19 |
+
ExhaustiveMatching_block_size: 50
|
| 20 |
+
|
| 21 |
+
mapper:
|
| 22 |
+
Mapper_min_num_matches: 15
|
| 23 |
+
Mapper_ignore_watermarks: 0
|
| 24 |
+
Mapper_multiple_models: 1
|
| 25 |
+
Mapper_max_num_models: 50
|
| 26 |
+
Mapper_max_model_overlap: 20
|
| 27 |
+
Mapper_min_model_size: 10
|
| 28 |
+
Mapper_init_image_id1: -1
|
| 29 |
+
Mapper_init_image_id2: -1
|
| 30 |
+
Mapper_init_num_trials: 200
|
| 31 |
+
Mapper_extract_colors: 1
|
| 32 |
+
Mapper_num_threads: -1
|
| 33 |
+
Mapper_min_focal_length_ratio: 0.10000000000000001
|
| 34 |
+
Mapper_max_focal_length_ratio: 10
|
| 35 |
+
Mapper_max_extra_param: 1
|
| 36 |
+
Mapper_ba_refine_focal_length: 1
|
| 37 |
+
Mapper_ba_refine_principal_point: 0
|
| 38 |
+
Mapper_ba_refine_extra_params: 1
|
| 39 |
+
Mapper_ba_local_num_images: 6
|
| 40 |
+
Mapper_ba_local_function_tolerance: 0
|
| 41 |
+
Mapper_ba_local_max_num_iterations: 25
|
| 42 |
+
Mapper_ba_global_images_ratio: 1.1000000000000001
|
| 43 |
+
Mapper_ba_global_points_ratio: 1.1000000000000001
|
| 44 |
+
Mapper_ba_global_images_freq: 500
|
| 45 |
+
Mapper_ba_global_points_freq: 250000
|
| 46 |
+
Mapper_ba_global_function_tolerance: 0
|
| 47 |
+
Mapper_ba_global_max_num_iterations: 50
|
| 48 |
+
Mapper_ba_global_max_refinements: 5
|
| 49 |
+
Mapper_ba_global_max_refinement_change: 0.00050000000000000001
|
| 50 |
+
Mapper_ba_local_max_refinements: 2
|
| 51 |
+
Mapper_ba_local_max_refinement_change: 0.001
|
| 52 |
+
Mapper_ba_use_gpu: 0
|
| 53 |
+
Mapper_ba_gpu_index: -1
|
| 54 |
+
Mapper_ba_min_num_residuals_for_cpu_multi_threading: 50000
|
| 55 |
+
Mapper_snapshot_images_freq: 0
|
| 56 |
+
Mapper_fix_existing_images: 0
|
| 57 |
+
Mapper_init_min_num_inliers: 100
|
| 58 |
+
Mapper_init_max_error: 4
|
| 59 |
+
Mapper_init_max_forward_motion: 0.94999999999999996
|
| 60 |
+
Mapper_init_min_tri_angle: 16
|
| 61 |
+
Mapper_init_max_reg_trials: 2
|
| 62 |
+
Mapper_abs_pose_max_error: 12
|
| 63 |
+
Mapper_abs_pose_min_num_inliers: 30
|
| 64 |
+
Mapper_abs_pose_min_inlier_ratio: 0.25
|
| 65 |
+
Mapper_filter_max_reproj_error: 4
|
| 66 |
+
Mapper_filter_min_tri_angle: 1.5
|
| 67 |
+
Mapper_max_reg_trials: 3
|
| 68 |
+
Mapper_local_ba_min_tri_angle: 6
|
| 69 |
+
Mapper_tri_max_transitivity: 1
|
| 70 |
+
Mapper_tri_create_max_angle_error: 2
|
| 71 |
+
Mapper_tri_continue_max_angle_error: 2
|
| 72 |
+
Mapper_tri_merge_max_reproj_error: 4
|
| 73 |
+
Mapper_tri_complete_max_reproj_error: 4
|
| 74 |
+
Mapper_tri_complete_max_transitivity: 5
|
| 75 |
+
Mapper_tri_re_max_angle_error: 5
|
| 76 |
+
Mapper_tri_re_min_ratio: 0.20000000000000001
|
| 77 |
+
Mapper_tri_re_max_trials: 1
|
| 78 |
+
Mapper_tri_min_angle: 1.5
|
| 79 |
+
Mapper_tri_ignore_two_view_tracks: 1
|