|
a |
|
b/datasets/OUMVLP/rearrange_OUMVLP.py |
|
|
1 |
import argparse |
|
|
2 |
import os |
|
|
3 |
import shutil |
|
|
4 |
from pathlib import Path |
|
|
5 |
from typing import Tuple |
|
|
6 |
|
|
|
7 |
from tqdm import tqdm |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
TOTAL_SUBJECTS = 10307 |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
def sanitize(name: str) -> Tuple[str, str]: |
|
|
14 |
return name.split('_')[1].split('-') |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
def rearrange(input_path: Path, output_path: Path) -> None: |
|
|
18 |
os.makedirs(output_path, exist_ok=True) |
|
|
19 |
|
|
|
20 |
for folder in input_path.iterdir(): |
|
|
21 |
print(f'Rearranging {folder}') |
|
|
22 |
view, seq = sanitize(folder.name) |
|
|
23 |
progress = tqdm(total=TOTAL_SUBJECTS) |
|
|
24 |
for sid in folder.iterdir(): |
|
|
25 |
src = os.path.join(input_path, f'Silhouette_{view}-{seq}', sid.name) |
|
|
26 |
dst = os.path.join(output_path, sid.name, seq, view) |
|
|
27 |
os.makedirs(dst, exist_ok=True) |
|
|
28 |
for subfile in os.listdir(src): |
|
|
29 |
if subfile not in os.listdir(dst) and subfile.endswith('.png'): |
|
|
30 |
os.symlink(os.path.join(src, subfile), |
|
|
31 |
os.path.join(dst, subfile)) |
|
|
32 |
# else: |
|
|
33 |
# os.remove(os.path.join(src, subfile)) |
|
|
34 |
progress.update(1) |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
if __name__ == '__main__': |
|
|
38 |
parser = argparse.ArgumentParser(description='OUMVLP rearrange tool') |
|
|
39 |
parser.add_argument('-i', '--input_path', required=True, type=str, |
|
|
40 |
help='Root path of raw dataset.') |
|
|
41 |
parser.add_argument('-o', '--output_path', default='OUMVLP_rearranged', type=str, |
|
|
42 |
help='Root path for output.') |
|
|
43 |
|
|
|
44 |
args = parser.parse_args() |
|
|
45 |
|
|
|
46 |
input_path = Path(args.input_path).resolve() |
|
|
47 |
output_path = Path(args.output_path).resolve() |
|
|
48 |
rearrange(input_path, output_path) |