31
31
parser .add_argument ("--resize" , action = "store_true" )
32
32
parser .add_argument ("--magick_executable" , default = "" , type = str )
33
33
parser .add_argument ("--masks_path" , type = str )
34
+ parser .add_argument ("--generate_text_model" , action = "store_true" )
34
35
args = parser .parse_args ()
35
36
colmap_command = '"{}"' .format (args .colmap_executable ) if len (args .colmap_executable ) > 0 else "colmap"
36
37
magick_command = '"{}"' .format (args .magick_executable ) if len (args .magick_executable ) > 0 else "magick"
75
76
logging .error (f"Mapper failed with code { exit_code } . Exiting." )
76
77
exit (EXIT_FAIL )
77
78
78
- ### Convert model to text format so we can read cameras
79
- convert_cmd = (colmap_command + " model_converter \
80
- --input_path " + args .source_path + "/distorted/sparse/0 \
81
- --output_path " + args .source_path + "/distorted/sparse/0 \
82
- --output_type TXT" )
83
- exit_code = os .system (convert_cmd )
84
- if exit_code != 0 :
85
- logging .error (f"Convert failed with code { exit_code } . Exiting." )
86
- exit (EXIT_FAIL )
79
+
80
+ # select the largest submodel
81
+ i = 0
82
+ largest_size = 0
83
+ index = 0
84
+
85
+ while True :
86
+ path = args .source_path + "/distorted/sparse/" + str (i )
87
+ if not os .path .exists (path ):
88
+ break
89
+
90
+ # check the file size of images.bin
91
+ images_bin = path + "/images.bin"
92
+ size = os .path .getsize (images_bin )
93
+ if size > largest_size :
94
+ largest_size = size
95
+ index = i
96
+
97
+ i += 1
98
+
99
+ str_index = str (index )
100
+ distorted_sparse_path = args .source_path + "/distorted/sparse/" + str_index
101
+
87
102
88
103
### Image undistortion
89
104
## We need to undistort our images into ideal pinhole intrinsics.
90
105
img_undist_cmd = (colmap_command + " image_undistorter \
91
106
--image_path " + args .source_path + "/input \
92
- --input_path " + args . source_path + "/distorted/sparse/0 \
107
+ --input_path " + distorted_sparse_path + " \
93
108
--output_path " + args .source_path + "\
94
109
--output_type COLMAP" )
95
110
@@ -110,7 +125,7 @@ def remove_dir_if_exist(path):
110
125
# We need to "hack" colmap to undistort segmentation maps modify paths
111
126
# First convert model to text format
112
127
model_converter_cmd = (colmap_command + " model_converter \
113
- --input_path " + args . source_path + "/distorted/sparse/0 \
128
+ --input_path " + distorted_sparse_path + " \
114
129
--output_path " + args .source_path + "/alpha_distorted_sparse_txt/ \
115
130
--output_type TXT" )
116
131
exit_code = os .system (model_converter_cmd )
@@ -162,11 +177,23 @@ def concat_alpha(seg_path):
162
177
Path (f'{ args .source_path } /sparse' ).replace (f'{ args .source_path } /sparse_src/' )
163
178
Path (f'{ args .source_path } /alpha_undistorted_sparse/sparse' ).replace (f'{ args .source_path } /sparse/' )
164
179
180
+ if args .generate_text_model :
181
+ ### Convert model to text format so we can read cameras
182
+ convert_cmd = (colmap_command + " model_converter \
183
+ --input_path " + args .source_path + "/sparse" + " \
184
+ --output_path " + args .source_path + "/sparse" + " \
185
+ --output_type TXT" )
186
+ exit_code = os .system (convert_cmd )
187
+ if exit_code != 0 :
188
+ logging .error (f"Convert failed with code { exit_code } . Exiting." )
189
+ exit (exit_code )
190
+
191
+ # move all files from sparse into sparse/0, as train.py expects it
165
192
files = os .listdir (args .source_path + "/sparse" )
166
193
os .makedirs (args .source_path + "/sparse/0" , exist_ok = True )
167
194
# Copy each file from the source directory to the destination directory
168
195
for file in files :
169
- if file == '0' :
196
+ if file == "0" :
170
197
continue
171
198
source_file = os .path .join (args .source_path , "sparse" , file )
172
199
destination_file = os .path .join (args .source_path , "sparse" , "0" , file )
0 commit comments