Recording
Start a recording, stop it, and understand the four ways starting can be refused. Everything a recording reports once it is running is the next page; what ends up in the file is the one after that.
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? |
Overview
The SDK records thermal data to MKV container files using the FFV1 lossless codec, preserving the full 16-bit radiometric data, and plays those files back through Player, which shares the FrameSource interface with Imager: the same callbacks, frame types, measuring areas and alarm rules.
Recording is reached through imager->Recorder() (optris/sdk/recorder.h), a handle owned by the imager. Playback is a separate type, Player (optris/sdk/player.h), opened with Player::Open().
Key features:
- Pre-roll ring buffer captures frames before the recording starts, so events that happen unexpectedly are not lost.
- Alarm-driven recording: a
Rulecarrying aRecordingActionstarts and stops a recording itself, whether its input is a measuring area, a PIF input or a device signal. - Playback with
Player::Open(), measured by the same region and alarm pass a live frame goes through. - Seeking and speed control during playback with
SeekToFrame(),SeekToTimestamp(),SetSpeed(), andSetLoop(). - Preview pictures in every recording: a clean cover for file managers and a notice track that VLC shows in place of a near-black picture, held on screen for the first three minutes. See The preview pictures.
- Snapshot export saves individual frames as PNG, TIFF or CSV with embedded metadata. A PNG snapshot is the colorized picture (palette, colour scale and region overlays exactly as they were on screen) with the 16-bit radiometric data carried losslessly inside it as an attachment. TIFF stays radiometric, because it is the format analysis tools read numbers from. A fourth format, JPEG, carries the picture and nothing measurable; it is reached through
rec::Snapshot::SaveJpeg()rather than throughSnapshotFormat.
Starting and Stopping
Recording is started and stopped through Imager::Recorder():
#include <optrissdk.h> auto imager = optris::sdk::Imager::Create(); imager->Start(); // Start recording to an MKV file. imager->Recorder().Start("/data/capture_001.mkv"); // ... frames are being recorded ... // Check if recording is active. if (imager->Recorder().IsRecording()) { // Stop recording and finalize the file. imager->Recorder().Stop(); }
int recording = 0; /* Start recording to an MKV file. */ optris_sdk_imager_start_recording(imager, "/data/capture_001.mkv"); /* ... frames are being recorded ... */ /* Check if recording is active. */ optris_sdk_imager_is_recording(imager, &recording); if (recording) { /* Stop recording and finalize the file. */ optris_sdk_imager_stop_recording(imager); }
camera.Start(); camera.StartRecording("run.mkv"); await Task.Delay(TimeSpan.FromSeconds(10)); camera.StopRecording();
# Start recording to an MKV file. camera.start_recording('capture_001.mkv') # ... frames are being recorded ... # Check if recording is active. if camera.is_recording: # Stop recording and finalize the file. camera.stop_recording()
// Start recording to an MKV file. camera.start_recording("capture_001.mkv")?; // ... frames are being recorded ... // Check if recording is active. if camera.is_recording()? { // Stop recording and finalize the file. camera.stop_recording()?; }
Start() throws SdkException if the file cannot be opened. Calling it while a recording is already running does nothing: there is one recorder per imager, and the running recording is neither replaced nor restarted. When Stop() returns, the file is finalized and can be opened, copied or played at once; Stop() with nothing recording is a no-op. A recording runs until Stop() is called, a time limit it was started with runs out, an alarm rule stops it, or the imager is destroyed. Stopping the imager's stream does not end the recording by itself.
Pre-Roll Buffer
The pre-roll feature maintains a fixed-duration ring buffer that continuously captures frames. When recording starts (via API or trigger), the buffer contents are flushed to disk first, so the recording includes frames from before the trigger event.
#include <optrissdk.h> #include <chrono> auto imager = optris::sdk::Imager::Create(); // Enable a 30-second pre-roll buffer. imager->Recorder().EnablePreRoll(std::chrono::seconds(30)); imager->Start(); // ... time passes, something interesting happens ... // Recording starts with the last 30 seconds already captured. imager->Recorder().Start("/data/event.mkv"); // ... record more ... imager->Recorder().Stop(); // Disable pre-roll when no longer needed. imager->Recorder().DisablePreRoll();
/* Enable a 30-second pre-roll buffer. */ optris_sdk_imager_enable_pre_roll_ms(imager, 30000); optris_sdk_imager_start(imager); /* ... time passes, something interesting happens ... */ /* Recording starts with the last 30 seconds already captured. */ optris_sdk_imager_start_recording(imager, "/data/event.mkv"); /* ... record more ... */ optris_sdk_imager_stop_recording(imager); /* Disable pre-roll when no longer needed. */ optris_sdk_imager_disable_pre_roll(imager);
camera.EnablePreRoll(TimeSpan.FromSeconds(5)); camera.Start(); // ... something happens ... // The file begins five seconds before this line. camera.StartRecording("event.mkv");
# Enable a 5-second pre-roll buffer. camera.enable_pre_roll(5.0) # ... something happens ... # The file begins five seconds before this line. camera.start_recording('event.mkv') camera.stop_recording() # Disable pre-roll when no longer needed. camera.disable_pre_roll()
// Enable a 5-second pre-roll buffer. camera.enable_pre_roll(Duration::from_secs(5))?; // ... something happens ... // The file begins five seconds before this line. camera.start_recording("event.mkv")?; camera.stop_recording()?; // Disable pre-roll when no longer needed. camera.disable_pre_roll()?;
The buffer depth is computed from the imager's frame rate and the requested duration. At 30 fps with a 30-second buffer, approximately 900 frames are kept in memory.
Ask for what you actually want, in milliseconds, and read back what you got. EnablePreRoll() takes std::chrono::milliseconds, so std::chrono::seconds(30) above still works and std::chrono::milliseconds(900) now means 900 ms rather than nothing. Two adjustments are made to the request, and both are readable rather than silent:
- a duration shorter than one frame period becomes one frame, because a buffer cannot hold less than that;
- a depth that would cost more than the memory budget is cut to what fits.
Every buffered frame is a full copy of the pixel data, so the memory matters: 30 s of a 640x480 sensor at 32 Hz is about 600 MB. The budget is 512 MiB by default and the depth is shortened to fit rather than the request being refused.
#include <optrissdk.h> #include <chrono> #include <print> auto imager = optris::sdk::Imager::Create(); // 256 MiB is all this pre-roll may have. imager->Recorder().SetPreRollMemoryBudget(256ULL * 1024 * 1024); imager->Recorder().EnablePreRoll(std::chrono::milliseconds(2500)); const auto pre_roll = imager->Recorder().GetPreRoll(); std::println("pre-roll: {} ms asked, {} ms held, {} of {} frames, {}", pre_roll.duration.count(), pre_roll.held.count() / 1000, pre_roll.buffered, pre_roll.frames, pre_roll.holds_duration ? "full" : "filling");
optris_sdk_pre_roll_state pre_roll; /* 256 MiB is all this pre-roll may have. */ optris_sdk_imager_set_pre_roll_memory_budget( imager, 256ULL * 1024 * 1024); optris_sdk_imager_enable_pre_roll_ms(imager, 2500); optris_sdk_pre_roll_state_init(&pre_roll, sizeof(pre_roll)); optris_sdk_imager_get_pre_roll_state(imager, &pre_roll); printf("pre-roll: %u ms asked, %u of %u frames, %s\n", pre_roll.duration_ms, pre_roll.buffered, pre_roll.frames, pre_roll.holds_duration ? "full" : "filling");
camera.EnablePreRoll(TimeSpan.FromMilliseconds(2500)); PreRollState state = camera.PreRoll; Console.WriteLine( $"{state.Duration.TotalSeconds:0.0} s asked, " + $"{state.Held.TotalSeconds:0.0} s held, " + $"{state.Buffered} of {state.Frames} frames, " + $"{(state.HoldsDuration ? "full" : "filling")}");
# 256 MiB is all this pre-roll may have. camera.pre_roll_memory_budget = 256 * 1024 * 1024 camera.enable_pre_roll(2.5) state = camera.pre_roll held = 'full' if state.holds_duration else 'filling' print(f"pre-roll: {state.duration_s:.1f} s asked, " f"{state.held_s:.1f} s held, " f"{state.buffered} of {state.frames} frames, {held}")
// 256 MiB is all this pre-roll may have. camera.set_pre_roll_memory_budget(256 * 1024 * 1024)?; camera.enable_pre_roll(Duration::from_millis(2500))?; let pre_roll = camera.pre_roll_state()?; println!("pre-roll: {} ms asked, {} us held, {} of {} frames, {}", pre_roll.duration_ms, pre_roll.held_us, pre_roll.buffered, pre_roll.frames, if pre_roll.holds_duration { "full" } else { "filling" });
EnablePreRoll() throws on a duration of zero or less.
Wait on holds_duration, not on buffered == frames. frames is derived from the sensor's rate while the ring keeps a fixed number of seconds, so on a camera that delivers more slowly than its sensor runs (one you have asked for fewer frames per second, or an export-restricted one held to 9), the two counts never meet. A 32 Hz camera delivering 9 fps with 5 s armed holds its whole 5 s in about 45 of its 160 frames, and buffered == frames stays false for as long as the camera is armed. holds_duration is the SDK's answer and covers both cases; held is the span actually held, which is the number to show a user, and it settles just under duration because a span is measured between two frames' stamps.
holds_duration goes false again when a recording starts: the recording takes the whole ring, so the pre-roll genuinely begins refilling from nothing.
Starting a recording does not wait for the pre-roll to be written out. The buffered frames are encoded on the SDK's own thread, so Start() returns immediately and frame delivery is not interrupted while the history is written. The pre-roll still reaches the file, in order, ahead of the live frames.
A change of frame size empties the buffer. A camera reports one geometry while it is still calibrating and settles on another a moment later; a buffer holding both cannot be written into one stream. The older history is dropped and the buffer refills at the new size, which costs a few seconds of pre-roll rather than all of it.
Timed Recording
Recorder::Start() has an overload that takes a duration. The recording stops itself when the time is up, so nothing has to sit and wait for it, which matters most for a recording an alarm started, since there is no application call to close it.
#include <optrissdk.h> #include <chrono> #include <thread> auto imager = optris::sdk::Imager::Create(); imager->Start(); // Record for thirty seconds, hands off. imager->Recorder().Start("/data/clip.mkv", std::chrono::seconds(30)); while (imager->Recorder().IsRecording()) { std::this_thread::sleep_for(std::chrono::milliseconds(250)); } // The file is finalized and can be opened by Player.
int recording = 1; /* Record for thirty seconds, hands off. */ optris_sdk_imager_start_recording_for(imager, "/data/clip.mkv", 30000); while (recording) { optris_sdk_imager_is_recording(imager, &recording); } /* The file is finalized and can be opened as a recording. */
// Record for thirty seconds, hands off. camera.StartRecording("clip.mkv", TimeSpan.FromSeconds(30)); while (camera.IsRecording) { await Task.Delay(TimeSpan.FromMilliseconds(250)); } // The file is finalized and can be opened as a recording.
import time # Record for two seconds, hands off. camera.start_recording('clip.mkv', duration_s=2.0) while camera.is_recording: time.sleep(0.25) # The file is finalized and can be opened as a recording.
// Record for thirty seconds, hands off. camera.start_recording_for("clip.mkv", Duration::from_secs(30))?; while camera.is_recording()? { std::thread::sleep(Duration::from_millis(250)); } // The file is finalized and can be opened as a recording.
GetRemainingRecordingTime() reports how long is left, for a progress display. It is zero when nothing is recording, and also when the running recording has no time limit.
Stopping early with Stop() is fine and cancels the deadline. Stopping is safe from any thread and can be called as often as you like: a recording that has already stopped, including one that stopped itself, is left alone rather than closed a second time.
With pre-roll enabled, the clock starts when the recording goes live, after the pre-roll buffer has been flushed. The duration therefore bounds what is recorded from that moment onwards, and the file ends up roughly pre-roll + duration long. This is the reading that matches what callers ask for ("record the next thirty seconds"), and it means a two-second pre-roll and a one-second duration produce a three-second file rather than stopping immediately.
Starting twice
A recording is one at a time. Calling Start() while a recording is running throws optris::sdk::InvalidStateException and changes nothing: the running recording keeps its own file, and the path you just passed is not created.
If more than one thing in your application can start a recording (a button, a "record all", a keyboard shortcut, an alarm rule), either gate them on IsRecording() or catch the exception.
#include <optrissdk.h> auto imager = optris::sdk::Imager::Create(); imager->Start(); imager->Recorder().Start("/data/first.mkv"); try { imager->Recorder().Start("/data/second.mkv"); } catch (const optris::sdk::InvalidStateException &e) { // "already recording to '/data/first.mkv'" }
optris_sdk_imager_start_recording(imager, "/data/first.mkv"); if (optris_sdk_imager_start_recording(imager, "/data/second.mkv") == OPTRIS_SDK_ERROR_INVALID_STATE) { /* "already recording to '/data/first.mkv'" */ }
if (!camera.IsRecording) { camera.StartRecording(path); }
camera.start_recording('first.mkv') try: camera.start_recording('second.mkv') except optris_sdk.StateError: pass # "already recording to 'first.mkv'" finally: camera.stop_recording()
camera.start_recording("first.mkv")?; match camera.start_recording("second.mkv") { Err(e) if e.status() == Status::InvalidState => { // "already recording to 'first.mkv'" } other => other?, } camera.stop_recording()?;
An alarm rule that would have started a recording while one is running still does not interrupt it, and now reports that it was skipped through the action-error channel instead of doing nothing silently.
No room to start
RecordingOptions::min_free_bytes refuses a start below a floor you set. Zero, the default, does not check. The refusal happens before anything is opened and throws optris::sdk::InsufficientSpaceException, naming what was free and what was required.
It is honoured by an alarm rule's RecordingAction as well, and that is why it exists. A rule starts the camera's recording on the SDK's own action thread, with no call of yours in front of it to check anything, so an application that refused its own starts on a nearly full disk still had an alarm start one behind its back, which its own low-water watch then stopped seconds later, and the next activation started another. Set the same number on RecordingAction::options and one check covers both paths. A rule's refusal arrives on the action-error channel rather than as an exception, that being the only channel a rule's action has.
The same name, unit and "zero is off" convention as rec::RetentionPolicy::min_free_bytes, which continuous recording has had since it existed. Two deliberate differences:
- No headroom is added. Continuous recording refuses below its floor plus room for one segment, because it writes continuously and prunes against that floor for the life of the recording. This is the plain threshold an application's own "refuse to start under N" setting means, and adding headroom would refuse starts your own number allows.
- It is a floor at the start and nothing else. Nothing stops a recording that has already begun. A volume that fills up mid-recording is a different question: continuous recording has a retention window to trade against, so it can prune or stop (
rec::DiskFullAction); a plain recording has neither, and a running stop on a timer is a policy the SDK deliberately does not own.
A name already in use
Start() will not overwrite a file. A path that already holds a regular file throws optris::sdk::PathExistsException, naming the path, and nothing is opened. A caller that means to replace a fixed name (a latest.mkv, a nightly that reuses one path) removes it first; one std::filesystem::remove() is the whole of it.
The file checked is the first one the recording is about to write, which is run_part000.mkv whenever you asked for a segment limit, see Splitting a long recording. The message names that file as well as the name you gave, so you do not have to work out the relation between the two yourself. Ask for no segment limit and they are the same file.
#include <optrissdk.h> auto imager = optris::sdk::Imager::Create(); imager->Start(); try { imager->Recorder().Start("/data/run.mkv"); } catch (const optris::sdk::PathExistsException &e) { // "'/data/run.mkv' already exists and will not be overwritten" imager->Recorder().Start("/data/run-2.mkv"); }
if (optris_sdk_imager_start_recording(imager, "/data/run.mkv") == OPTRIS_SDK_ERROR_ALREADY_EXISTS) { /* "'/data/run.mkv' already exists and will not be overwritten" */ optris_sdk_imager_start_recording(imager, "/data/run-2.mkv"); }
try { camera.StartRecording("run.mkv"); } catch (PathExistsException) { camera.StartRecording("run-2.mkv"); }
try: camera.start_recording('run.mkv') except optris_sdk.PathExistsError: # "'run.mkv' already exists and will not be overwritten" camera.start_recording('run-2.mkv') camera.stop_recording()
match camera.start_recording("run.mkv") { Err(e) if e.status() == Status::AlreadyExists => { // "'run.mkv' already exists and will not be overwritten" camera.start_recording("run-2.mkv")?; } other => other?, } camera.stop_recording()?;
PathExistsException derives from SdkException, so a broad catch keeps working. It is a type of its own so that choosing another name is a decision your code can make: across the C ABI it is OPTRIS_SDK_ERROR_ALREADY_EXISTS, in .NET PathExistsException, in Python PathExistsError and in Rust Status::AlreadyExists. Until that status existed the refusal reached C as OPTRIS_SDK_ERROR_UNKNOWN, which is what a caller is told when something has gone genuinely wrong, so there was nothing to branch on but the message.
Only a regular file is refused. A directory, a device node or a FIFO holds no measurement to lose and still gets the real reason it could not be opened; recording to /dev/full is how a full disk is staged, and it still reaches the write failure it is meant to. A symlink is followed, because the file it points at is the one that would be lost; a dangling one is not a regular file, so the start proceeds and creates the target.
Only a path you named. Interval capture and alarm-fired recordings keep moving to the next free name, because the SDK chooses those names itself, see the -1, -2, … rule under Interval Capture. A rollover is not refused either: once a split recording is running, the names it moves on to are the SDK's own. Only the first file is checked, which on a split recording is _part000. Start() takes your string, so recording somewhere else would trade one silent surprise for another.
Record 10 Seconds
#include <optrissdk.h> #include <chrono> #include <print> #include <thread> int main() { optris::sdk::SimulatedConfig cfg; cfg.width = 160; cfg.height = 120; cfg.framerate = 30; cfg.pattern = optris::sdk::TestPattern::kGradient; auto imager = optris::sdk::Imager::Create(cfg); imager->Start(); // Stops itself after ten seconds. imager->Recorder().Start("/tmp/test_recording.mkv", std::chrono::seconds(10)); std::println("Recording started..."); while (imager->Recorder().IsRecording()) { std::this_thread::sleep_for(std::chrono::milliseconds(250)); } std::println("Recording stopped."); imager->Stop(); }
#include <stdio.h> #include "optris/sdk_c.h" int main(void) { optris_sdk_simulated_config cfg; optris_sdk_imager *camera = NULL; int recording = 1; optris_sdk_simulated_config_init(&cfg, sizeof(cfg)); cfg.width = 160; cfg.height = 120; cfg.framerate = 30; cfg.pattern = OPTRIS_SDK_PATTERN_GRADIENT; optris_sdk_imager_create_simulated(&cfg, &camera); optris_sdk_imager_start(camera); /* Stops itself after ten seconds. */ optris_sdk_imager_start_recording_for(camera, "/tmp/test_recording.mkv", 10000); printf("Recording started...\n"); while (recording) { optris_sdk_imager_is_recording(camera, &recording); } printf("Recording stopped.\n"); optris_sdk_imager_stop(camera); optris_sdk_imager_destroy(camera); return 0; }
using Optris.Sdk; await using ThermalCamera simulated = ThermalCamera.OpenSimulated( new SimulatedCameraOptions { Width = 160, Height = 120, FrameRate = 30, Pattern = TestPattern.Gradient, }); simulated.Start(); // Stops itself after ten seconds. simulated.StartRecording("test_recording.mkv", TimeSpan.FromSeconds(10)); Console.WriteLine("Recording started..."); while (simulated.IsRecording) { await Task.Delay(TimeSpan.FromMilliseconds(250)); } Console.WriteLine("Recording stopped."); simulated.Stop();
import time import optris_sdk config = optris_sdk.SimulatedCamera(width=160, height=120, framerate=30, pattern=optris_sdk.PATTERN_GRADIENT) with optris_sdk.Camera.simulated(config) as simulated: simulated.start() # Stops itself after two seconds. simulated.start_recording('test_recording.mkv', duration_s=2.0) print('Recording started...') while simulated.is_recording: time.sleep(0.25) print('Recording stopped.') simulated.stop()
use optris_sdk::{Camera, SimulatedConfig, TestPattern}; fn main() -> optris_sdk::Result<()> { let cfg = SimulatedConfig::new() .resolution(160, 120) .framerate(30) .pattern(TestPattern::Gradient); let mut simulated = Camera::simulated(&cfg)?; simulated.start()?; // Stops itself after ten seconds. simulated.start_recording_for("test_recording.mkv", std::time::Duration::from_secs(10))?; println!("Recording started..."); while simulated.is_recording()? { std::thread::sleep(std::time::Duration::from_millis(250)); } println!("Recording stopped."); simulated.stop()?; Ok(()) }
Alarm-Triggered Recording
#include <optrissdk.h> #include <chrono> #include <cstddef> #include <print> #include <string_view> #include <thread> #include <vector> // Your own process context, as bytes. std::vector<std::byte> CaptureContext() { std::string_view json = R"({"line": 3, "batch": "A-1042"})"; const auto* bytes = reinterpret_cast<const std::byte*>(json.data()); return {bytes, bytes + json.size()}; } int main() { // Simulated imager with a gradient from 20-80 C. optris::sdk::SimulatedConfig cfg; cfg.width = 160; cfg.height = 120; cfg.framerate = 30; cfg.pattern = optris::sdk::TestPattern::kGradient; cfg.temp_min_c = 20.0f; cfg.temp_max_c = 80.0f; auto imager = optris::sdk::Imager::Create(cfg); // A measuring area over the hot side, from pixel geometry. auto region = optris::sdk::RegionFromGeometry( optris::sdk::Rectangle{120, 30, 30, 60}, imager->GetWidth(), imager->GetHeight()); region.name = "Hot Zone"; const auto region_id = imager->Regions().Add(std::move(region)); // Enable pre-roll so the recording includes the 2 seconds before // the alarm fired. imager->Recorder().EnablePreRoll(std::chrono::seconds(2)); imager->Recorder().SetOutputDirectory("/tmp"); // A rule that records for as long as it is ringing. The recording // is part of the rule, not a side effect an application has to // wire up. optris::sdk::Rule rule; rule.name = "alarm_event"; // The slot is filled in from region_id by the two-argument Add(). rule.input = optris::sdk::SignalId::Region( 0, optris::sdk::SignalField::kMax); rule.condition.compare = optris::sdk::Compare::kAbove; rule.condition.alarm.high = 50.0f; rule.condition.alarm.hysteresis = 2.0f; optris::sdk::RecordingAction recording; recording.mode = optris::sdk::RecordingAction::Mode::kWhileActive; rule.actions.push_back( {optris::sdk::ActionTrigger::kOnAnyChange, recording}); imager->Alarms().Add(region_id, std::move(rule)); // Your own files travel inside whatever the alarm produces. The SDK // pulls this as the file's header goes down -- which is why it works // even though nothing here calls Recorder().Start(). imager->Recorder().AddAttachmentProvider( [](const optris::sdk::rec::AttachmentRequest& request) { std::vector<optris::sdk::rec::Attachment> out; optris::sdk::rec::Attachment context; context.name = "process.json"; context.mime = "application/json"; context.data = CaptureContext(); // std::vector<std::byte> out.push_back(std::move(context)); return out; }); imager->Start(); // The gradient ensures max > 50 C, so the alarm fires // immediately. Let it record for a few seconds. std::this_thread::sleep_for(std::chrono::seconds(5)); // The rule stops the recording itself when the alarm clears; this // only covers the case where it is still ringing at shutdown. imager->Recorder().Stop(); imager->Stop(); std::println("Done, see /tmp for the recording."); }
#include <stdio.h> #include "optris/sdk_c.h" int main(void) { optris_sdk_simulated_config cfg; optris_sdk_imager *camera = NULL; optris_sdk_region *zone = NULL; optris_sdk_rule *rule = NULL; optris_sdk_signal_id input; optris_sdk_condition condition; uint64_t region_id = 0; uint64_t rule_id = 0; /* Simulated imager with a gradient from 20-80 C. */ optris_sdk_simulated_config_init(&cfg, sizeof(cfg)); cfg.width = 160; cfg.height = 120; cfg.framerate = 30; cfg.pattern = OPTRIS_SDK_PATTERN_GRADIENT; cfg.temp_min_c = 20.0F; cfg.temp_max_c = 80.0F; optris_sdk_imager_create_simulated(&cfg, &camera); /* A measuring area over the hot side. */ { optris_sdk_vec2 centre = {0.84F, 0.375F}; optris_sdk_vec2 size = {0.19F, 0.38F}; optris_sdk_region_create_rect(centre, size, 0.0F, &zone); } optris_sdk_region_set_name(zone, "Hot Zone"); optris_sdk_imager_add_region(camera, zone, ®ion_id); optris_sdk_region_free(zone); /* Pre-roll, so the recording includes the 2 seconds before the * alarm fired, and where the rule's files go. */ optris_sdk_imager_enable_pre_roll_ms(camera, 2000); optris_sdk_imager_set_output_directory(camera, "/tmp"); /* A rule that records for as long as it is ringing. */ optris_sdk_rule_create(&rule); optris_sdk_rule_set_name(rule, "alarm_event"); optris_sdk_signal_id_init(&input, sizeof(input)); input.domain = OPTRIS_SDK_SIGNAL_DOMAIN_REGION; input.field = OPTRIS_SDK_FIELD_MAX; optris_sdk_rule_set_input(rule, &input); optris_sdk_condition_init(&condition, sizeof(condition)); condition.compare = OPTRIS_SDK_COMPARE_ABOVE; condition.alarm.high = 50.0F; condition.alarm.hysteresis = 2.0F; optris_sdk_rule_set_condition(rule, &condition); optris_sdk_rule_add_recording_action(rule, OPTRIS_SDK_ACTION_ON_ANY_CHANGE, OPTRIS_SDK_RECORDING_WHILE_ACTIVE, 0, NULL, NULL); optris_sdk_imager_add_rule(camera, region_id, rule, &rule_id); optris_sdk_rule_free(rule); optris_sdk_imager_start(camera); /* The gradient ensures max > 50 C, so the alarm fires immediately. * Let it record for a few seconds, pulling frames as a clock. */ { int i; optris_sdk_frame *frame = NULL; for (i = 0; i < 150; ++i) { if (optris_sdk_imager_acquire_frame(camera, 2000, &frame) == OPTRIS_SDK_OK) { optris_sdk_frame_free(frame); frame = NULL; } } } /* The rule stops the recording itself when the alarm clears; this * only covers the case where it is still ringing at shutdown. */ optris_sdk_imager_stop_recording(camera); optris_sdk_imager_stop(camera); optris_sdk_imager_destroy(camera); printf("Done, see /tmp for the recording.\n"); return 0; }
using Optris.Sdk; // Simulated camera with a gradient from 20-80 C. await using ThermalCamera simulated = ThermalCamera.OpenSimulated( new SimulatedCameraOptions { Width = 160, Height = 120, FrameRate = 30, Pattern = TestPattern.Gradient, MinTemperature = 20.0f, MaxTemperature = 80.0f, }); // A measuring area over the hot side. Region zone = Region.Rect(new Vector2(0.84f, 0.375f), new Vector2(0.19f, 0.38f)); zone.Name = "Hot Zone"; ulong regionId = simulated.AddRegion(zone); // Pre-roll, so the recording includes the 2 seconds before the alarm // fired, and where the rule's files go. simulated.EnablePreRoll(TimeSpan.FromSeconds(2)); simulated.OutputDirectory = "/tmp"; // A rule that records for as long as it is ringing. var rule = new AlarmRule { Name = "alarm_event", Input = SignalId.Region(SignalField.Max), Condition = AlarmCondition.Above(50.0f, hysteresis: 2.0f), }; rule.Actions.Add(new RecordingAction()); simulated.AddRule(regionId, rule); simulated.Start(); // The gradient ensures max > 50 C, so the alarm fires immediately. await Task.Delay(TimeSpan.FromSeconds(5)); // The rule stops the recording itself when the alarm clears; this // only covers the case where it is still ringing at shutdown. simulated.StopRecording(); simulated.Stop();
import time import optris_sdk # Simulated camera with a gradient from 20-80 C. config = optris_sdk.SimulatedCamera(width=160, height=120, framerate=30, pattern=optris_sdk.PATTERN_GRADIENT, temp_min_c=20.0, temp_max_c=80.0) with optris_sdk.Camera.simulated(config) as simulated: # A measuring area over the hot side. zone = optris_sdk.Region.rect((0.84, 0.375), (0.19, 0.38)) zone.set_name('Hot Zone') region_id = simulated.regions.add(zone) # Pre-roll, so the recording includes the 2 seconds before the # alarm fired, and where the rule's files go. simulated.enable_pre_roll(2.0) simulated.set_output_directory('.') # A rule that records for as long as it is ringing. rule = optris_sdk.Rule( name='alarm_event', input=optris_sdk.SignalId.region(optris_sdk.FIELD_MAX), condition=optris_sdk.Condition( compare=optris_sdk.COMPARE_ABOVE, alarm=optris_sdk.Limits(high=50.0, hysteresis=2.0))) rule.add_recording_action( trigger=optris_sdk.ON_ANY_CHANGE, mode=optris_sdk.RECORDING_WHILE_ACTIVE) simulated.alarms.add(rule, region_id=region_id) simulated.start() # The gradient ensures max > 50 C, so the alarm fires immediately. time.sleep(3) # The rule stops the recording itself when the alarm clears; this # only covers the case where it is still ringing at shutdown. simulated.stop_recording() simulated.stop()
use optris_sdk::*; fn main() -> optris_sdk::Result<()> { // Simulated camera with a gradient from 20-80 C. let cfg = SimulatedConfig::new() .resolution(160, 120) .framerate(30) .pattern(TestPattern::Gradient) .temperature_range(20.0, 80.0); let mut simulated = Camera::simulated(&cfg)?; // A measuring area over the hot side. let mut zone = Region::rect((0.84, 0.375), (0.19, 0.38), 0.0)?; zone.set_name("Hot Zone")?; let region_id = simulated.add_region(&zone)?; // Pre-roll, so the recording includes the 2 seconds before the // alarm fired, and where the rule's files go. simulated.enable_pre_roll(std::time::Duration::from_secs(2))?; simulated.set_output_directory("/tmp")?; // A rule that records for as long as it is ringing. let mut rule = Rule::new()?; rule.set_name("alarm_event")?; rule.set_input(SignalId::region(SignalField::Max))?; rule.set_condition(Condition::above(50.0, 2.0))?; rule.add_recording_action(ActionTrigger::OnAnyChange, RecordingActionMode::WhileActive, 0, None, None)?; simulated.add_rule(region_id, &rule)?; simulated.start()?; // The gradient ensures max > 50 C, so the alarm fires immediately. std::thread::sleep(std::time::Duration::from_secs(5)); // The rule stops the recording itself when the alarm clears; this // only covers the case where it is still ringing at shutdown. simulated.stop_recording()?; simulated.stop()?; Ok(()) }