Frame
pub struct Frame<'a>
A borrowed view of one thermal frame.
'a is how long the pixels stay valid. See the crate-level
safety contract for what that means on each path.
This is Copy: it is a pointer and a lifetime, nothing more.
Copying one does not copy a frame.
Frame — methods
pub fn info(self) -> Result<FrameInfo>
Read the frame's metadata.
Errors
Returns Status::InvalidHandle if the frame has been
invalidated by the SDK.
pub fn extreme_location(self, which: FrameExtreme) -> Result<Option<(u32, u32)>>
Where the coldest or warmest measured pixel is, as (x, y).
Ok(None) when the frame had nothing measurable in it, which is
not an error a caller made; the SDK answers NOT_FOUND and
that becomes None here, the same rule .NET and Python apply.
Why this exists beside FrameInfo::min_location
FrameInfo is owned data, so its helper does the arithmetic
locally and needs no FFI; that is the ergonomic route and the
one to reach for. This one goes through the C entry point,
which matters for two reasons: it is what
scripts/check_binding_parity.py counts, so without it this
crate shows a permanent GAP on a function it can perfectly well
reach; and it keeps one implementation authoritative. The two
are asserted to agree by
camera::tests::every_scalar_conversion_agrees_with_the_committed_pairs's
neighbours rather than assumed to.
Errors
Returns Status::InvalidHandle if the frame has been
invalidated by the SDK.
pub fn data(self) -> Result<&'a [i16]>
Borrow the frame's pixels, in the SDK's internal format.
The returned slice is the SDK's own memory; nothing is copied.
Its lifetime is 'a, so the compiler will not let it outlive the
frame that owns it.
These are samples, not temperatures, and the sentinel lives
here: a pixel the SDK could not measure reads
sys::OPTRIS_SDK_INVALID_PIXEL. If what you want is
temperatures, use Frame::temperatures, which converts the
whole frame inside the library and answers f32::NAN for
such a pixel. internal_to_celsius is for a single sample
you already hold and applies the formula to whatever it is
given, including the sentinel.
Examples
This is the shape that matters; a slice taken inside a callback cannot escape it:
# use optris_sdk::{Camera, Frame};
# fn main() -> optris_sdk::Result<()> {
let mut escaped: Option<&[i16]> = None;
let mut camera = Camera::open()?;
camera.on_thermal_frame(move |frame: Frame<'_>| {
// error: borrowed data escapes outside of closure
escaped = Some(frame.data().unwrap());
})?;
# Ok(())
# }
Errors
Returns Status::InvalidHandle if the frame is no longer
valid, or Status::Unknown if the SDK reports a length that
cannot be addressed.
pub fn temperatures(self) -> Result<Vec<f32>>
The frame's pixels as temperatures in the SDK's temperature unit
(Celsius unless crate::set_temperature_unit chose
Fahrenheit), in the unit in force when this is called.
The SDK converts them; this crate does not apply the
fixed-point formula itself, and that is deliberate twice over.
The scale is the SDK's internal business and may change; and a
pixel the SDK could not measure comes back as f32::NAN
rather than as the plausible-looking -3376.8 that mapping
internal_to_celsius over Frame::data produces (that
decoder is Celsius in either unit, by design).
That second point is not hypothetical: this method was that
map, and it returned -3376.8 for every pixel radial distortion
correction could not measure: 1.9 % of a PI 640i frame, 15.8 %
of a G7 frame, on every frame.
NAN propagates, so iter().sum() or a fold with f32::min
over the whole vector is NAN if any pixel was unmeasured. That
is a loud wrong answer rather than a quiet one; for the coldest
pixel that was measured read FrameInfo::min_temp_c, which
excludes them.
This one does allocate, an f32 per pixel, because there is
nowhere else to put the results.
Errors
Returns Status::InvalidHandle if the frame is no longer
valid.
pub fn temperature_at(self, x: u32, y: u32) -> Result<f32>
The temperature at one pixel, in the SDK's temperature unit
(Celsius unless crate::set_temperature_unit chose
Fahrenheit).
Convenient for a handful of probes. For a whole frame use
Frame::temperatures, which converts it in one call -- this
function costs a call and a bounds check per pixel.
This doc comment used to say "for a whole frame use
Frame::data and convert in a loop", which is exactly the
advice to retire: a loop here is a fourth copy of
(raw - 1000) / 10, and copies of that formula are where the
binding disagreements were found. The C header's wording for the same
function was corrected and this one was missed.
Errors
Returns Status::OutOfRange if the coordinates are outside the
frame.
pub fn is_measurement(self) -> Result<bool>
Whether this frame is a measurement of the scene.
False while the shutter is closed, when the sensor is looking at
its own flag, and false until the camera's startup calibration
has finished and its detector has stopped warming
(FrameInfo::thermal_data_reliable). The second wait is
the camera's own: one that has been running clears in about
18 s, one switched on cold takes as long as its warm-up does --
about four and a half minutes on a PI 4x0 measured from cold.
Both kinds still arrive and still carry plausible-looking
numbers, so anything recording measurements should skip them.
Errors
As Frame::info.
pub fn to_owned(self) -> Result<OwnedFrame>
Take an owned copy of this frame.
This is how a callback keeps the frame it was given. The copy is independent of the original and outlives it.
Errors
Returns Status::OutOfMemory if the copy cannot be allocated.