36
36
magick_command = '"{}"' .format (args .magick_executable ) if len (args .magick_executable ) > 0 else "magick"
37
37
use_gpu = 1 if not args .no_gpu else 0
38
38
39
+ EXIT_FAIL = 1
40
+
39
41
if not args .skip_matching :
40
42
os .makedirs (args .source_path + "/distorted/sparse" , exist_ok = True )
41
43
49
51
exit_code = os .system (feat_extracton_cmd )
50
52
if exit_code != 0 :
51
53
logging .error (f"Feature extraction failed with code { exit_code } . Exiting." )
52
- exit (exit_code )
54
+ exit (EXIT_FAIL )
53
55
54
56
## Feature matching
55
57
feat_matching_cmd = colmap_command + " exhaustive_matcher \
58
60
exit_code = os .system (feat_matching_cmd )
59
61
if exit_code != 0 :
60
62
logging .error (f"Feature matching failed with code { exit_code } . Exiting." )
61
- exit (exit_code )
63
+ exit (EXIT_FAIL )
62
64
63
65
### Bundle adjustment
64
66
# The default Mapper tolerance is unnecessarily large,
71
73
exit_code = os .system (mapper_cmd )
72
74
if exit_code != 0 :
73
75
logging .error (f"Mapper failed with code { exit_code } . Exiting." )
74
- exit (exit_code )
76
+ exit (EXIT_FAIL )
75
77
76
78
### Convert model to text format so we can read cameras
77
79
convert_cmd = (colmap_command + " model_converter \
81
83
exit_code = os .system (convert_cmd )
82
84
if exit_code != 0 :
83
85
logging .error (f"Convert failed with code { exit_code } . Exiting." )
84
- exit (exit_code )
86
+ exit (EXIT_FAIL )
85
87
86
88
### Image undistortion
87
89
## We need to undistort our images into ideal pinhole intrinsics.
94
96
exit_code = os .system (img_undist_cmd )
95
97
if exit_code != 0 :
96
98
logging .error (f"image_undistorter failed with code { exit_code } . Exiting." )
97
- exit (exit_code )
99
+ exit (EXIT_FAIL )
98
100
99
101
100
102
def remove_dir_if_exist (path ):
@@ -114,7 +116,7 @@ def remove_dir_if_exist(path):
114
116
exit_code = os .system (model_converter_cmd )
115
117
if exit_code != 0 :
116
118
logging .error (f"model_converter failed with code { exit_code } . Exiting." )
117
- exit (exit_code )
119
+ exit (EXIT_FAIL )
118
120
119
121
# replace '.jpg' to '.png'
120
122
with open (args .source_path + "/alpha_distorted_sparse_txt/images.txt" , "r+" ) as f :
@@ -133,7 +135,7 @@ def remove_dir_if_exist(path):
133
135
exit_code = os .system (seg_undist_cmd )
134
136
if exit_code != 0 :
135
137
logging .error (f"image_undistorter for segs failed with code { exit_code } . Exiting." )
136
- exit (exit_code )
138
+ exit (EXIT_FAIL )
137
139
138
140
# switch images
139
141
remove_dir_if_exist (f'{ args .source_path } /alpha_undistorted_sparse/alphas' )
@@ -188,20 +190,20 @@ def concat_alpha(seg_path):
188
190
exit_code = os .system ("mogrify -resize 50% " + destination_file )
189
191
if exit_code != 0 :
190
192
logging .error (f"50% resize failed with code { exit_code } . Exiting." )
191
- exit (exit_code )
193
+ exit (EXIT_FAIL )
192
194
193
195
destination_file = os .path .join (args .source_path , "images_4" , file )
194
196
shutil .copy2 (source_file , destination_file )
195
197
exit_code = os .system ("mogrify -resize 25% " + destination_file )
196
198
if exit_code != 0 :
197
199
logging .error (f"25% resize failed with code { exit_code } . Exiting." )
198
- exit (exit_code )
200
+ exit (EXIT_FAIL )
199
201
200
202
destination_file = os .path .join (args .source_path , "images_8" , file )
201
203
shutil .copy2 (source_file , destination_file )
202
204
exit_code = os .system ("mogrify -resize 12.5% " + destination_file )
203
205
if exit_code != 0 :
204
206
logging .error (f"12.5% resize failed with code { exit_code } . Exiting." )
205
- exit (exit_code )
207
+ exit (EXIT_FAIL )
206
208
207
209
print ("Done." )
0 commit comments