OptrisOptrisDocumentation

Documentation/OTC SDK/Overviewv12.0

Start Developing

Pick a language, link the SDK into your build, and get one program streaming. That is the whole of this page, and it is deliberately short: the detail of every area lives on the topic page that owns it, listed under Where to go next.

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.

Which Language to Choose?

Language Use Case Downsides
C++ Lowest latency, maximum performance, full API Needs C++17 or later; on Windows the application must be built like the DLL (see below)
C Any language or toolchain that can call a C function; the stable ABI the other bindings are built on Manual resource management
C# GUI application development (.NET 10.0), through the Optris.Sdk package Minor performance penalties due to bindings
Python 3 Prototyping and data science, through the optris_sdk package Not suitable for high frame rate demands (GIL)
Rust Applications that want compile-checked lifetimes, through the optris-sdk crate

The C#, Python and Rust bindings are hand-written over the flat C ABI in include/optris/sdk_c.h (C ABI version 34). They are not generated and do not mirror the C++ class layout; each follows its own language's conventions. Language Bindings says how much of the SDK each one reaches (measured, not claimed) and where its guide and member-by-member reference are.

The older SWIG-generated bindings over the v11 IRImager API still exist for existing code (the Optris.OtcSdk C# namespace, which ships inside the Optris.Sdk package, and the optris.otcsdk Python module), but new applications should not be written against them.

Your First Program

One program per language, each one complete. The SDK auto-detects the first available USB or Ethernet camera, downloads calibration files if it needs them, and starts streaming.

#include <optrissdk.h>

#include <atomic>
#include <chrono>
#include <iostream>
#include <thread>

int main() {
  // Create an imager for the first available camera.
  auto imager = optris::sdk::Imager::Create();

  // Register a callback for thermal frames.
  std::atomic<int> shown{0};
  imager->SetThermalCallback(
      [&shown](const optris::sdk::ThermalFrame& f) {
        // A camera that was just opened calibrates itself first, for
        // about 20 s. Those frames arrive too, and are not measurements.
        if (!f.GetMetadata().thermal_data_reliable) return;
        if (shown++ < 10) {
          std::cout << f.GetWidth() << "x"
                    << f.GetHeight()
                    << " max=" << f.GetMaxTemperature()
                    << " C\n";
        }
      });

  // Start streaming.
  std::cout << "waiting for the camera's startup calibration\n";
  imager->Start();

  // Ten measurements, or give up after a minute.
  for (int i = 0; i < 600 && shown < 10; ++i) {
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
  }
  imager->Stop();
  return 0;
}

The thermal callback is called on the processing thread for every frame, and the frame it carries holds calibrated temperatures. For about the first 20 seconds after a camera is opened, it also delivers frames from before its startup calibration has finished: on many cameras every pixel of them reads the top of the range, for example 125.0 °C. The SDK marks them thermal_data_reliable false (IsThermalDataReliable in C#), and every program on this page skips them, because they are not measurements. That is why the C++, Python and Rust programs say they are waiting and then stop after ten measurements rather than after a fixed time: a program that stops after 10 seconds, or 100 frames, prints nothing at all on a camera that was just opened. C# has no frame callback: FramesAsync hands back a frame the caller owns, and the loop above is that binding's shape of the same program.

No camera to hand

Every one of those has a simulated sibling that needs no hardware and no calibration: Imager::Create(SimulatedConfig{}) in C++, ThermalCamera.OpenSimulated() in C#, Camera.simulated() in Python. It draws deterministic scenes at a resolution and frame rate you choose, and it is the right thing to develop against, see Virtual Imager (Simulated) for the eleven patterns and what may be changed while it runs.

What the callback may call on the imager

Every getter, and every setter but four. Read the width, the serial, the radiometry, the temperature range, the regions and their measurements; add, move and remove regions and rules; change the palette, the colour range or the orientation. None of it can deadlock.

The four exceptions are the calls that stop or drain the stream, and so would wait for the callback that is asking: Stop(), Reconnect(), SetOperationMode() and Device().SetNetworkConfig(). They are refused rather than hung: each throws, or logs and returns, naming the callback it came from. Destroying the imager from inside its own callback is the one case that cannot report itself; hand that decision to a thread of your own. The cost that remains is time: the stream waits while the lambda runs.

Pulling frames instead of waiting to be called

#include <optrissdk.h>

#include <iostream>

int main() {
  auto imager = optris::sdk::Imager::Create();
  imager->Start();

  for (int i = 0; i < 100; ++i) {
    // Block until the next frame is ready.
    auto frame = imager->AcquireFrame();
    // Frames from before the startup calibration has finished arrive
    // too, and are not measurements.
    if (!frame.GetMetadata().thermal_data_reliable) continue;
    std::cout << "Frame " << i
              << " max=" << frame.GetMaxTemperature()
              << " C\n";
  }

  imager->Stop();
  return 0;
}

AcquireFrame(timeout) takes a std::chrono::milliseconds bound, and TryAcquireFrame() returns std::nullopt at once when no frame is waiting. Callbacks and pulls can both be live on one imager.

A picture to put on screen

Set a palette, then register a BGRA callback; the thermal callback can stay registered beside it.

#include <optrissdk.h>

#include <iostream>

int main() {
  auto imager = optris::sdk::Imager::Create();
  imager->SetPalette(optris::sdk::Palette::kIronBow);

  // A fixed scale in Celsius. Without this the range
  // auto-scales to each frame, and
  // SetColorRange(std::nullopt, std::nullopt) returns
  // to auto-scaling.
  imager->SetColorRange(20.0f, 80.0f);

  imager->SetBgraCallback(
      [](const optris::sdk::BgraFrame& f) {
        // f.GetData() is BGRA8, f.GetWidth() x
        // f.GetHeight() pixels.
        std::cout << f.GetWidth() << "x"
                  << f.GetHeight() << "\n";
      });

  imager->Start();
  imager->Stop();
  return 0;
}

There are seventeen built-in palettes and a custom-palette API; Colour Palettes is the page for both, and for what the colour scale does to a measurement (nothing).

When it goes wrong

Every SDK failure is an exception under SdkException, and errors raised on a processing thread after Start() reach you through SetErrorCallback() rather than by being thrown. C reports the same failures as status codes. .NET takes a handler the same way, through ThermalCamera.OnError; a .NET caller who installs none sees only the frame stream drying up, and the next AcquireFrameAsync with a timeout reporting a FrameTimeoutException.

#include <optrissdk.h>

#include <iostream>
#include <string>

int main() {
  try {
    auto imager = optris::sdk::Imager::Create();
    imager->SetErrorCallback(
        [](const std::string& msg) {
          std::cerr << "SDK error: " << msg << "\n";
        });
    imager->Start();
    imager->Stop();
  } catch (const optris::sdk::DeviceException& e) {
    std::cerr << "Device error: " << e.what()
              << " (S/N " << e.serial() << ")\n";
    return 1;
  } catch (const optris::sdk::SdkException& e) {
    std::cerr << "SDK error: " << e.what() << "\n";
    return 1;
  }
  return 0;
}

Error Handling has the whole hierarchy, which of them are worth retrying, and what each one means on the other four surfaces.

Linking It Into Your Build

C++ requirements

Your application needs C++17 or later; the SDK needs C++23 to build itself, and that is not your concern. The headers under include/optris/sdk/ compile at -std=c++17, and the installed CMake target declares cxx_std_17 on its interface: a floor, not a cap, so a project already on C++20 or C++23 is unaffected and needs no change. Building the SDK from source still requires C++23 and still refuses a lower CMAKE_CXX_STANDARD; nothing about that reaches a caller.

The table below is the set Optris builds and tests with. Older compilers that implement C++17 are not tested; if you are below the table, trust your own build.

Platform Compiler Minimum Version
Linux GCC 13
Linux Clang 17
Windows MSVC 19.36 (Visual Studio 2022 17.6+)

Windows: build your application the same way the DLL was built

A hard requirement, not a recommendation, and nothing reports it at build time. Your application and otcsdk-34.dll must use the same MSVC toolset (matching major version), the same C runtime (/MD with /MD, /MT with /MT, never mixed), and the same configuration: Release DLL with Release application, Debug DLL with Debug application.

The reason is that 22 public members hold standard-library types, and they are not obscure corners: Region::name and Roi::name are std::string; Region::children, Region::rules, Roi::children and Roi::vertices are std::vector; Region::motion and Roi::motion are std::optional; the pixel buffer inside ThermalFrame, RgbFrame and BgraFrame is a std::vector; so are Canvas::placements and the CanvasMap index; and SdkException carries its message as a std::string, DeviceException its serial number, both deriving from std::exception, which is itself not exported. The layout of those members is decided by the compiler and runtime that built each side, and the accessors are inline in the headers, so your compiler generates code against your idea of the layout while the DLL was built against its own. private does not protect you: the inline accessor still runs in your binary.

The exceptions deserve their own warning, because an exception crosses the boundary at the worst possible moment. If the SDK throws SdkException and your application catches it, the std::string inside was built by the DLL's runtime and is being read by yours, so under a mismatch, reading what() in your catch block is itself the crash, while you are already handling an error.

A mismatch links and starts; the damage shows up later as wrong pixel data, a string that reads as garbage, or a crash inside an unrelated call. Mixing Debug and Release is the most common way to hit it, because the Microsoft runtime deliberately changes container layout between them.

Two ways out if you cannot control how your application is built, for example when loading the SDK from a language or runtime that is not MSVC C++. Use the C API in include/optris/sdk_c.h, which passes only plain C types across the boundary and is therefore unaffected; or build the SDK from source with your own toolchain, as Installation describes.

CMake (recommended)

cmake_minimum_required(VERSION 3.14)
project(my_thermal_app LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(otcsdk REQUIRED)

add_executable(my_thermal_app main.cc)
target_link_libraries(my_thermal_app
  PRIVATE
    otcsdk::otcsdk
)

Then:

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel

That links the shared library. For static linking use otcsdk::otcsdk_static (inside the SDK's own build tree the same library is also reachable as otcsdk::static).

On Linux find_package finds the SDK through the standard CMake search paths; for a non-standard prefix pass -DCMAKE_PREFIX_PATH=/opt/otcsdk. On Windows the installer registers the SDK with CMake's package registry and sets OTC_SDK_DIR, so find_package works automatically. Note that OTC_SDK_DIR holds one entry per SDK installation and can also hold an entry of other Optris software, such as Optris Relay; to build against a particular installation, pass its prefix explicitly via -DCMAKE_PREFIX_PATH.

Visual Studio project (Windows)

If you prefer Visual Studio project files over CMake, set:

  • General > C++ Language Standard = ISO C++17 Standard or later
  • VC++ Directories > Include Directories += $(OTC_SDK_DIR)\include
  • VC++ Directories > Library Directories += $(OTC_SDK_DIR)\lib
  • Linker > Input > Additional Dependencies += otcsdk.lib (Release) or otcsdkd.lib (Debug)

$(OTC_SDK_DIR) expands the environment variable as written. With a single SDK installation and no other Optris software that is its directory; otherwise the variable holds several entries, one per SDK installation and one for each other Optris product that added its own, so write the directory of the installation you build against instead of the macro.

The Visual Studio projects of the simpleView and playground applications in examples\apps already do this, and pick the right entry of OTC_SDK_DIR by themselves; see Example Applications.

For static linking, use otcsdk_static.lib / otcsdk_staticd.lib and add OTC_SDK_STATIC to the preprocessor definitions.

At run time a dynamically linked program needs the DLL that belongs to the import library it linked: otcsdk-34.dll for otcsdk.lib (Release) and otcsdkd-34.dll for otcsdkd.lib (Debug), both in $(OTC_SDK_DIR)\bin. Put that directory on PATH, or copy the DLL beside your program together with the five FFmpeg DLLs from the same directory (avcodec-*.dll, avformat-*.dll, avutil-*.dll, swresample-*.dll and swscale-*.dll). The number in the name is the SDK's API version. A program built against another SDK version asks Windows for a different file name, so instead of running against a library it was not built for it does not start, and Windows names the file it is missing. Rebuild such a program against this SDK.

Include paths

Path Contents
include/optris/sdk/ The v12 C++ API: imager.h, player.h, still_source.h, device_enumerator.h, device_info.h, exception.h, imager_config.h, simulated_config.h, region.h, alarm.h, motion.h, canvas.h, palette.h, recorder.h, buffers.h, pipeline_info.h and the rest, plus the frame/, view/, rec/ and pif/ subdirectories
include/optris/sdk_c.h The flat C API
include/optrissdk.h The combined header: one include for the complete C++ API, rec:: and view:: included
include/optris/sdk.h The umbrella header: one include for the facade API
include/sdk.h The generated amalgamated header: the facade API in one self-contained file, Release installs only
include/legacy/otcsdk/ Legacy v10/v11 API: IRImager.h, IRImagerClient.h, facade headers

Include the specific headers you need:

#include <optris/sdk/imager.h>
#include <optris/sdk/device_enumerator.h>
#include <optris/sdk/exception.h>

One include, and there are three of them

optrissdk.h is the combined header: one include for the complete public C++ API, the facades plus the rec:: recording layer and the view:: visualization layer. When you do not want to think about headers, this is the one.

#include <optrissdk.h>

int main() {
  auto imager = optris::sdk::Imager::Create();
  // ... everything is available, rec:: and view:: included
}

optris/sdk.h is the umbrella header: hand-written, includes the facade headers under optris/sdk/, part of the source tree, installs with the rest, always there.

#include <optris/sdk.h>

sdk.h, with no directory in front of it, is the amalgamated header: one self-contained file with the same headers inlined in dependency order, generated at build time. It is what the shipped C++ examples include, and what a build with no SDK include tree beside it wants:

#include "sdk.h"

It ships in Release packages at the include root, as include/sdk.h.

The two are held to the same set on every build, so #include <optris/sdk.h> and #include "sdk.h" cannot quietly become two different APIs.

Neither the umbrella nor the amalgamated header carries the whole of optris/sdk/rec/ and optris/sdk/view/. The types the public facades hand you (rec::Attachment, rec::FileMetadata, rec::Snapshot, rec::TemperatureGrid and the recording types beneath them) are in both. The layer itself (rec/recorder.h, rec/player.h, rec/session.h, rec/video_exporter.h, view/frame_processor.h, view/blob_detector.h and the rest) is not, and is reached by including it directly or by taking optrissdk.h, which holds everything. Those headers are public, installed and supported; the page Headers outside the single-include header is the list, and optrissdk.h is held to the complete installed set on every build.

A program that includes sdk.h, as every shipped C++ example does, adds such a header on the next line, for example to set the quality of a Motion JPEG export:

#include "sdk.h"
#include "optris/sdk/rec/video_exporter.h"

int main() {
  optris::sdk::rec::VideoExportConfig config;
  config.codec = optris::sdk::rec::VideoCodec::kMjpeg;
  config.mjpeg_quality = 2;
}

Before 12.0.29 those two includes together did not compile (the compiler reported every type the two share as defined twice). With an older SDK, include optris/sdk.h or optrissdk.h in that source file instead of sdk.h.

C

The C API is part of the SDK library itself and declared in one header, optris/sdk_c.h. It passes only plain C types across the library boundary, so the Windows matching rule above does not apply to it. Link the same otcsdk::otcsdk target, or otcsdk.lib / libotcsdk.so directly.

optris_sdk_c_abi_version() returns the version of the C ABI the loaded library implements; OPTRIS_SDK_C_ABI_VERSION is the version the header was written for. The C examples in examples/c/ are compiled as C99 with warnings as errors.

C#

The .NET binding is the Optris.Sdk package on nuget.org, a hand-written wrapper over the C API. Add it to your project with:

dotnet add package Optris.Sdk

It needs .NET SDK 10.0 (every .NET project in the SDK targets net10.0): sudo apt install dotnet-sdk-10.0 on Linux, or the .NET desktop development workload in the Visual Studio installer on Windows. The package carries the native library (otcsdk-34.dll / libotcsdk.so) for 64-bit Windows and Linux and loads it from the application's output directory, so the SDK does not need to be installed; see Adding it to a project.

The legacy SWIG binding (namespace Optris.OtcSdk, over the v11 IRImager API) ships in the same Optris.Sdk package, as the assembly Optris.OtcSdk.dll, so existing code needs no second package; its generated classes are also used by the examples under examples/csharp/legacy/.

Build your project Debug or Release as you like; it is independent of the SDK. The warning under C++ requirements, a Release DLL with a Release application, does not apply to you. It is about C++ types crossing the DLL boundary with standard-library members inside them; the .NET binding calls the plain C API, which passes only C types, so there is no layout to agree about and nothing changes between configurations.

So a .NET project built in Debug loads the shipped Release native library correctly, and that is the only combination we publish: the Optris.Sdk package always contains release-built natives for both of its interfaces, in every version. There is no debug variant of it, and there will not be: a debug Windows native imports the debug Visual C++ runtime (MSVCP140D.dll, VCRUNTIME140D.dll), which is not part of the redistributables and is present only on machines with Visual Studio's C++ workload installed. A package built that way fails to load for everyone else, which is what happened in 11.4.9 and 11.4.10.

To step into the SDK's own code from your debugger you do not need a debug build: that is what the symbol files in the package are for, under symbols/win-x64/. The same applies to the Python and Rust bindings, which also go through the C API.

Python 3

The Python binding is the optris_sdk package on PyPI, pure Python over the C API through ctypes. Install it with:

pip install optris-sdk

The wheel carries the native library, so nothing else needs installing; the .deb and the Windows installer also put the package into the system dist-packages beside an installed SDK. There is no compiled extension, so it needs no compiler, SWIG or SDK headers, only Python >= 3.9 and a native library, which it locates through OPTRIS_SDK_LIBRARY, a bundled copy, OPTRIS_SDK_DIR or OTC_SDK_DIR, the installation the package itself sits in, or the platform's own library search, in that order. NumPy is optional and needed only for Frame.to_numpy().

Camera.open(serial="...") opens a particular camera. On import the package refuses a native library older than the C ABI version it was generated against. See The Optris SDK from Python.

The legacy SWIG module optris.otcsdk (over the v11 IRImager API) is still built when BUILD_PYTHON_BINDINGS=ON. It is compiled against the system default Python 3 and NumPy, so using different versions may cause import errors.

Rust

Two crates on crates.io: optris-sdk-sys holds the raw FFI declarations, and optris-sdk is the safe wrapper your code uses. Put both into [dependencies], so their versions stay matched and the raw layer is there if you need it:

[dependencies]
optris-sdk = "12.0"
optris-sdk-sys = "12.0"

The crates do not carry the native library: install the platform package (the .deb or the Windows installer) as well. With the .deb there is nothing to set. On Windows, or for a library outside the system directories, set OPTRIS_SDK_LIB_DIR to the directory holding it, and make sure the loader finds the same copy at run time. See Adding it to a project.

What Happens When You Open a Camera

Imager::Create() and Imager::Create(DeviceInfo) do six things, in this order:

  1. Locate the device: queries USB and (optionally) the network for the target camera. With no serial named, the first available camera is used.
  2. Load configuration: locates or generates an XML configuration file holding connection details, video format, temperature range and radiation parameters.
  3. Establish connection: opens a control channel for commands and a streaming channel for frame data.
  4. Load calibration: from the device, the local filesystem, or Optris servers (calibration.optris.com).
  5. Determine operation mode: matches the requested optics, temperature range and video format against the available calibrations.
  6. Startup calibration: runs an initial calibration. Frames arrive during this phase and their temperatures are not reliable; the flag state is Initializing until it completes.

Note: A camera whose calibration files cannot be found still opens and streams, and its temperatures are wrong. Check Imager::GetCalibrationStatus() after opening: kMissing means the numbers must not be used, and GetCalibrationDiagnosis() names which source let the machine down. Where the open itself fails for want of calibration, Imager::Create() throws CalibrationException.

Where to go next

Nothing above is the full story of anything; each of these is.

To do this Read
See what is attached before opening it, and watch for a camera arriving Device Enumeration
Connect over Ethernet, and survive a camera dropping out Device Communication
Tour the whole C++ API area by area Using the API
Find an exact declaration API Reference
Write it in C#, Python or Rust Language Bindings
Measure regions rather than whole frames Regions
Choose a palette, or build your own Colour Palettes
Develop with no camera attached Virtual Imager (Simulated)
Record, play back and take snapshots Recording
Handle every failure mode Error Handling
Do it from the command line, without writing code Command Line Tools
Run the 27 examples that ship in all five languages Example Applications
Port an application from SDK 11 Migration Guide: v11 to v12