render¶
[render]: draw video frames and result arrays onto the panels of a video.
config.render says what a video is (ADR-0031); this module
draws it frame by frame, with Pillow and
VideoWriter, handed the resolved table, the
arrays through a read callable, the video readers and the rig, and knows nothing of
runs. A panel shows one view, or a whole video with every view it carries drawn in
the video's own pixels. Content fits its panel by uniform scale, centered, and every
2D coordinate goes through the same map, so a cropped picture and the points over it
agree. A frame is a NumPy canvas: OpenCV resizes the footage into it and draws the
vector marks straight onto it, anti-aliased against what is under them, and the text
is FreeType's through Pillow, rendered once per string (_Marks, ADR-0143). The
treadmill ball is drawn from what [ball] writes: its outline, and the trail the
animal has walked over it (ADR-0147).
Layer
dataclass
¶
One thing to draw: a draw kind over one data reference, with its style.
The renderer's record of a layers entry (Layer
says which keys each kind takes); every field but draw has a default.
Source code in src/deeperfly/render.py
RenderReport
dataclass
¶
What one video came to.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
The MP4 written. |
n_frames |
int
|
Frames drawn. |
fps |
float
|
The file's frame rate. |
hold |
int
|
Output frames each drawn frame is held for, so the file carries
|
size |
tuple[int, int]
|
The |
Source code in src/deeperfly/render.py
SyntheticView
dataclass
¶
A view no camera recorded: an orbit placement to draw 3D data from.
distance, focal and image_size may be left to the renderer, which fits them
to the data.
Source code in src/deeperfly/render.py
alpha_map ¶
An array's values as opacities in [0, 1], NaN transparent.
As they are without a range; with [lo, hi], lo maps to 0 and hi to 1, so
[20, 0] fades what is large.
Source code in src/deeperfly/render.py
frames_in_range ¶
The frames a half-open [start, stop] or [start, stop, step] range keeps.
frames are the frames asked for; an empty range keeps them all, and a step
counts from start.
Source code in src/deeperfly/render.py
layout ¶
Each grid name's canvas rectangle for cells of (height, width).
Source code in src/deeperfly/render.py
render_video ¶
render_video(
video: Mapping[str, Any],
*,
out: str | Path,
project: str,
videos: Mapping[str, FrameReader],
frames: Sequence[int] | ndarray,
fps: float | None,
rig: Rig,
skeleton: Skeleton,
views: Mapping[str, SyntheticView],
read: Callable[[str], ndarray],
names: Callable[[str], tuple[str, ...] | None],
axes: Callable[[str], tuple] | None = None,
mesh: ModelMesh | None = None,
layout: Layout | None = None,
log: Callable[[str], None] = print,
) -> RenderReport
Draw one video and write it as an MP4.
video is one resolved [render.outputs.<name>] table with [render]'s defaults
filled in, and frames the increasing frame indices to draw, one output frame
each: the caller applies the table's own range
(frames_in_range). videos maps each video
to its reader, decoded once per frame whatever its panels, and layout says which
views each video carries (omitted, one view per video, of its name). A grid name
is a view of rig, a video of videos, which shows its whole frame with every
view it carries drawn in, or a synthetic view of views. project is the name a
{project} caption shows. A view this project lacks renders as an empty panel
with a notice. fps defaults to FALLBACK_FPS. read resolves a data
reference, names a reference's named axis and axes its declared axes (which
tell a per-animal array apart). mesh is the body model's overlay mesh, which
the caller loads from the pack [ik] names. The video is drawn at its cell a
panel and, with a max_size, scaled down to fit it before it is written.
Raises:
| Type | Description |
|---|---|
ValueError
|
On a trace over an array without channel names, or a |
Source code in src/deeperfly/render.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |