fontan commited on
Commit
d7e30ae
·
1 Parent(s): c9607fd

vslamlab integration

Browse files
colmap_mapper.sh CHANGED
@@ -6,12 +6,13 @@ exp_folder="$2"
6
  exp_id="$3"
7
  settings_yaml="$4"
8
  calibration_yaml="$5"
9
- rgb_txt="$6"
10
 
11
  exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
12
- rgb_path="${sequence_path}/$(awk '{print $2}' "${rgb_txt}" | awk -F'/' 'NR==1 {print $1}')"
 
13
 
14
- calibration_model=$(grep -oP '(?<=Camera\.model:\s)[\w]+' "$calibration_yaml")
15
  echo " camera model : $calibration_model"
16
 
17
  # Reading settings from yaml file
 
6
  exp_id="$3"
7
  settings_yaml="$4"
8
  calibration_yaml="$5"
9
+ rgb_csv="$6"
10
 
11
  exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
12
+ rgb_dir=$(awk -F, 'NR==2 { split($2,a,"/"); print a[1]; exit }' "$rgb_csv")
13
+ rgb_path="${sequence_path}/${rgb_dir}"
14
 
15
+ calibration_model=$(grep -oP '(?<=Camera0\.model:\s)[\w]+' "$calibration_yaml")
16
  echo " camera model : $calibration_model"
17
 
18
  # Reading settings from yaml file
colmap_matcher.sh CHANGED
@@ -7,28 +7,20 @@ exp_folder="$2"
7
  exp_id="$3"
8
  settings_yaml="$4"
9
  calibration_yaml="$5"
10
- rgb_txt="$6"
11
  matcher_type="$7"
12
  use_gpu="$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)
