File size: 1,622 Bytes
4e6a175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Copy masks and homographies into a reproduced dataset."""

import argparse
import shutil
from pathlib import Path


def copy_annotations(source_root, destination_root):
    copied = 0
    for unit_dir in sorted(path for path in destination_root.iterdir() if path.is_dir()):
        for pair_dir in sorted(path for path in unit_dir.iterdir() if path.is_dir()):
            source_pair = source_root / unit_dir.name / pair_dir.name
            for name in ("mask", "homography"):
                source = source_pair / name
                if not source.is_dir():
                    raise RuntimeError(f"missing annotation directory: {source}")
                shutil.copytree(source, pair_dir / name, dirs_exist_ok=True)
                copied += 1

    print(f"Copied {copied} directories to {destination_root}")


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        "destination",
        type=Path,
        nargs="?",
        default=Path("Data"),
        help="reproduced dataset root (default: Data/)",
    )
    parser.add_argument(
        "--source",
        type=Path,
        default=Path("AnnotationHomography"),
        help="annotation root (default: AnnotationHomography/)",
    )
    args = parser.parse_args()

    if not args.source.is_dir():
        parser.error(f"source directory does not exist: {args.source}")
    if not args.destination.is_dir():
        parser.error(f"destination directory does not exist: {args.destination}")

    copy_annotations(args.source, args.destination)


if __name__ == "__main__":
    main()