-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.py
137 lines (104 loc) · 4.18 KB
/
cleanup.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import argparse
from pathlib import Path
import json
import numpy as np
from metadata import SUBJECTS
def symlink(src_path: Path, dst_path: Path):
print(src_path, dst_path)
dst_path.parent.mkdir(parents=True, exist_ok=True)
if dst_path.exists():
dst_path.unlink()
dst_path.symlink_to(src_path.resolve())
def cameras(src_path: Path, dst_path: Path):
print(src_path, dst_path)
with src_path.open() as file:
calibration = json.load(file)
raw_cameras = [c for c in calibration["cameras"] if c["type"] == "hd"]
cameras = {}
for raw_camera in raw_cameras:
view = raw_camera["name"].replace("00_", "")
cameras[view] = {
"R": np.array(raw_camera["R"]).tolist(),
"t": (np.array(raw_camera["t"]) * 1e-2).tolist(),
"K": np.array(raw_camera["K"]).tolist(),
"dist_coef": np.array(raw_camera["distCoef"]).tolist(),
"resolution": np.array(raw_camera["resolution"]).tolist(),
}
with dst_path.open("w") as file:
json.dump(cameras, file)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--src_root", type=Path, required=True)
parser.add_argument("--dst_root", type=Path, required=True)
args = parser.parse_args()
src_root = args.src_root
dst_root = args.dst_root
for subject in SUBJECTS:
src_subject = src_root / "data" / subject
dst_subject = dst_root / subject
src_videos = sorted((src_subject / "Videos").glob("*.mp4"))
assert len(src_videos) == 128
for src_video in src_videos:
stem, suffix = src_video.stem, src_video.suffix
sequence, view = stem.replace(" ", "_").split(".")
sequence = sequence.replace("TakingPhoto", "Photo")
sequence = sequence.replace("WalkingDog", "WalkDog")
if subject == "S11" and sequence == "Directions":
continue
if "_ALL" in sequence:
continue
dst_video = dst_subject / "Sequences" / sequence / "Videos" / (view + suffix)
symlink(
src_path=src_video,
dst_path=dst_video,
)
src_poses = sorted((src_subject / "MyPoseFeatures" / "D3_Positions").glob("*.cdf"))
assert len(src_poses) == 30
for src_pose in src_poses:
stem, suffix = src_pose.stem, src_pose.suffix
sequence = stem.replace(" ", "_")
sequence = sequence.replace("TakingPhoto", "Photo")
sequence = sequence.replace("WalkingDog", "WalkDog")
if subject == "S11" and sequence == "Directions":
continue
dst_pose = dst_subject / "Sequences" / sequence / "Poses" / "3D" / ("Groundtruth" + suffix)
symlink(
src_path=src_pose,
dst_path=dst_pose,
)
src_calibration = Path("data/calibration.json")
with src_calibration.open() as file:
calibration = json.load(file)
extrinsics = calibration["extrinsics"][subject]
intrinsics = calibration["intrinsics"]
assert extrinsics.keys() == intrinsics.keys()
cameras = {}
for view in extrinsics:
R = extrinsics[view]["R"]
t = extrinsics[view]["t"]
K = intrinsics[view]["calibration_matrix"]
dist_coef = intrinsics[view]["distortion"]
h, w = intrinsics[view]["resolution"]
resolution = w, h
t = np.array(t)
t = t * 1e-3
t = t.tolist()
cameras[view] = {
"R": R,
"t": t,
"K": K,
"dist_coef": dist_coef,
"resolution": resolution,
}
dst_calibration = dst_subject / "cameras.json"
print(dst_calibration)
with dst_calibration.open("w") as file:
json.dump(cameras, file)
sequences = sorted([x for x in (dst_subject / "Sequences").glob("*") if x.is_dir()])
for sequence in sequences:
symlink(
src_path=dst_calibration,
dst_path=sequence / "cameras.json",
)
if __name__ == "__main__":
main()