Example Applications
27 examples, in each of five languages: 135 programs. They carry the same names and sit in the same 11 areas in every language, so any two can be read side by side, and examples/manifest.txt is the statement of what the set is. It is read by five cmake files and enforced in both directions: a source file with no row in it fails the build, and a row with no source file fails too.
This page is the inventory, where each language's copy lives, and the command that runs one.
The 27 examples
Every row exists in all five languages. The descriptions come from examples/manifest.txt, the one statement of what the example set is, so this table cannot disagree with what ships.
The 27 rows are spread over 11 areas.
| Area | Example | What it shows |
|---|---|---|
| discovery | list_devices |
What is attached: model, serial, resolution, connection, and hotplug |
multi_camera |
Several cameras at once, each Imager independent | |
open_network_camera |
Opening over Ethernet, and why naming the serial beats naming an address | |
name_a_camera |
A host-side name, keyed by serial, that outlives the process | |
set_address_by_broadcast |
A camera's MAC address and discovery version, and setting its address by broadcast without knowing the old one | |
| frames | minimal |
The shortest complete program: open, callback, centre temperature |
pull_frames |
Asking for frames at your own pace, blocking and polling | |
frame_types |
Thermal, raw, energy and BGRA side by side, and how they relate | |
| radiometry | radiation_parameters |
Emissivity, transmissivity, ambient, and the auto-NUC settings around them |
| measurement | regions |
Every region shape, added, edited and removed while streaming |
region_stats |
Min, max, mean, coverage per frame, and why no measurement is NaN rather than zero | |
region_percentiles |
p01/p05/p95/p99, why they are opt-in, and when to prefer them to min and max | |
line_profile |
A line region and the per-pixel samples its statistics were reduced from | |
spot_tracking |
Hot and cold spots that track the extreme within a region | |
region_emissivity |
Per-region emissivity, and that it reaches no number without a real backend | |
motion_zones |
Motion zones, their events, and why a zeroed zone is inert rather than open | |
| canvas | rotate_and_zoom |
Turning and zooming the picture, and a canvas reading traced back to its sensor pixel |
pan_live |
Dragging the picture while it streams, under a fixed spot and a spot that follows it | |
composite |
Placing the colour picture into a larger canvas yourself with a CanvasMap | |
| alarms | threshold_alarm |
Warning bands, hysteresis, delay frames, latching and actions |
| device_control | operation_modes |
Optics, temperature ranges, resolution and frame rate |
focus |
Motorised focus: the capability query, the range, and the travel | |
network_config |
Network settings: read them, and ask the camera to take new ones, refusal included | |
| process_interface | pif_info |
What is attached, its channels, and reading and driving them |
| configuration | save_and_load |
Reading a config, writing it, and applying one back |
| recording | record_and_replay |
Recording with pre-roll, snapshots in every format, then replaying the file |
| diagnostics | error_handling |
Every failure mode, provoked deliberately, one at a time |
Where they are, and how to run one
| Language | Source | Run it |
|---|---|---|
| C++ | examples/cpp/<area>/<example>.cc |
build/examples/<example> |
| C | examples/c/<area>/<example>.c |
build/examples/c_<area>_<example> |
| C# | examples/csharp/<area>/<example>/Program.cs |
dotnet run --project examples/csharp/<area>/<example> |
| Python | examples/python/<area>/<example>.py |
python3 examples/python/<area>/<example>.py |
| Rust | examples/rust/<area>/<example>.rs, and examples/<area>/<example>.rs in the optris-sdk crate |
cargo run --example <area>_<example>, from the optris-sdk crate's folder |
So the frames/minimal example is five files and five commands:
# C++ and C -- one build produces both cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON cmake --build build --parallel ./build/examples/minimal ./build/examples/c_frames_minimal # C# -- needs .NET SDK 10.0 dotnet run --project examples/csharp/frames/minimal # Python -- needs Python 3.9+ and the binding: pip install optris-sdk python3 examples/python/frames/minimal.py # Rust -- from the optris-sdk crate's folder cargo run --example frames_minimal
The C++ and C builds
Both are built by the SDK's own build when BUILD_EXAMPLES=ON, which is the default; the C ones additionally need BUILD_C_API=ON, also the default. Every binary lands in build/examples/, flat: a C++ example is named after its source file, and a C example carries its area in the target name because a bare regions would collide.
The C++ examples are built as C++23 by their own choice (examples/cpp/CMakeLists.txt sets cxx_std_23 on each of them and several use <print>), so building the shipped examples asks more of a compiler than using the SDK does. The SDK's own headers need only C++17.
examples/cpp/ and examples/c/ are also standalone find_package(otcsdk) projects, which is how a reader builds them against an installed package rather than inside this tree:
cp -r /usr/share/otcsdk/examples/cpp ~/otcsdk-examples cd ~/otcsdk-examples && cmake -S . -B build && cmake --build build
The C examples are compiled as C99 under -Wall -Wextra -Wpedantic -Werror, which is the standing proof that optris/sdk_c.h really is a C header. One that only ever meets a C++ compiler turns out not to be, and the customer is the one who finds out.
The C#, Python and Rust builds
Each uses its own toolchain, and each is also run on every build of the SDK rather than only compiled; compiling proves only that an example still matches the API.
| Language | Built by | Also run as |
|---|---|---|
| C# | dotnet build, against the Optris.Sdk package |
ctest CSharpExamples.<name> |
| Python | nothing: pure Python over the C ABI | ctest PythonExamples.<name> |
| Rust | cargo build --examples from bindings/rust |
ctest under RustBindings.Examples |
Each Rust example needs an explicit [[example]] entry in bindings/rust/optris-sdk/Cargo.toml naming its path, because the sources sit outside the crate that builds them and cargo does not auto-discover them. check_rust_examples_declared.cmake is what stops one being added to the manifest and never built.
What to pass on the command line
Most take [serial | --simulated]: a serial opens that camera, --simulated opens the SDK's built-in synthetic camera, and no argument opens the first camera found. Some are different, deliberately:
error_handlinguses the simulated camera when given no argument, because it provokes failures on purpose.list_devicestakes[--network] [--simulated] [--watch]and opens nothing.--watchstarts the hotplug monitor and prints arrivals and departures until Ctrl+C.--fahrenheitis taken by every example that shows or sets a temperature, in all five languages, anywhere on the command line. The example switches the whole SDK to degrees Fahrenheit with one call before it opens the camera, writes the limits and scenes it sets in Fahrenheit, and every reading it prints is then in Fahrenheit, with nothing converted in the example itself. The letter after each number is the unit the SDK reports. See Temperatures in Fahrenheit.name_a_cameraopens no camera at all. The name is stored on the host, keyed by the serial, so naming a camera never takes it away from whatever is streaming from it.- The three
canvasexamples take only--simulatedand never open a real camera. Each checks that a reading on the canvas came from the sensor pixel its placement names, which needs a scene whose temperature is known at every pixel: the simulated camera's gradient, half a degree warmer in every sensor column. Each exits 1 when a reading is wrong, and ctest runs all fifteen.
Every C, C#, Python and Rust example runs against a simulated camera with no argument, which is what lets ctest run all of them on a machine with nothing plugged in. The C, C++, Python and Rust examples also answer --help (or -h): each prints what it accepts and exits 0 without opening a camera, and refuses an option it does not know with exit status 2 instead of taking it for a serial number.
Where an example writes
An example that writes a file writes it into the system temporary directory, never into the directory it was started from and never beside its own executable. Each one prints the path it used. Two rules follow from this, and both are properties of the programs rather than advice:
- An example never writes into the installation. The prebuilt copies under
examples/binrun from wherever the SDK was installed, and on Windows that is a location a standard user cannot write to. An example that wrote there would either fail or leave files inside the installation. - An example that cannot write its file exits non-zero. An alarm's snapshot is written on the SDK's action thread, so the failure is reported to the handler rather than returned from a call. The examples install that handler, count what it reports, and fail the run. A run that exits 0 produced the files it describes.
The temporary directory is the choice rather than your documents folder on purpose: an example is a program a stranger runs to see what happens, and nothing it does should be able to cost anybody a file. The recording examples go one step further and make a new directory for each run, because a recording refuses to overwrite an existing file, so a fixed name would work once per machine and fail afterwards.
The windowed applications below are the exception, and the reason is the same one: a picture you asked for by pressing a key goes into a folder of its own inside your pictures folder, where you can find it again, rather than into a temporary directory the system clears behind you. They, too, write nothing beside their own executable.
Why the areas are what they are
The areas are not a taxonomy invented for the examples: they are the sub-interfaces optris::sdk::Imager is already decomposed into (Regions(), Canvas(), Alarms(), Radiometry(), Recorder(), GetPif() and the device controls) plus four for surface that sits outside one: discovery, frames, configuration and diagnostics.
So an area with nothing in it is a visibly un-demonstrated part of the API rather than a gap in somebody's imagination. Measured over the C++ set, the annex excluded: Display() and Buffers() are reached by no example at all, and that is the honest statement of what is not demonstrated. Processing(), Detector(), Optics() and Motion() have no area of their own but are each exercised from inside another one: radiation_parameters drives Processing() and Detector(), focus drives Optics(), motion_zones drives Motion().
Areas land one at a time, complete across every language, rather than as a thin layer everywhere; a half-filled area cannot be told apart from an abandoned one.
The C++-only annex
examples/cpp/patterns/ is outside the area set on purpose, and outside the parity check with it: subclass derives from Imager so callbacks arrive as virtual method overrides, and dependency_injection passes an imager and a region container into independent components. Both are about structuring a larger C++ application rather than about the SDK's surface, and neither has a counterpart in another binding.
The windowed applications
Four larger programs in examples/apps/, which are applications rather than examples; each is many files and demonstrates a whole viewer rather than one call.
| Application | What it is |
|---|---|
simpleView |
The smallest real viewer: SDL2, a palette, a measuring area |
showcase |
The same frames through SDL2 on a fixed scale, for comparing one viewer against another |
playground |
A larger C++ surface to try things in |
csharp_simple_view |
The .NET viewer, on Avalonia, for Windows and Linux from the same source |
Opening a camera on the network
Each of the four opens a camera you name by its serial number wherever it is, on USB or on the network, and waits for it if it is not there yet:
simpleView 26094201 showcase --serial 26094201 playground 26094201 dotnet run --project examples/apps/csharp_simple_view -- --live 26094201
A camera that starts answering on the network after the viewer was started opens a few seconds later, without a restart; while the viewer waits, its window says which camera it is waiting for (the playground says so in its console). A camera that another program is using when it appears is opened as soon as that program lets go of it; the playground tries again every two seconds. The network is searched in the background, so the window keeps responding during the few seconds a search takes.
Without a serial number the viewers search USB only. With no serial they open the first camera they find (simpleView: every camera), and on a network shared with other users the first camera to answer is somebody else's. Add --network to search the network as well:
| Application | First camera, USB only | First camera, USB or network | One camera by serial |
|---|---|---|---|
simpleView |
simpleView (every camera on USB) |
simpleView --network (every camera) |
simpleView 26094201 |
showcase |
showcase |
showcase --network |
showcase --serial 26094201 |
playground |
playground |
playground --network |
playground 26094201 |
csharp_simple_view |
--live |
--network |
--live 26094201 |
The showcase also has a camera dialog. It opens by itself when no camera was found, or when more than one is on USB and none was named, and over the picture with N or Camera > Connect camera in the menu (Tab). It lists the cameras on USB with their model, serial number and connection; Search network (N) adds the cameras that answer on the network, searching in the background while the window keeps working. Nothing is opened until you choose a camera and press Enter or click Connect, and Disconnect (D) closes the open camera and goes back to the list. The menu is grouped into sections that fold (Right opens one, Left closes it) and scrolls with the selected entry, so all of it can be reached in a 640x480 window.
--help in each of them lists these. A camera on another subnet, behind a router, is not found by any of them, because the search is a broadcast; see Ethernet Cameras for opening one by its address in your own program.
Focusing a motorized lens
On a camera with a motorized lens, simpleView focuses the selected camera farther with PageUp and nearer with PageDown, by 5 % of the lens's travel (1 % with Shift), and its status line shows the focus as a percentage. The showcase has a Focus entry in its menu (Tab) that moves the lens by 1 % per press. Both go through Optics().SetFocus(), a share of the travel from 0.0 at the near end to 1.0 at the far end, and never show the motor's own position. An Xi 640 ETH on the network cannot report its current focus to the SDK yet, so both show it as unknown until the first press, which starts from the middle of the travel.
The three C++ ones need SDL2 and are built only when CMake finds it (SDL2_FOUND), so a build without SDL2 simply does not have them; simpleView also picks up SDL2_ttf for its on-screen text when that is present.
On Windows, simpleView and playground also come with Visual Studio projects (simpleView.vcxproj, playground.vcxproj). They find the SDK by themselves: the installation they came with, or, for a copy you moved elsewhere, the first entry of OTC_SDK_DIR that holds the SDK's headers, so another Optris product's entry in that variable does not get in the way. To name the SDK yourself, build with /p:OtcSdkRoot=<the SDK folder>. SDL2 and SDL2_ttf are not part of the SDK: download their Visual C++ development packages from libsdl-org on GitHub and set SDL2_DIR and SDL2_TTF_DIR to the unpacked folders. The build copies the SDK library and the SDL2 DLLs beside the program it produces.
csharp_simple_view takes Avalonia from nuget.org, so building it needs access to nuget.org once.
Older sets still in the tree
None of these is part of the table above, and new code should not be written against any of them.
examples/c/numbered files:minimal.cand01_enumerate.cthrough08_error_handling.c, the original C tour, kept beside the area set.examples/csharp/legacy/: againstOptris.OtcSdk, the SWIG binding over the v11IRImagerAPI.examples/python3/: against the v11 API through the SWIGoptris.otcsdkmodule. A different API against a different SDK, not an older spelling of these examples.examples/legacy/:legacySimpleViewandv11consumer.
There was also a numbered v12 set, 01_minimal through 18_camera_names, in a directory called apiv2. The numbers said nothing about what an example covered and the name was scaffolding from designing the API; the content moved into the areas above. 06_measurement_fields and 16_rois were retired outright, superseded by the seven examples in measurement.