canvas — functions
Placing a camera's picture in view space, and asking what covers what.
The C ABI gained this whole feature late -- optris_sdk_canvas,
optris_sdk_placement and thirty-three entry points around them --
and no binding in any language reached a single one of them until
this module. It was not a Python gap: it was an unbound feature,
declared at the ABI, gated, and called from nothing above it. The
changelog meanwhile said "a program that is not written in C++ can now
place a camera's picture on a canvas", in a list whose next line names
Python and Rust, so the claim was true of a C caller and of nobody
else.
Three types, mirroring the ABI exactly:
Placement is a value, not a handle -- where one camera's
frame sits in view space, as a 3x3 affine transform. Build one with
Placement.identity or Placement.centred, then move it.
Canvas is a handle owning a list of placements plus the
colour of the space none of them covers. It is a context manager; use
it as one.
CanvasMap is a handle holding the answer to "which
placement covers this output pixel", recomputed by CanvasMap.update
whenever the canvas or the frame size changes.
with optris_sdk.Canvas(640, 480) as canvas:
canvas.add_placement(optris_sdk.Placement.centred(382, 288))
with optris_sdk.CanvasMap() as cmap:
cmap.update(canvas, 382, 288)
print(cmap.fill) # how much of the canvas is covered
Why the frame size is an argument and not state
Six of these calls take frame_width and frame_height. A
placement is stored in a frame-size-independent space, so the same
placement describes a 382x288 camera and a 640x480 one differently, and
the ABI asks for the size at the point of the question rather than
binding a placement to one camera. This module does not cache it:
caching would make a placement silently wrong the moment a camera's
mode changed, which is the defect the ABI's shape avoids.
An unmeasurable answer is None, never a number
Placement.inverse returns None for a transform that cannot
be inverted -- the ABI reports that through an out_valid flag
beside the matrix, and a singular transform's coefficients are not a
matrix anyone should use. None rather than nine zeros or an
identity, for the reason stated throughout this binding: a value in
the value space cannot be told apart from a real answer.
frame_centre_of(width, height)
The centre of a frame that size, in frame coordinates.
Not (0.5, 0.5), which is the mistake this call exists to
stop. Both axes are divided by the width, so x runs 0..1 and y
runs 0..height/width -- the centre of a 382x288 frame is therefore
(0.5, 0.377), and a hand-written (0.5, 0.5) places it
below centre on every camera that is not square.
- Raises
InvalidArgumentError— if either dimension is zero.