OptrisOptrisDocumentation

Documentation/OTC SDK/optris_sdk — Rust API referencev12.0

Snapshot

pub struct Snapshot

A snapshot file, read into memory.

Opened with Snapshot::open and closed when dropped; there is no manual close. The file is read once, at open, so asking half a dozen questions about it parses it once rather than six times.

Examples

# fn main() -> optris_sdk::Result<()> {
use optris_sdk::{PixelEncoding, Snapshot};

let snapshot = Snapshot::open("shift2.png")?;
let (width, height) = snapshot.dimensions()?;
println!("{width}x{height}, {:?}", snapshot.encoding()?);

if snapshot.encoding()? == PixelEncoding::Temperature {
    let frame = snapshot.load_thermal()?;
    println!("{:.1} C at the hottest pixel", frame.info()?.max_temp_c);
}
# Ok(())
# }

Snapshot — methods

pub fn open(path: &str) -> Result<Self>

Open a snapshot this SDK wrote.

A PNG or a TIFF. CSV is write-only: it carries no metadata document, so there is nothing to read back.

Errors

Returns Status::Io when the file cannot be read or an attachment fails the SHA-256 recorded for it, and Status::InvalidArgument when the file carries no metadata document, which is how a file from before this format is recognised rather than guessed at.

pub fn info(&self) -> Result<SnapshotInfo>

What the file says about its own capture.

Errors

Returns Status::InvalidHandle if the snapshot is not valid.

pub fn render(&self) -> Result<Option<SnapshotRender>>

How the colorized picture in the file was drawn.

None when the file's primary image is the 16-bit greyscale one: a TIFF, or a PNG written with no live view to take a picture from. That is routine rather than a failure, which is why it is None and not Status::NotFound.

Errors

As Snapshot::info.

pub fn metadata_json(&self) -> Result<String>

The full metadata document as JSON.

Everything SnapshotInfo carries and everything it does not: the pixel scale, the scene statistics, the capture telemetry, the measuring regions, the attachment index and any extra_json the writer merged in.

Errors

As Snapshot::info.

pub fn encoding(&self) -> Result<PixelEncoding>

What a pixel in this file means, which decides how to read the image back.

Errors

As Snapshot::info.

pub fn dimensions(&self) -> Result<(u32, u32)>

Image dimensions as recorded in the file, as (width, height).

Errors

As Snapshot::info.

pub fn load_thermal(&self) -> Result<OwnedFrame>

Read the temperatures back as a frame.

Exact for every temperature file this SDK writes: the internal value that went in is the internal value that comes out. The frame behaves like any other.

Errors

Returns Status::NotSupported when the file holds raw detector counts rather than temperature; ask Snapshot::encoding first, or read the counts with Snapshot::read_raw_pixels.

pub fn read_raw_pixels(&self) -> Result<Vec<u16>>

Read uncalibrated detector counts back, bit for bit.

width * height counts, row-major.

Errors

Returns Status::NotSupported when the file holds temperature rather than raw counts, which is what a snapshot written by a camera holds, so check Snapshot::encoding first.

pub fn attachment_count(&self) -> Result<usize>

How many files the application attached to this snapshot.

Not how many the file carries. Three of the SDK's own are left out of this count and out of Snapshot::attachment_info, each matched on name and MIME type so that an application which attached something of its own under one of those names keeps it:

Left out What it is
thermal.png On a colour snapshot, the measurement itself. It is the image's data rather than a payload; Snapshot::load_thermal is how to reach it.
characteristic-curve.otc The camera's characteristic curve.
radiometry.otc The radiometry bundle.

So a file carrying nothing but those reports zero, and that is not a failure. An attachment list has always meant "the files I attached", and putting the SDK's own in front of them would shift every index and every count in code written before any of them existed.

All three stay in the file and stay in the attachments array of Snapshot::metadata_json, which describes the container literally, so a reader that has never heard of this SDK sees them, and so can you.

The curve and the bundle cannot be read back as data, here or on any binding. What a file's curve is for is reached instead by opening the snapshot with Camera::open_still: the measurement is then redone through the carried curve, which is what makes a per-region emissivity and a different global emissivity work on a still. Camera::honours_region_emissivity says whether this file carried one at all.

Camera::open_still: crate::Camera::open_still Camera::honours_region_emissivity: crate::Camera::honours_region_emissivity

Errors

As Snapshot::info.

pub fn attachment_info(&self, index: usize) -> Result<AttachmentInfo>

What one application-attached file is, without reading its bytes.

Indexed over the same list Snapshot::attachment_count counts, see there for which three files are not in it.

Errors

Returns Status::InvalidArgument for an index past the end.

pub fn attachments(&self) -> Result<Vec<AttachmentInfo>>

Describe every application-attached file, in order.

Over the same list Snapshot::attachment_count counts, see there for which three files are not in it, and why an empty result is routine rather than a failure.

Errors

As Snapshot::info.

pub fn read_attachment(&self, index: usize) -> Result<Vec<u8>>

Copy one application-attached file's bytes out.

Indexed over the same list Snapshot::attachment_count counts.

Errors

Returns Status::InvalidArgument for an index past the end.