File size: 1,626 Bytes
16231ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Split equirectangular street-view panoramas into 4 perspective views (yaw 0/90/180/270, 90-degree FOV, pitch 0),
exactly as our training views were made (panorama_views.make_views: 512 x 512, vertical extent
360 * H / W degrees centred on the horizon, so vertically cropped panoramas such as Baidu 1024 x 384 work too).
Views: <output>/<subfolder>/<stem>_yaw000.jpg ... _yaw270.jpg. Images with aspect < 1.8 are copied as one view.
"""
import sys as _sys
from pathlib import Path as _Path
_SCRIPTS = next(_p for _p in _Path(__file__).resolve().parents if _p.name == "scripts")
_sys.path[:0] = [str(_SCRIPTS.parent), str(_SCRIPTS.parent / "models")] + [str(_d) for _d in sorted(_SCRIPTS.rglob("*")) if _d.is_dir() and _d.name != "__pycache__"]
import argparse
import sys
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))
from panorama_views import make_views  # noqa: E402

p = argparse.ArgumentParser(description=__doc__)
p.add_argument("--input", type=Path, required=True)
p.add_argument("--output", type=Path, required=True)
p.add_argument("--size", type=int, default=512)
p.add_argument("--workers", type=int, default=8)
a = p.parse_args()
exts = {".jpg", ".jpeg", ".png"}
images = sorted(q for q in a.input.rglob("*") if q.suffix.lower() in exts)


def one(q):
    return make_views(q, a.output / q.parent.relative_to(a.input), q.stem, a.size)[1]


with ThreadPoolExecutor(a.workers) as pool:
    panos = sum(pool.map(one, images))
print(f"{len(images)} images ({panos} panoramas -> 4 views each) -> {a.output}")