Skip to content

Commit 2888b7f

Browse files
committed
Prevent exit codes >= 255 in convert.py
1 parent 54c035f commit 2888b7f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

convert.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
colmap_command = '"{}"'.format(args.colmap_executable) if len(args.colmap_executable) > 0 else "colmap"
2828
magick_command = '"{}"'.format(args.magick_executable) if len(args.magick_executable) > 0 else "magick"
2929
use_gpu = 1 if not args.no_gpu else 0
30+
clamp_exit_code = lambda code: code if code <= 255 else 1
3031

3132
if not args.skip_matching:
3233
os.makedirs(args.source_path + "/distorted/sparse", exist_ok=True)
@@ -41,7 +42,7 @@
4142
exit_code = os.system(feat_extracton_cmd)
4243
if exit_code != 0:
4344
logging.error(f"Feature extraction failed with code {exit_code}. Exiting.")
44-
exit(exit_code)
45+
exit(clamp_exit_code(exit_code))
4546

4647
## Feature matching
4748
feat_matching_cmd = colmap_command + " exhaustive_matcher \
@@ -50,7 +51,7 @@
5051
exit_code = os.system(feat_matching_cmd)
5152
if exit_code != 0:
5253
logging.error(f"Feature matching failed with code {exit_code}. Exiting.")
53-
exit(exit_code)
54+
exit(clamp_exit_code(exit_code))
5455

5556
### Bundle adjustment
5657
# The default Mapper tolerance is unnecessarily large,
@@ -63,7 +64,7 @@
6364
exit_code = os.system(mapper_cmd)
6465
if exit_code != 0:
6566
logging.error(f"Mapper failed with code {exit_code}. Exiting.")
66-
exit(exit_code)
67+
exit(clamp_exit_code(exit_code))
6768

6869
### Image undistortion
6970
## We need to undistort our images into ideal pinhole intrinsics.
@@ -75,7 +76,7 @@
7576
exit_code = os.system(img_undist_cmd)
7677
if exit_code != 0:
7778
logging.error(f"Mapper failed with code {exit_code}. Exiting.")
78-
exit(exit_code)
79+
exit(clamp_exit_code(exit_code))
7980

8081
files = os.listdir(args.source_path + "/sparse")
8182
os.makedirs(args.source_path + "/sparse/0", exist_ok=True)
@@ -105,20 +106,20 @@
105106
exit_code = os.system(magick_command + " mogrify -resize 50% " + destination_file)
106107
if exit_code != 0:
107108
logging.error(f"50% resize failed with code {exit_code}. Exiting.")
108-
exit(exit_code)
109+
exit(clamp_exit_code(exit_code))
109110

110111
destination_file = os.path.join(args.source_path, "images_4", file)
111112
shutil.copy2(source_file, destination_file)
112113
exit_code = os.system(magick_command + " mogrify -resize 25% " + destination_file)
113114
if exit_code != 0:
114115
logging.error(f"25% resize failed with code {exit_code}. Exiting.")
115-
exit(exit_code)
116+
exit(clamp_exit_code(exit_code))
116117

117118
destination_file = os.path.join(args.source_path, "images_8", file)
118119
shutil.copy2(source_file, destination_file)
119120
exit_code = os.system(magick_command + " mogrify -resize 12.5% " + destination_file)
120121
if exit_code != 0:
121122
logging.error(f"12.5% resize failed with code {exit_code}. Exiting.")
122-
exit(exit_code)
123+
exit(clamp_exit_code(exit_code))
123124

124125
print("Done.")

0 commit comments

Comments
 (0)