File size: 1,538 Bytes
9b812c9 b628aec e40672f 9b812c9 919b3d8 574a22c 919b3d8 18c7611 6f12d62 919b3d8 6f12d62 9b812c9 919b3d8 574a22c 919b3d8 18c7611 919b3d8 6f12d62 919b3d8 6f12d62 919b3d8 9b812c9 | 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 | """Build and write one final spatial-code JSON file per scene."""
from __future__ import annotations
import os
from encoder import config
from encoder import geometric as geometry_math
from encoder import run as perceive
def build_spatial_code_for(
scene,
depth,
input_selection,
tracking,
frame_count=config.FRAMES_PER_VIDEO,
rebuild=False,
spatial_code_format="explicit",
):
"""Build a spatial code from cached or newly adapted scene geometry."""
spatial_code_format = perceive.adapters.validate_spatial_code_format(
spatial_code_format
)
geometry, how = perceive.cache_or_load(
scene, depth, input_selection, tracking, frame_count, rebuild
)
code, *_ = geometry_math.build_spatial_code(geometry, spatial_code_format)
return code, how
def write_spatial_code_for(
scene,
depth,
input_selection,
tracking,
frame_count=config.FRAMES_PER_VIDEO,
rebuild=False,
spatial_code_format="explicit",
):
"""Build and write one scene's spatial-code JSON."""
code, how = build_spatial_code_for(
scene,
depth,
input_selection,
tracking,
frame_count,
rebuild,
spatial_code_format,
)
path = config.spatial_code_path(
scene,
depth,
input_selection,
tracking,
frame_count,
spatial_code_format,
)
os.makedirs(os.path.dirname(path), exist_ok=True)
geometry_math.dump_spatial_code(code, path)
return code, how, path
|