-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpreprocess_tnt.py
56 lines (44 loc) · 2.14 KB
/
preprocess_tnt.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
50
51
52
53
54
55
56
# =============================================================================
# Imports
# =============================================================================
import os
import shutil
from gs2mesh_utils.colmap_utils import move_files_to_sparse_zero
base_dir = os.path.abspath(os.getcwd())
# =============================================================================
# Helper functions
# =============================================================================
def clean_directory(dir_path):
files_to_delete = [
'images_raw',
'stereo',
'pinhole_dict.json',
'run-colmap-geometric.sh',
'run-colmap-photometric.sh',
'scene.json'
]
for item in files_to_delete:
item_path = os.path.join(dir_path, item)
if os.path.exists(item_path):
if os.path.isdir(item_path):
shutil.rmtree(item_path)
else:
os.remove(item_path)
# =============================================================================
# Main code to run COLMAP and clean output directories
# =============================================================================
if __name__ == "__main__":
# =============================================================================
# Run COLMAP
# =============================================================================
os.chdir(os.path.join(base_dir,'gs2mesh_utils','third_party','colmap_runner'))
os.system(f"python convert_tnt_to_json.py --tnt_path {os.path.join(base_dir,'data','TNT')}")
# =============================================================================
# Convert model to txt
# =============================================================================
scans = ['Barn', 'Caterpillar', 'Truck', 'Ignatius']
for scan_name in scans:
scan_path = os.path.join(base_dir,'data','TNT',scan_name)
os.system(f"colmap model_converter --input_path {os.path.join(scan_path,'sparse')} --output_path {os.path.join(scan_path,'sparse')} --output_type TXT")
clean_directory(scan_path)
move_files_to_sparse_zero(scan_path)