-
Notifications
You must be signed in to change notification settings - Fork 1
/
file.py
80 lines (62 loc) · 2.63 KB
/
file.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Open3D: www.open3d.org
# The MIT License (MIT)
# See license file or visit www.open3d.org for details
# examples/Python/Utility/file.py
from os import listdir, makedirs
from os.path import exists, isfile, join, splitext
import shutil
import re
def sorted_alphanum(file_list_ordered):
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
return sorted(file_list_ordered, key=alphanum_key)
def get_file_list(path, extension=None):
if extension is None:
file_list = [path + f for f in listdir(path) if isfile(join(path, f))]
else:
file_list = [
path + f
for f in listdir(path)
if isfile(join(path, f)) and splitext(f)[1] == extension
]
file_list = sorted_alphanum(file_list)
return file_list
def add_if_exists(path_dataset, folder_names):
for folder_name in folder_names:
if exists(join(path_dataset, folder_name)):
path = join(path_dataset, folder_name)
return path
def get_rgbd_folders(path_dataset):
path_color = add_if_exists(path_dataset, ["image/", "rgb/", "color/"])
path_depth = join(path_dataset, "depth/")
return path_color, path_depth
def get_rgbd_file_lists(path_dataset):
path_color, path_depth = get_rgbd_folders(path_dataset)
color_files = get_file_list(path_color, ".jpg") + \
get_file_list(path_color, ".png")
depth_files = get_file_list(path_depth, ".png")
return color_files, depth_files
def make_clean_folder(path_folder):
if not exists(path_folder):
makedirs(path_folder)
else:
shutil.rmtree(path_folder)
makedirs(path_folder)
def check_folder_structure(path_dataset):
path_color, path_depth = get_rgbd_folders(path_dataset)
assert exists(path_depth), \
"Path %s is not exist!" % path_depth
assert exists(path_color), \
"Path %s is not exist!" % path_color
def write_poses_to_log(filename, poses):
with open(filename, 'w') as f:
for i, pose in enumerate(poses):
f.write('{} {} {}\n'.format(i, i, i + 1))
f.write('{0:.8f} {1:.8f} {2:.8f} {3:.8f}\n'.format(
pose[0, 0], pose[0, 1], pose[0, 2], pose[0, 3]))
f.write('{0:.8f} {1:.8f} {2:.8f} {3:.8f}\n'.format(
pose[1, 0], pose[1, 1], pose[1, 2], pose[1, 3]))
f.write('{0:.8f} {1:.8f} {2:.8f} {3:.8f}\n'.format(
pose[2, 0], pose[2, 1], pose[2, 2], pose[2, 3]))
f.write('{0:.8f} {1:.8f} {2:.8f} {3:.8f}\n'.format(
pose[3, 0], pose[3, 1], pose[3, 2], pose[3, 3]))