-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_best_colmap_folder.py
49 lines (36 loc) · 1.77 KB
/
select_best_colmap_folder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import argparse
from pathlib import Path
import general_utils
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Converting COLMAP format to the one we use',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--sequence_root", type=str, required=True, help='root of video sequence')
args = parser.parse_args()
sequence_root = Path(args.sequence_root)
print(str(sequence_root) + ": ")
result_root = sequence_root / "colmap"
if not result_root.exists():
print("ERROR: COLMAP sparse reconstruction does not exist")
result_path_list = list(result_root.glob("*"))
result_path_list.sort()
if len(result_path_list) > 1:
result_visible_views = [len(general_utils.read_visible_view_indexes(prefix)) for prefix in result_path_list]
best_result = result_visible_views.index(max(result_visible_views))
if best_result != 0:
print("Exchanging results in {} for 0".format(best_result))
# Move best results to 'best' directory
best_result_path = result_root / str(best_result)
best_result_dest_path = result_root / "best"
os.system("cp -r {} {}".format(str(best_result_path), str(best_result_dest_path)))
os.system("rm -r {}".format(str(best_result_path)))
# Exchange previous '0' for previous best index
zero_result_path = result_root / "0"
os.system("mv {} {}".format(str(zero_result_path), str(best_result_path)))
# Change 'best' directory to new '0'
os.system("mv {} {}".format(str(best_result_dest_path), str(zero_result_path)))
else:
print("No change needed")
else:
print("No change needed")