frame — functions and constants
Thermal frames, and the lifetimes that keep their pixels honest.
The C API hands out two kinds of frame and they have opposite
ownership. A frame delivered to a callback is borrowed; the
SDK reuses the memory as soon as the callback returns. A frame from
crate::Camera::acquire_frame or Frame::to_owned is
owned and lasts until it is freed.
Reading a borrowed frame's pixels after the callback returned is the single easiest way to misuse this SDK, and in C nothing stops you: the pointer stays valid-looking and quietly starts returning the next frame's data. That is the bug this module exists to make unrepresentable.
Both kinds are expressed here as one borrowed view, Frame,
whose lifetime parameter says how long the pixels last:
- In a callback you are handed a
Frame<'cb>where'cbends when the callback returns. A slice taken from it cannot outlive the callback, so the compiler rejects storing one. - An
OwnedFramelends you aFrame<'_>borrowed from itself, so its slices live exactly as long as theOwnedFramedoes.
Nothing is copied to achieve this. The header points out that copying every frame at 32 Hz on a 640x480 sensor is 19 MB/s of pure overhead; these are the same borrowed pointers with a lifetime attached.
pub fn celsius_is_encodable(celsius: f32) -> bool
Whether a temperature has a sample of its own in this encoding.
The companion to celsius_to_internal: false exactly when that
call is about to answer -32768 because the input is not a
measurement, or saturate at 32767 because the input is hotter
than the format reaches. True means the answer is the real
encoding, to the format's usual tenth of a degree.
Examples
# use optris_sdk::celsius_is_encodable; assert!(celsius_is_encodable(23.5)); assert!(celsius_is_encodable(-100.0)); assert!(!celsius_is_encodable(f32::NAN)); assert!(!celsius_is_encodable(3200.0));
pub fn celsius_to_internal(celsius: f32) -> i16
Convert degrees Celsius to the SDK's internal format.
Three answers, and celsius_is_encodable says which you got:
- a temperature that is not a measurement (
NaN, or at or below absolute zero) gives-32768, the encoding's reserved "nothing was measured"; - one hotter than 3176.7 C saturates at
32767; - everything else is the format, truncated toward zero.
Examples
# use optris_sdk::celsius_to_internal; assert_eq!(celsius_to_internal(0.0), 1000); assert_eq!(celsius_to_internal(23.5), 1235); // Not a measurement, so not a sample. assert_eq!(celsius_to_internal(f32::NAN), -32768); // Hotter than this format reaches. assert_eq!(celsius_to_internal(3200.0), 32767);
pub fn internal_to_celsius(raw: i16) -> f32
Convert one internal-format sample to degrees Celsius.
Frame pixels are stored in the SDK's fixed-point format rather than as floats: half the memory, and what the camera actually sends.
Examples
# use optris_sdk::internal_to_celsius; // The format's zero point: 1000 counts is 0 C, 10 counts per K. assert_eq!(internal_to_celsius(1000), 0.0); assert_eq!(internal_to_celsius(1235), 23.5);
pub fn pixel_is_measured(raw: i16) -> bool
Whether a raw sample is a measurement at all.
Guard with this before converting. Not every sample in a frame
is a measurement: one that is not carries
sys::OPTRIS_SDK_INVALID_PIXEL, and
internal_to_celsius has no opinion about it; it converts the
sentinel to -3376.8 C, which is a plausible-looking number and is
not a reading.
It is not a cold pixel and it is not a bad reading: it is the
absence of one. Radial distortion correction in Wide mode produces
it wherever an output pixel's source falls outside the sensor, by
design and on every frame: 6.1 % of a PI 400 frame, 1.9 % of
a PI 640i frame and 15.8 % of a G7 frame, measured. So
anything that averages, ranks or compares samples has to exclude
it, and a loop over Frame::data that does not is wrong on
every camera with a wide optic fitted.
The sample-domain counterpart of FrameInfo's already-finished
temperatures: there the SDK has excluded them for you.
Examples
# use optris_sdk::{internal_to_celsius, pixel_is_measured};
assert!(pixel_is_measured(1235));
assert!(!pixel_is_measured(-32768));
// Which is why the guard comes first: the conversion answers
// anyway, and the answer looks like a temperature.
assert!(internal_to_celsius(-32768) < -3000.0);