Snapshots and Interval Capture
One frame to a file, or one every N seconds, from a camera, a replay or a still. The on-disk formats themselves, and what each one can and cannot hold, are Snapshot File Formats.
In Fahrenheit: with the SDK switched to Fahrenheit (SetTemperatureUnit() and its counterparts, see Temperatures in Fahrenheit), every temperature on this page is read and written in Fahrenheit, and every difference in Fahrenheit degrees; the samples are unchanged.
The recording chapter is seven pages, each answering one question:
| Page | Question |
|---|---|
| Recording | How do I write a camera to a file? |
| A Running Recording | What is it telling me while it runs? |
| Recording File Format | What is the file, and what may a third party rely on? |
| Preview Pictures | Why does the file open on a picture, and which frame is it? |
| Snapshots and Interval Capture | How do I save one frame, or one every N seconds? |
| Recording Attachments | How do I put my own files inside the recording? |
| Playback | How do I read one back? |
A snapshot is a single frame written to a file that says what it contains. Open it anywhere (Pillow, ImageJ, MATLAB, exiftool) and you can turn a pixel into a temperature without being told anything out of band.
| Format | Pixels | Metadata | Use case |
|---|---|---|---|
| PNG | the colorized picture, with the 16-bit measurement attached | iTXt otc:meta JSON + otCa attachments |
The standard format. Archival, lossless, self-describing |
| TIFF | float32 Kelvin (or opt-in uint16) | ImageDescription JSON + private tag 65200 |
Analysis in ImageJ/Fiji, MATLAB, GDAL, tifffile |
| CSV | float Celsius or Fahrenheit text, spelled for a program or for a spreadsheet's locale | # comment header, naming the unit |
Spreadsheet import |
| JPEG | the colorized picture, and nothing measurable | otc:meta in a JPEG comment segment |
A report, a work order, an email |
SnapshotFormat (what Recorder().SaveSnapshot() and an alarm's snapshot action take) is kPng, kTiff, kCsv and kJpeg. The kJpeg arm fills the rendering from the source's own palette and colour scale, exactly as the kPng arm does, and strips the SDK's own two attachments for the reason the CSV arm does. rec::Snapshot::SaveJpeg() is still the direct call, and requires SnapshotInfo::rendering (there is nothing else in a SnapshotInfo a JPEG can hold) and refuses a non-empty attachment list rather than dropping it. Snapshot::LoadThermal() refuses a JPEG: eight bits a channel and lossy, so there are no temperatures to get back, and returning approximate ones would be worse than refusing.
The full byte-level layout of both radiometric image formats is in Snapshot File Formats.
Turning a pixel into a temperature
Temperature pixels are anchored at absolute zero, with the step size written into the file:
T_kelvin = pixel * scale T_celsius = pixel * scale - 273.15
There is no offset constant and no Optris-specific magic number: a reader needs one value out of the file and one multiply. scale is 0.01, 0.025 or 0.05 K, chosen automatically from the camera's measurement range, and every one of them converts back to the SDK's internal encoding exactly.
Taking one
imager->Recorder().SaveSnapshot() is the entry point. Going through the Imager is what fills in the camera's identity, its radiometry and its measurement range, and what lets the attachment provider contribute, so an application should not normally reach past it to rec::Snapshot.
All three formats record the metadata: the PNG in its iTXt otc:meta chunk, the TIFF in ImageDescription, the CSV in its # header. Recorder().SaveSnapshot() fills in emissivity, transmissivity, ambient temperature, model, serial, hardware and firmware revision and the measurement range from the imager; any field you set on the SnapshotInfo you pass wins over what the imager would have supplied.
#include <optrissdk.h> imager->SetThermalCallback( [&](const optris::sdk::ThermalFrame& frame) { if (!take_snapshot) return; take_snapshot = false; optris::sdk::rec::SnapshotInfo info; info.description = "line 7, bearing check"; try { imager->Recorder().SaveSnapshot(frame, "/data/capture.png", optris::sdk::SnapshotFormat::kPng, info); } catch (const optris::sdk::IoException& error) { spdlog::error("Snapshot failed: {}", error.what()); } });
/* A picture for the report... */ optris_sdk_imager_save_snapshot(imager, "/data/event.png", OPTRIS_SDK_SNAPSHOT_PNG); /* ...and the measurement to go with it. */ optris_sdk_imager_save_snapshot(imager, "/data/event.tiff", OPTRIS_SDK_SNAPSHOT_TIFF);
// A picture for the report... camera.SaveSnapshot("event.png"); // ...and the measurement to go with it. camera.SaveSnapshot("event.tiff", SnapshotFormat.Tiff);
# A picture for the report... camera.save_snapshot('event.png') # ...and the measurement to go with it. camera.save_snapshot('event.tiff', format=optris_sdk.SNAPSHOT_TIFF)
// A picture for the report... camera.save_snapshot("event.png", SnapshotFormat::Png)?; // ...and the measurement to go with it. camera.save_snapshot("event.tiff", SnapshotFormat::Tiff)?;
Taking one from a replay, or from a still
The same call, on all three kinds of source. A replay delivers the same thermal frames and the same picture a camera does, through the same FrameSource seam, and a replay is where an operator most often wants one frame out, the moment they found while scrubbing. Player::SaveSnapshot() and StillSource::SaveSnapshot() have the same two overloads Recorder::SaveSnapshot() has, and the C ABI's optris_sdk_imager_save_snapshot() and _ex() accept all three handle kinds.
#include <optrissdk.h> auto player = optris::sdk::Player::Open("/data/run.mkv"); player->SeekToTimestamp(12'000'000); player->Start(); // ... the operator finds the moment ... player->SaveSnapshot("/data/found_it.png");
optris_sdk_imager *playback = NULL; optris_sdk_imager_create_from_file("/data/run.mkv", &playback); optris_sdk_imager_seek_to_timestamp_us(playback, 12000000); optris_sdk_imager_start(playback); /* ... the operator finds the moment ... */ optris_sdk_imager_save_snapshot(playback, "/data/found_it.png", OPTRIS_SDK_SNAPSHOT_PNG);
await using var playback = ThermalCamera.OpenRecording("run.mkv"); playback.SeekTo(TimeSpan.FromSeconds(12)); playback.Start(); // ... the operator finds the moment ... playback.SaveSnapshot("found_it.png");
playback = optris_sdk.Camera.open_recording('run.mkv') playback.seek_to(12.0) playback.start() # ... the operator finds the moment ... playback.save_snapshot('found_it.png')
let mut playback = Camera::from_file("run.mkv")?; playback.seek_to_timestamp_us(12_000_000)?; playback.start()?; // ... the operator finds the moment ... playback.save_snapshot("found_it.png", SnapshotFormat::Png)?;
An alarm rule carrying a snapshot action writes a file on a replay and on a still, the same as on a camera.
Which fields a replay or still snapshot can lack
The metadata comes from the source file's own document, not from GetRadiation() and GetDeviceInfo(). Those flatten absent to a default, and a snapshot stating an emissivity nobody ever set cannot be told apart from one stating the emissivity an operator chose; the second is a measurement, so a field the source does not carry is left out rather than written as a default. A reader must treat each of these as "not recorded" rather than as zero:
That stays true even though GetRadiation() reads the metadata document. It does not report a default for a file that does state its radiometry, but it still reports one for a file that does not, because that is the honest answer to "what parameters apply to these frames". Player::HasRadiation() is how you tell which case you are in. The snapshot writer keeps reading the optionals directly, because it needs the three fields individually and one flag cannot say which of them was absent.
| Can be absent | When |
|---|---|
| emissivity, transmissivity | The source carried no radiometry block: a v11 recording, or one from another writer. |
| ambient temperature | As above, and also whenever the original had none worth writing: a camera estimating ambient with no reading yet, or configured the v11 way. Never the -100 placeholder. |
| measurement range | The source carried no range block. |
| model, serial, hardware and firmware revision | Whichever of them the source did not name. A v11 device.json carries model and serial only. |
| field of view | Carried only since the optic was recorded. |
| the characteristic curve, the radiometry bundle | The source carried neither: anything written before 12.0, or from a camera with no curve. Without them the snapshot still reads back as a measurement but cannot be re-measured at another emissivity. |
When the source did carry the curve and the bundle, both are carried forward byte for byte rather than decoded and re-encoded, so the new file can be opened as a StillSource and measured at another emissivity exactly as the source can, and so that a file from a newer writer keeps a curve this build could not have rebuilt.
Three differences from a live snapshot, all deliberate
render.overlaysisfalse. Region and blob overlays are composited into a delivered picture by the GPU backend alone, and neither a replay nor a still has one, so the picture genuinely has none in it. Recorded as a definitefalserather than left absent, because a reader drawing boxes from the region list has to know.- Attachment providers are not pulled.
SetAttachmentProvideris on a camera'sRecorder, and neither of the other two sources has a registry. What the source file carried of its own travels; what your application would have attached live does not; pass it on theSnapshotInfo. - A replay nothing is displaying produces the greyscale form. A
Playerestablishes its colour scale while delivering the picture, so with no BGRA consumer there is no range to stretch a palette over and the file keeps its 16-bit greyscale primary image, carrying no render block at all. That is the same rule a camera follows with no live view, and inventing a palette would put the file in colours nobody chose.
A still is different in one small way: it has its frame from the moment it opens, so SaveSnapshot() on one never reports "no frame captured yet". It saves what the still is measuring: oriented as SetOrientation() asked, and re-derived if ApplyConfig() put a different global emissivity in force.
This is not a way to save an edited snapshot. Measuring areas added or moved on a replay or a still are not written into the new file: the schema's RoiDefinition and the measuring model's Region have no mapping between them in either direction, so SnapshotInfo::rois is filled in by hand or not at all, on a live camera too.
Interval Capture
A time-lapse: one still image every so often, for a long unattended run. It is driven by the SDK rather than by your own timer, so the images keep coming without the application having to stay awake for them.
#include <optrissdk.h> #include <chrono> #include <filesystem> #include <print> #include <thread> auto imager = optris::sdk::Imager::Create(); imager->Start(); // One image a minute, into /data/timelapse. std::filesystem::create_directories("/data/timelapse"); imager->Recorder().StartIntervalCapture( std::chrono::minutes(1), "/data/timelapse", optris::sdk::SnapshotFormat::kPng, "night_{sequence}"); std::this_thread::sleep_for(std::chrono::hours(8)); imager->Recorder().StopIntervalCapture(); std::println("wrote {} images", imager->Recorder().GetIntervalCaptureCount());
uint64_t written = 0; /* One image a minute, into /data/timelapse. The SDK makes the folder, * and the folders above it, if they are not there yet. */ optris_sdk_imager_start_interval_capture(imager, 60000, "/data/timelapse", OPTRIS_SDK_SNAPSHOT_PNG, "night_{sequence}"); /* ... eight hours pass ... */ optris_sdk_imager_stop_interval_capture(imager); optris_sdk_imager_get_interval_capture_count(imager, &written); printf("wrote %llu images\n", (unsigned long long)written);
// One image a minute, into timelapse/. Directory.CreateDirectory("timelapse"); camera.StartIntervalCapture(TimeSpan.FromMinutes(1), "timelapse", SnapshotFormat.Png, "night_{sequence}"); await Task.Delay(TimeSpan.FromHours(8)); camera.StopIntervalCapture(); Console.WriteLine($"wrote {camera.IntervalCaptureCount} images");
import os # One image a minute, into timelapse/. os.makedirs('timelapse', exist_ok=True) camera.start_interval_capture(60.0, directory='timelapse', name_pattern='night_{sequence}') time.sleep(8 * 3600) camera.stop_interval_capture() print(f"wrote {camera.interval_capture_count} images")
// One image a minute, into timelapse/. std::fs::create_dir_all("timelapse").expect("a folder to write into"); camera.start_interval_capture(Duration::from_secs(60), "timelapse", SnapshotFormat::Png, "night_{sequence}")?; std::thread::sleep(Duration::from_secs(8 * 3600)); camera.stop_interval_capture()?; println!("wrote {} images", camera.interval_capture_count()?);
This writes night_000001.png, night_000002.png and so on.
Nothing is overwritten. A second run into the same directory with the same pattern does not replace the first run's images: a name that already exists gets a -1, -2, … suffix, up to -9999. Losing a measurement silently is the worse failure, so the SDK does not. Putting {timestamp} in the pattern is still the tidier way to keep runs apart.
One placeholder vocabulary serves every file the SDK names (a time-lapse image, an alarm snapshot, an alarm recording):
| Token | Expands to |
|---|---|
{sequence} |
A counter, zero-padded to six digits, so a directory listing sorts in capture order. Interval capture counts from 1; an alarm action uses the event's sequence. |
{timestamp} |
YYYYmmdd_HHMMSS, local time, taken from the wall clock as the file is written. |
{timestamp_us} |
The raw microsecond stamp, for correlating file names with delivered events. Not a date: on the Linux USB transports a frame's capture stamp is a steady_clock reading, microseconds since the host booted. |
{serial}, {model} |
The camera's serial number and model. |
{rule}, {region} |
The alarm rule and the measuring area it watched. Empty in a time-lapse. |
A placeholder with no context behind it expands to nothing, not to the literal token: {rule} in a time-lapse name names nothing, and leaving the braces in the file name would be the worse answer. Each substituted value is sanitized on its own before the result is, so a rule named ../../etc/passwd cannot walk out of the output directory.
Images are written on a thread of the SDK's own, never on the one delivering frames, so a slow disk cannot stall the camera. The same holds for a recording: see What a recording needs from its target.
Properties:
- Interval capture and recording are independent. A time-lapse keeps running when a recording stops, and vice versa.
Stop()does not end it;StopIntervalCapture()does. - An interval shorter than the frame period is raised to the frame period. No more images than frames can exist, so asking for 1 ms on a 27 fps camera gets you one image per frame rather than an error.
GetIntervalCaptureInterval()reports what is actually in force, and the adjustment is logged once. - Missed ticks are skipped, not queued. If the machine stalls for a minute, the time-lapse resumes on the next tick instead of writing a minute's worth of images back to back. The cadence is measured from the previous tick, so it does not drift.
GetIntervalCaptureCount()counts images that reached disk, so it is the honest number if writes are failing.- The folder is made if it is not there yet, with the folders above it, because the SDK names every file in it. A folder that cannot be made or written to (a file in its place, no permission) is refused when the capture starts, with the SDK's I/O error naming the folder, and nothing starts. SDK 12.0.22 and earlier started such a capture without an error and wrote nothing. The C++, C#, Python and Rust samples above still create the folder themselves, as a program writing anywhere else would; C has no portable call for it and leaves it to the SDK.
For a snapshot taken from a UI button or a timer, where there is no frame to hand, there is an overload that uses the most recent frame the SDK received. It throws if no frame has arrived yet, rather than writing a blank one.
// From any thread, once the camera is streaming: imager->Recorder().SaveSnapshot("/data/capture.png"); imager->Recorder().SaveSnapshot("/data/capture.tiff", optris::sdk::SnapshotFormat::kTiff);
/* From any thread, once the camera is streaming: */ optris_sdk_imager_save_snapshot(imager, "/data/capture.png", OPTRIS_SDK_SNAPSHOT_PNG); optris_sdk_imager_save_snapshot(imager, "/data/capture.tiff", OPTRIS_SDK_SNAPSHOT_TIFF);
// From any thread, once the camera is streaming: camera.SaveSnapshot("capture.png"); camera.SaveSnapshot("capture.tiff", SnapshotFormat.Tiff);
# From any thread, once the camera is streaming: camera.save_snapshot('capture.png') camera.save_snapshot('capture.tiff', format=optris_sdk.SNAPSHOT_TIFF)
// From any thread, once the camera is streaming: camera.save_snapshot("capture.png", SnapshotFormat::Png)?; camera.save_snapshot("capture.tiff", SnapshotFormat::Tiff)?;
Reading one back
The reader is part of the format, not a follow-up. Attaching a calibration blob would be pointless if nothing could get it back out.
#include <optrissdk.h> namespace rec = optris::sdk::rec; try { auto info = rec::Snapshot::ReadInfo("/data/capture.png"); for (const auto& attachment : info.attachments) { // attachment.data has already been checked against the // SHA-256 recorded in the file. } auto frame = rec::Snapshot::LoadThermal("/data/capture.png"); // Bit-exact: the internal value that went in comes back out. } catch (const optris::sdk::SdkException& e) { std::println(stderr, "{}", e.what()); }
ReadInfo() and LoadThermal() throw on failure, like the rest of the C++ surface. ReadInfo() raises InvalidArgumentException for a file with no otc:meta chunk (which is exactly how a file from before this format is recognized) and IoException when an attachment fails its SHA-256 check.
camera.SaveSnapshot("event.tiff", SnapshotFormat.Tiff, new SnapshotInfo { Description = "bearing 3, second shift", Emissivity = 0.95f, }); using Snapshot snapshot = Snapshot.Open("event.tiff"); Console.WriteLine(snapshot.Info.Description); Console.WriteLine($"{snapshot.Width}x{snapshot.Height}, {snapshot.Encoding}"); using ThermalFrame measured = snapshot.LoadThermal(); Console.WriteLine($"{measured.GetTemperature(0, 0):F1} C at the top left"); foreach (AttachmentInfo carried in snapshot.Attachments) { Console.WriteLine($"{carried.Name} ({carried.Mime}), {carried.Size} bytes"); }
From C, C#, Python and Rust
The reader is on the ABI, and every binding is built on it, so no caller has to decode the image and the otc:meta document itself, which would be a second copy of the SDK's own format, to write and then to maintain.
The shape is the same everywhere: open the file once, then ask it questions. Opening verifies a SHA-256 per attachment, so it is not a call to make in a loop.
optris_sdk_snapshot *snap = NULL; if (optris_sdk_snapshot_open("/data/capture.png", &snap) == OPTRIS_SDK_OK) { optris_sdk_snapshot_info info; optris_sdk_snapshot_info_init(&info, sizeof(info)); optris_sdk_snapshot_get_info(snap, &info); printf("%s %s, emissivity %.2f\n", info.device_model, info.device_serial, info.has_emissivity ? (double)info.emissivity : 1.0); /* The temperatures, as an ordinary frame: get_info(), get_data() and * get_temperature() all work on it. Free it with frame_free(). */ optris_sdk_frame *frame = NULL; if (optris_sdk_snapshot_acquire_frame(snap, &frame) == OPTRIS_SDK_OK) { float centre = 0.0f; optris_sdk_frame_get_temperature(frame, 160, 120, ¢re); optris_sdk_frame_free(frame); } size_t count = 0; optris_sdk_snapshot_get_attachment_count(snap, &count); optris_sdk_snapshot_close(snap); }
snap = optris_sdk.Snapshot.open('capture.png') info = snap.info print(f"{info.device_model} {info.device_serial}, " f"emissivity {info.emissivity}") # The temperatures, as an ordinary frame. frame = snap.load_thermal() centre = frame.celsius(160, 120) print(len(snap.attachments)) snap.close()
let snap = Snapshot::open("capture.png")?; let info = snap.info()?; println!("{} {}", info.device_model, info.device_serial); // The temperatures, as an ordinary frame. let frame = snap.load_thermal()?; let centre = frame.temperature_at(160, 120)?; println!("{}", snap.attachments()?.len());
optris_sdk_snapshot_get_metadata_json() hands back the whole document (the pixel scale, the scene statistics, the capture telemetry, the regions, the attachment index and anything the writer merged in) for the cases the fixed struct does not cover.
Ask what a file holds before you read it. optris_sdk_snapshot_get_encoding() answers TEMPERATURE, RAW_ADU or ENERGY. Calling acquire_frame() on a raw-ADU file is refused with OPTRIS_SDK_ERROR_NOT_SUPPORTED rather than reinterpreted, and read_raw_pixels() on a temperature file is refused the same way.
CSV stays write-only. It carries no metadata document, so optris_sdk_snapshot_open() reports that rather than guessing.
Writing with metadata, from a binding
optris_sdk_imager_save_snapshot() takes a path and a format, and that is all it ever took. optris_sdk_imager_save_snapshot_ex() adds what C++ always had: the operator's description, the radiometry to record, a JSON object of your own merged into the document, and the encoder settings.
optris_sdk_snapshot_info info; optris_sdk_snapshot_info_init(&info, sizeof(info)); snprintf(info.description, sizeof(info.description), "north bearing, shift 2"); info.has_emissivity = 1; info.emissivity = 0.95f; optris_sdk_imager_save_snapshot_ex(imager, "/data/capture.png", OPTRIS_SDK_SNAPSHOT_PNG, &info, "{\"layout\":\"line 4\"}", NULL);
info = optris_sdk.SnapshotInfo(description='north bearing, shift 2', emissivity=0.95) camera.save_snapshot('capture.png', info=info, extra_json='{"layout": "line 4"}')
let mut info = SnapshotInfo::default(); info.description = "north bearing, shift 2".to_string(); info.emissivity = Some(0.95); camera.save_snapshot_with("capture.png", SnapshotFormat::Png, Some(&info), None, Some(r#"{"layout": "line 4"}"#))?;
The camera's identity, radiometry and measurement range are still filled in for you; anything set explicitly in info wins. The same optris_sdk_snapshot_info comes back out of optris_sdk_snapshot_get_info(), so a round trip through disk is expressible in one type.
A CSV for a spreadsheet in another locale
A CSV snapshot is written for programs: , between values, . before the decimals, nan for a pixel that was not measured, and # header lines on top. A spreadsheet set to German, French or most other European locales splits on ; and reads , as the decimal separator, so it opens that file as one text column per row with nothing in it a number.
SaveCsvSnapshot() writes the CSV in the spelling you choose. CsvOptions has four settings, and each default is what a CSV snapshot has always been:
| Setting | Default | Alternatives |
|---|---|---|
| delimiter | , |
; or a tab |
| decimal separator | . |
, (it applies to the header's numbers too) |
| leave unmeasured empty | off: nan |
on: an empty field, which every spreadsheet shows as a blank cell |
| omit header lines | off: the # lines are written |
on: the file is the table and nothing else |
optris::sdk::rec::CsvOptions csv; csv.delimiter = ';'; csv.decimal_separator = ','; csv.leave_unmeasured_empty = true; imager->Recorder().SaveCsvSnapshot("capture.csv", csv);
optris_sdk_csv_options csv; optris_sdk_csv_options_init(&csv, sizeof(csv)); csv.delimiter = ';'; csv.decimal_separator = ','; csv.leave_unmeasured_empty = 1; optris_sdk_imager_save_csv_snapshot(imager, "capture.csv", NULL, &csv);
camera.SaveCsvSnapshot("capture.csv", new CsvOptions { Delimiter = ';', DecimalSeparator = ',', LeaveUnmeasuredEmpty = true, });
camera.save_csv_snapshot('capture.csv', optris_sdk.CsvOptions( delimiter=';', decimal_separator=',', leave_unmeasured_empty=True))
let csv = CsvOptions::default() .with_delimiter(';') .with_decimal_separator(',') .with_unmeasured_left_empty(true); camera.save_csv_snapshot("capture.csv", &csv, None)?;
The file depends on these settings and on nothing else. The process locale, the thread's culture and the Windows regional settings never reach it, so one call writes the same bytes on every machine. To follow the user's own settings, read them in your application (in .NET, CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator and TextInfo.ListSeparator) and pass the two characters.
Any other delimiter or decimal separator is refused with the SDK's invalid-argument error, and so is a decimal separator equal to the delimiter, because a reader could not tell 1,5 from two values. Nothing is written then. The call takes the same SnapshotInfo as SaveSnapshot(), fills in the same metadata, and works on a camera, a replay and a still. An alarm's snapshot action writes its CSV in the default spelling.
A CSV in degrees Fahrenheit
A CSV snapshot is the one file the SDK writes as numbers for a person to read, so it can be written in the unit that person reads. Everything else the SDK writes and every number its API hands back stays in degrees Celsius, so a recording or a stored setting never depends on the unit somebody was looking at.
The unit is one more setting in CsvOptions, and it composes with the spelling above:
optris::sdk::rec::CsvOptions csv; csv.temperature_unit = optris::sdk::TemperatureUnit::kFahrenheit; csv.delimiter = ';'; csv.decimal_separator = ','; imager->Recorder().SaveCsvSnapshot("capture_f.csv", csv);
optris_sdk_csv_options csv; optris_sdk_csv_options_init(&csv, sizeof(csv)); csv.temperature_unit = OPTRIS_SDK_TEMPERATURE_UNIT_FAHRENHEIT; csv.delimiter = ';'; csv.decimal_separator = ','; optris_sdk_imager_save_csv_snapshot(imager, "capture_f.csv", NULL, &csv);
camera.SaveCsvSnapshot("capture_f.csv", new CsvOptions { TemperatureUnit = TemperatureUnit.Fahrenheit, Delimiter = ';', DecimalSeparator = ',', });
camera.save_csv_snapshot('capture_f.csv', optris_sdk.CsvOptions( temperature_unit=optris_sdk.TEMPERATURE_UNIT_FAHRENHEIT, delimiter=';', decimal_separator=','))
let csv = CsvOptions::default() .with_temperature_unit(TemperatureUnit::Fahrenheit) .with_delimiter(';') .with_decimal_separator(','); camera.save_csv_snapshot("capture_f.csv", &csv, None)?;
What changes in a Fahrenheit file, and what does not:
| Celsius (the default) | Fahrenheit | |
|---|---|---|
| the pixels | degrees Celsius, two decimals | each value converted at full precision, then rounded once to two decimals, half away from zero |
| a pixel that was not measured | nan (or empty) |
the same |
| the unit line | # Unit: degC |
# Unit: degF |
| the ambient line | # AmbientTempC: 23.50 |
# AmbientTempF: 74.30 |
| emissivity, transmissivity, the capture lines | unchanged | unchanged: they are not temperatures |
Each Fahrenheit value is within 0.005 of the Celsius value of the same pixel × 9/5 + 32: a pixel holds a tenth of a degree Celsius, which is an exact 0.18 °F, so the Fahrenheit file loses nothing to the conversion. The rounding is the one Temperatures::Format() uses (see Showing a temperature in Fahrenheit), so a number in the file and the same number on a screen agree in their last digit.
Every CSV names its unit, a Celsius file too. The # Unit: line is the second line of the header. A program that skips the # lines, as a reader of the earlier files had to, is not affected by it; leaving the header out (omit_header_lines) leaves the unit line out with the rest.
An interval capture writing CSV takes the same options, as a fifth argument:
#include <filesystem> optris::sdk::rec::CsvOptions csv; csv.temperature_unit = optris::sdk::TemperatureUnit::kFahrenheit; std::filesystem::create_directories("/data/timelapse"); imager->Recorder().StartIntervalCapture( std::chrono::minutes(1), "/data/timelapse", optris::sdk::SnapshotFormat::kCsv, "night_{sequence}", csv);
optris_sdk_csv_options csv; optris_sdk_csv_options_init(&csv, sizeof(csv)); csv.temperature_unit = OPTRIS_SDK_TEMPERATURE_UNIT_FAHRENHEIT; /* The SDK makes /data/timelapse if it is not there yet. */ optris_sdk_imager_start_interval_capture_ex(imager, 60000, "/data/timelapse", OPTRIS_SDK_SNAPSHOT_CSV, "night_{sequence}", &csv);
Directory.CreateDirectory("timelapse"); camera.StartIntervalCapture( TimeSpan.FromMinutes(1), "timelapse", SnapshotFormat.Csv, "night_{sequence}", new CsvOptions { TemperatureUnit = TemperatureUnit.Fahrenheit });
import os os.makedirs('timelapse', exist_ok=True) camera.start_interval_capture( 60.0, directory='timelapse', format=optris_sdk.SNAPSHOT_CSV, name_pattern='night_{sequence}', csv=optris_sdk.CsvOptions( temperature_unit=optris_sdk.TEMPERATURE_UNIT_FAHRENHEIT))
let csv = CsvOptions::default().with_temperature_unit(TemperatureUnit::Fahrenheit); std::fs::create_dir_all("timelapse").expect("a folder to write into"); camera.start_interval_capture_with( Duration::from_secs(60), "timelapse", SnapshotFormat::Csv, "night_{sequence}", &csv, )?;
The call without the options writes the default Celsius file, so a capture started with it afterwards does not keep the unit of an earlier one. A unit other than the two is refused with the SDK's invalid-argument error and nothing is written or started. An alarm's snapshot action writes its CSV in Celsius with the default spelling. PNG and TIFF snapshots carry no temperature as text and are not affected: they are byte for byte what they were. A JPEG snapshot carries one sentence describing the scene, and that sentence follows the display unit (see Temperatures in Fahrenheit); its metadata stays in Celsius.
Snapshot Export
Recorder().SaveSnapshot() is the normal route, because it fills in the camera's metadata. rec::Snapshot is the stateless writer underneath it, for frames that did not come from an open imager; there the metadata is whatever you put in the SnapshotInfo.
#include <optrissdk.h> #include <atomic> #include <iostream> #include <print> int main() { auto imager = optris::sdk::Imager::Create(); optris::sdk::rec::SnapshotInfo info; info.emissivity = 0.95f; info.device_model = imager->GetDeviceInfo().model; info.device_serial = imager->GetDeviceInfo().serial; std::atomic<bool> saved = false; imager->SetThermalCallback( [&](const optris::sdk::ThermalFrame& frame) { if (saved.exchange(true)) return; namespace rec = optris::sdk::rec; try { rec::Snapshot::SavePng(frame, "/tmp/snapshot.png", info); rec::Snapshot::SaveCsv(frame, "/tmp/snapshot.csv", info); rec::Snapshot::SaveTiff(frame, "/tmp/snapshot.tiff", info); } catch (const optris::sdk::SdkException& e) { std::println(stderr, "Snapshot failed: {}", e.what()); } std::println("Snapshots written."); }); imager->Start(); std::println("Press Enter to quit."); std::cin.get(); imager->Stop(); }