@@ -51,7 +43,7 @@ matcher_ExhaustiveMatching_block_size=$(yq '.matcher.ExhaustiveMatching_block_si
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"
@@ -81,14 +73,14 @@ colmap feature_extractor \
81
  --SiftExtraction.dsp_num_scales ${feature_extractor_SiftExtraction_dsp_num_scales}
82
  fi
83
 
84
- if [ "${calibration_model}" == "PINHOLE" ]
85
  then
86
  echo " camera model : $calibration_model"
87
  colmap feature_extractor \
88
  --database_path ${database} \
89
  --image_path ${rgb_path} \
90
  --image_list_path ${colmap_image_list} \
91
- --ImageReader.camera_model ${calibration_model} \
92
  --ImageReader.single_camera 1 \
93
  --ImageReader.single_camera_per_folder 1 \
94
  --SiftExtraction.use_gpu ${use_gpu} \
@@ -104,6 +96,13 @@ fi
104
 
105
  if [ "${calibration_model}" == "OPENCV" ]
106
  then
 
 
 
 
 
 
 
107
  echo " camera model : $calibration_model"
108
  colmap feature_extractor \
109
  --database_path ${database} \
@@ -125,6 +124,12 @@ fi
125
 
126
  if [ "${calibration_model}" == "OPENCV_FISHEYE" ]
127
  then
 
 
 
 
 
 
128
  echo " camera model : $calibration_model"
129
  colmap feature_extractor \
130
  --database_path ${database} \
@@ -164,7 +169,7 @@ fi
164
  # Sequential Feature Matcher
165
  if [ "${matcher_type}" == "sequential" ]
166
  then
167
- num_rgb=$(wc -l < ${rgb_txt})
168
 
169
  # Pick vocabulary tree based on the number of images
170
  vocabulary_tree="Baselines/colmap/vocab_tree_flickr100K_words32K.bin"
 
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
 
14
  exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
15
+ rgb_dir=$(awk -F, 'NR==2 { split($2,a,"/"); print a[1]; exit }' "$rgb_csv")
16
+ rgb_path="${sequence_path}/${rgb_dir}"
17
 
18
+ calibration_model=$(grep -oP '(?<=Camera0\.model:\s)[\w]+' "$calibration_yaml")
19
 
20
+ fx=$(grep -oP '(?<=Camera0\.fx:\s)-?\d+\.\d+' "$calibration_yaml")
21
+ fy=$(grep -oP '(?<=Camera0\.fy:\s)-?\d+\.\d+' "$calibration_yaml")
22
+ cx=$(grep -oP '(?<=Camera0\.cx:\s)-?\d+\.\d+' "$calibration_yaml")
23
+ cy=$(grep -oP '(?<=Camera0\.cy:\s)-?\d+\.\d+' "$calibration_yaml")
 
 
 
 
 
 
 
 
 
24
 
25
  # Reading settings from yaml file
26
  feature_extractor_SiftExtraction_num_octaves=$(yq '.feature_extractor.SiftExtraction_num_octaves // 4.0' $settings_yaml)
 
43
 
44
  # Create colmap image list
45
  colmap_image_list="${exp_folder_colmap}/colmap_image_list.txt"
46
+ awk -F, 'NR>1 { split($2,a,"/"); print a[2] }' "$rgb_csv" > "$colmap_image_list"
47
 
48
  # Create Colmap Database
49
  database="${exp_folder_colmap}/colmap_database.db"
 
73
  --SiftExtraction.dsp_num_scales ${feature_extractor_SiftExtraction_dsp_num_scales}
74
  fi
75
 
76
+ if [ "${calibration_model}" == "Pinhole" ]
77
  then
78
  echo " camera model : $calibration_model"
79
  colmap feature_extractor \
80
  --database_path ${database} \
81
  --image_path ${rgb_path} \
82
  --image_list_path ${colmap_image_list} \
83
+ --ImageReader.camera_model PINHOLE \
84
  --ImageReader.single_camera 1 \
85
  --ImageReader.single_camera_per_folder 1 \
86
  --SiftExtraction.use_gpu ${use_gpu} \
 
96
 
97
  if [ "${calibration_model}" == "OPENCV" ]
98
  then
99
+
100
+ k1=$(grep -oP '(?<=Camera0\.k1:\s)-?\d+\.\d+' "$calibration_yaml")
101
+ k2=$(grep -oP '(?<=Camera0\.k2:\s)-?\d+\.\d+' "$calibration_yaml")
102
+ p1=$(grep -oP '(?<=Camera0\.p1:\s)-?\d+\.\d+' "$calibration_yaml")
103
+ p2=$(grep -oP '(?<=Camera0\.p2:\s)-?\d+\.\d+' "$calibration_yaml")
104
+ k3=$(grep -oP '(?<=Camera0\.k3:\s)-?\d+\.\d+' "$calibration_yaml")
105
+
106
  echo " camera model : $calibration_model"
107
  colmap feature_extractor \
108
  --database_path ${database} \
 
124
 
125
  if [ "${calibration_model}" == "OPENCV_FISHEYE" ]
126
  then
127
+
128
+ k1=$(grep -oP '(?<=Camera0\.k1:\s)-?\d+\.\d+' "$calibration_yaml")
129
+ k2=$(grep -oP '(?<=Camera0\.k2:\s)-?\d+\.\d+' "$calibration_yaml")
130
+ k3=$(grep -oP '(?<=Camera0\.k3:\s)-?\d+\.\d+' "$calibration_yaml")
131
+ k4=$(grep -oP '(?<=Camera0\.k4:\s)-?\d+\.\d+' "$calibration_yaml")
132
+
133
  echo " camera model : $calibration_model"
134
  colmap feature_extractor \
135
  --database_path ${database} \
 
169
  # Sequential Feature Matcher
170
  if [ "${matcher_type}" == "sequential" ]
171
  then
172
+ num_rgb=$(( $(wc -l < "$rgb_csv") - 1 ))
173
 
174
  # Pick vocabulary tree based on the number of images
175
  vocabulary_tree="Baselines/colmap/vocab_tree_flickr100K_words32K.bin"
colmap_reconstruction.sh CHANGED
@@ -9,7 +9,7 @@ sequence_path=""
9
  exp_folder=""
10
  exp_id=""
11
  calibration_yaml=""
12
- rgb_txt=""
13
 
14
  # Function to split key-value pairs and assign them to variables
15
  split_and_assign() {
@@ -35,7 +35,7 @@ echo " Matcher Type : $matcher_type"
35
  echo " Use GPU : $use_gpu"
36
  echo " Settings YAML : $settings_yaml"
37
  echo " Calibration YAML : $calibration_yaml"
38
- echo " RGB TXT : $rgb_txt"
39
  echo "============================================================"
40
 
41
  # Create folder to save colmap files
@@ -45,17 +45,18 @@ mkdir "$exp_folder_colmap"
45
 
46
  # Run COLMAP scripts for matching and mapping
47
  export QT_QPA_PLATFORM_PLUGIN_PATH="$CONDA_PREFIX/plugins/platforms"
48
- colmap_args="$sequence_path $exp_folder $exp_id $settings_yaml $calibration_yaml $rgb_txt"
49
  ./Baselines/colmap/colmap_matcher.sh $colmap_args $matcher_type $use_gpu
50
  ./Baselines/colmap/colmap_mapper.sh $colmap_args
51
 
52
  # Convert COLMAP outputs to a format suitable for VSLAM-LAB
53
- python Baselines/colmap/colmap_to_vslamlab.py $sequence_path $exp_folder $exp_id $verbose $rgb_txt
54
 
55
  # Visualization with colmap gui
56
  if [ "$verbose" -eq 1 ]; then
57
  exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
58
- rgb_path="${sequence_path}/$(awk '{print $2}' "${rgb_txt}" | awk -F'/' 'NR==1 {print $1}')"
 
59
  database="${exp_folder_colmap}/colmap_database.db"
60
  colmap gui --import_path "${exp_folder_colmap}/0" --database_path ${database} --image_path ${rgb_path}
61
  fi
 
9
  exp_folder=""
10
  exp_id=""
11
  calibration_yaml=""
12
+ rgb_csv=""
13
 
14
  # Function to split key-value pairs and assign them to variables
15
  split_and_assign() {
 
35
  echo " Use GPU : $use_gpu"
36
  echo " Settings YAML : $settings_yaml"
37
  echo " Calibration YAML : $calibration_yaml"
38
+ echo " RGB CSV : $rgb_csv"
39
  echo "============================================================"
40
 
41
  # Create folder to save colmap files
 
45
 
46
  # Run COLMAP scripts for matching and mapping
47
  export QT_QPA_PLATFORM_PLUGIN_PATH="$CONDA_PREFIX/plugins/platforms"
48
+ colmap_args="$sequence_path $exp_folder $exp_id $settings_yaml $calibration_yaml $rgb_csv"
49
  ./Baselines/colmap/colmap_matcher.sh $colmap_args $matcher_type $use_gpu
50
  ./Baselines/colmap/colmap_mapper.sh $colmap_args
51
 
52
  # Convert COLMAP outputs to a format suitable for VSLAM-LAB
53
+ python Baselines/colmap/colmap_to_vslamlab.py $sequence_path $exp_folder $exp_id $verbose $rgb_csv
54
 
55
  # Visualization with colmap gui
56
  if [ "$verbose" -eq 1 ]; then
57
  exp_folder_colmap="${exp_folder}/colmap_${exp_id}"
58
+ rgb_dir=$(awk -F, 'NR==2 { split($2,a,"/"); print a[1]; exit }' "$rgb_csv")
59
+ rgb_path="${sequence_path}/${rgb_dir}"
60
  database="${exp_folder_colmap}/colmap_database.db"
61
  colmap gui --import_path "${exp_folder_colmap}/0" --database_path ${database} --image_path ${rgb_path}
62
  fi
colmap_to_vslamlab.py CHANGED
@@ -2,6 +2,7 @@ import numpy as np
2
  from scipy.spatial.transform import Rotation as R
3
  import sys
4
  import os
 
5
 
6
  def get_colmap_keyframes(images_file, number_of_header_lines, verbose=False):
7
  print(f"get_colmap_keyframes: {images_file}")
@@ -65,21 +66,15 @@ def write_trajectory_tum_format(file_name, image_ts, t_wc, q_wc_xyzw):
65
  data = np.hstack((image_ts.reshape(-1, 1), t_wc, q_wc_xyzw))
66
  data = data[data[:, 0].argsort()]
67
 
68
- with open(file_name, 'w') as file:
 
69
  for row in data:
70
- # Format the row with the appropriate precision
71
- file.write(' '.join(f'{x:.15f}' for x in row) + '\n')
72
 
73
  def get_timestamps(files_path, rgb_file):
74
  print(f"getTimestamps: {os.path.join(files_path, rgb_file)}")
75
-
76
- ts = []
77
-
78
- with open(os.path.join(files_path, rgb_file), 'r') as file:
79
- for line in file:
80
- parts = line.split()
81
- ts.append(float(parts[0])) # Assuming the first part is the timestamp
82
-
83
  return ts
84
 
85
  if __name__ == "__main__":
@@ -102,5 +97,5 @@ if __name__ == "__main__":
102
 
103
  timestamps = np.array(timestamps)
104
 
105
- keyFrameTrajectory_txt = os.path.join(exp_folder, exp_id + '_KeyFrameTrajectory' + '.txt')
106
  write_trajectory_tum_format(keyFrameTrajectory_txt, timestamps, t_wc, q_wc_xyzw)
 
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}")
 
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('timestamp,tx,ty,tz,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):
75
  print(f"getTimestamps: {os.path.join(files_path, rgb_file)}")
76
+ df = pd.read_csv(rgb_file)
77
+ ts = df['ts_rgb0 (s)'].to_list()
 
 
 
 
 
 
78
  return ts
79
 
80
  if __name__ == "__main__":
 
97
 
98
  timestamps = np.array(timestamps)
99
 
100
+ keyFrameTrajectory_txt = os.path.join(exp_folder, exp_id + '_KeyFrameTrajectory' + '.csv')
101
  write_trajectory_tum_format(keyFrameTrajectory_txt, timestamps, t_wc, q_wc_xyzw)