The Optris SDK from Python
optris_sdk is the SDK's Python package: a hand-written binding over the SDK's flat C ABI, in pure Python through ctypes. There is no compiled extension, no SWIG, and no SDK headers involved. If CPython can load a shared library, this works, and a wheel is architecture-independent.
In Fahrenheit: with the SDK switched to Fahrenheit (optris_sdk.set_temperature_unit(), 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.
It is not optris.otcsdk, which is the SWIG wrap of the version 11 IRImager API and is still shipped. The two share no namespace and install side by side.
Installing
Install it from PyPI:
pip install optris-sdk
The wheel carries the native SDK library inside it, so it needs nothing else installed and works in a virtual environment. On Linux it takes libusb from your distribution, and a USB camera needs the udev rules once; Python with pip says how.
The other way in gives the same optris_sdk package: the platform package. The .deb or the Windows installer puts optris_sdk into the system dist-packages, beside the installed SDK, so on a computer with the SDK installed there is nothing further to install.
The binding is pure Python over ctypes, so neither way has a compile step, SDK headers or SWIG:
python3 -c "import optris_sdk; print(optris_sdk.sdk_version_string())"
Installation is the full picture.
NumPy is optional and is not a dependency. Frame.to_numpy() needs it; Frame.samples() does not, and returns a ctypes array viewing the SDK's own memory. Install NumPy however you normally do: python3-numpy from your distribution, or pip install numpy into your own environment.
The version is checked at import
The package is generated against one C ABI version and refuses a library older than that:
SdkLoadError: /usr/lib/libotcsdk.so implements C ABI version <older>, and this package was generated against version <newer>.
(The real message carries the two numbers.)
A newer library is fine: the ABI keeps older callers working, because every struct carries its own size and the SDK reads only the fields that fit. The reverse is not, so it is refused rather than left half-working.
This is checked at import rather than at the first call, because the mismatch is a property of the pair and not of any one call; discovering it at the first call makes it look like a bug in that call. optris_sdk.abi_version is what the loaded library reports.
A first program
import optris_sdk with optris_sdk.Camera.simulated() as camera: camera.start() spot = optris_sdk.Region.spot(camera.from_pixels(80, 60)) spot.set_name("inlet") region_id = camera.regions.add(spot) for frame in camera.frames(30): # Frames from before the startup calibration has finished # arrive too, and are not measurements. if not frame.thermal_data_reliable: continue stats = camera.regions.stats(region_id) if stats.valid: print(f"{stats.mean_c:.1f} C over {stats.pixel_count} px")
That runs with no hardware at all. For a real camera, name it:
with optris_sdk.Camera.open(serial="21074191") as camera: ...
Camera.open() with no argument enumerates and takes the first camera it finds, which on a machine with more than one is whichever answered first: a different camera from one run to the next, and on a shared machine possibly one somebody else is streaming from. Name the serial, or open a DeviceInfo you got from optris_sdk.enumerate_devices().
Which library gets loaded
In this order, taking the first that loads. Each step tries the Release filename and then the Debug one, because a Debug build of the SDK carries a d postfix.
| Where | Why | |
|---|---|---|
| 1 | OPTRIS_SDK_LIBRARY |
A full path to the file. An explicit answer always wins. |
| 2 | optris_sdk/lib/ beside the package |
Where a bundled wheel puts it. Ahead of the system copy on purpose: a bare dlopen("libotcsdk.so") searches system paths first, so an older installation would shadow the one shipped with your application, and because both load, the symptom is a missing symbol on the first call rather than "library not found". |
| 3 | OPTRIS_SDK_DIR, then OTC_SDK_DIR |
An installed SDK's root. The second is the one the SDK itself reads and the one the Windows installer writes, so on an installed machine it is already set; it is a list, read in order, because installing twice adds a second entry. |
| 4 | The installation this package is part of | Found by walking up from the package, so an archive unpacked anywhere works with nothing set. On Windows that reaches bin\otcsdk-34.dll and on Linux lib/libotcsdk.so. Ahead of the platform's own search for the reason step 2 gives. |
| 5 | The platform's own search | The last resort, and on Windows it cannot find a library that is only on PATH: since Python 3.8 ctypes does not search PATH. |
optris_sdk.library_path says which one was chosen. When nothing loads, the error lists every path tried and why.
Four things to know before you start
Region coordinates are not pixels
Regions are placed in frame-normalized, isotropic coordinates: the origin is the frame's top-left, and both axes are divided by the frame width. So x runs 0..1 and y runs 0..height/width: 0.75 on a 4:3 sensor, not 1.0, which puts the vertical centre at 0.375.
Dividing both axes by the width is what makes a circle a true circle in pixels at any resolution. Normalizing each axis by its own extent would make it an ellipse on anything that is not square.
This is the single easiest thing here to get wrong, and it fails quietly. A spot placed at (80, 60) (pixel coordinates on a 160×120 sensor) lands far off-frame, measures nothing, and reports valid = False rather than raising. If a region never becomes valid, check this first. camera.from_pixels(x, y) and camera.to_pixels(point) convert.
An absent measurement is NaN, not zero
RegionStats.valid is false when a region is off-sensor, disabled, or has not been measured yet, and then every temperature on it is NaN. It is not zero, because zero is a temperature and a scene containing 0 °C is not unusual. Check valid before reading a number; optris_sdk.is_measured(v) is the same test spelled out for a single value.
Errors are exceptions
Nothing returns a status code. Every failure raises SdkError or one of its subclasses: NotFoundError, NotSupportedError, TimeoutError, DeviceError and the rest, one per status the ABI defines. exc.status is the raw code, exc.status_name its spelling, and the message is the SDK's own description of what went wrong.
try: camera.regions.stats(region_id) except optris_sdk.NotFoundError: ... except optris_sdk.SdkError as exc: print(exc.status_name, exc)
Pull frames unless you have a reason not to
camera.acquire() and camera.frames(n) run on your thread and give you a frame you own. camera.on_thermal_frame(handler) is lower latency and comes with four rules: the handler runs on an SDK thread holding the GIL, so nothing else in your process runs while it does; the frame is borrowed and dies when the handler returns; an exception cannot propagate out of it; and closing the camera from inside one deadlocks against itself.
From Python the pull loop is usually the better trade. It costs one buffer copy and removes every one of those four.
The API, area by area
optris_sdk re-exports everything from the package root, so import optris_sdk is all any program needs. The modules below are how the surface is organised, and they follow the same areas as the topic chapters of this manual, so a reader moving between languages finds the same shape.
| Area | Module | What is in it |
|---|---|---|
| Device Enumeration | discovery |
Finding cameras, naming them, and watching them come and go |
| Device Communication | reconnect |
Connection status, and having the SDK re-open a camera by itself |
| Operation Modes | control |
Telling the camera what to do, grouped the way the SDK groups it |
| Measurement Fields · Regions | measurement |
Regions, their statistics, and motion zones |
| Alarms | alarms |
Rules over signals, and the one model behind all of them |
| Color Palettes | palettes, isotherms |
The colours a thermal picture is drawn with; isotherm windows over a grayscale scene |
| The Canvas | canvas |
Placing a camera's picture in view space, and asking what covers what |
| Recording and Playback | recording, playback, continuous, session, video, ravi |
Recording and replaying; what a seek will cost before paying for it; the rolling history and cutting clips out of it; several cameras on one clock; writing a recording out as a video; converting a PIX Connect .ravi into an SDK recording |
| Snapshot File Formats | snapshot |
Writing a still with everything in it, and reading it back |
| Process Interface (PIF) | pif |
Declare what a channel is for, then use it |
| Virtual Imager | camera (Camera.simulated()), faults |
Working with no hardware; breaking a camera on purpose so your error handling can be tested |
| Error Handling | errors |
Status codes in, exceptions out, in one place |
| (none) | camera |
Opening a camera, taking frames from it, and closing it |
| (none) | config |
Settings that outlive the process, and what a load actually did |
| (none) | log |
Taking the SDK's own log lines into your program's log |
| (none) | sdkinfo, version |
Facts about the SDK itself, none of which needs a camera |
Every public name carries a docstring, so help(optris_sdk.Camera) and your editor's completion are the member-by-member reference. optris_sdk/callbacks.py states the four callback rules in full.
What Python cannot reach
The binding reaches 684 of the SDK's 689 C entry points. Those numbers are not an estimate: they are what scripts/check_binding_parity.py counts, and the count is a gate rather than a note in a document.
One of the five it does not reach is superseded rather than missing. optris_sdk_imager_set_recording_callback is the older recording message; Camera.on_recording() uses its successor, optris_sdk_imager_set_recording_event_callback, which carries everything the older one did and more.
The other four cannot be reached, and the reason is structural rather than an omission. optris_sdk_internal_to_celsius, optris_sdk_celsius_to_internal, optris_sdk_celsius_is_encodable and optris_sdk_pixel_is_measured are declared static inline in the C header. An inline function has no exported symbol, so there is nothing for ctypes to call, not in this binding, and not in any other ctypes binding anybody writes.
Python therefore transcribes all four in Python, and you should know that it does. A transcription can drift away from the thing it transcribes, so the package pins each one against the SDK's own answer rather than against a remembered formula: PythonBindingTest.InternalToCelsiusAgreesWithTheSdk compares optris_sdk.internal_to_celsius against optris_sdk_frame_get_temperature over a whole frame, and Frames.test_pixel_is_measured_names_exactly_the_unmeasured_samples holds optris_sdk.pixel_is_measured to the samples the SDK itself converts to nan.
pixel_is_measured(raw) is the test to use on raw samples. A sample the SDK could not measure carries -32768, which is not a cold pixel but the absence of a reading, and Wide-mode distortion correction produces it on every frame. Anything that averages, ranks or compares samples from Frame.samples() or Frame.to_numpy(celsius=False) has to leave those out:
raw = frame.to_numpy(celsius=False) measured = raw[optris_sdk.pixel_is_measured(raw)]
It takes a single sample or a NumPy array. A temperature that was not measured is nan instead, and optris_sdk.is_measured() is the test for that.
One of those transcriptions was measurably wrong once, and the shape of the error is worth knowing. C, .NET and Rust all compute celsius * 10.0f + 1000.0f in float32; Python's arithmetic is float64. The float32 rounding of the multiply pushes the sum across an integer boundary the exact float64 product does not reach, and both int() and a C cast truncate, so celsius_to_internal answered one count low, 0.1 K, on 885 of 2,000,000 temperatures between −40 °C and 1800 °C. Every tenth-of-a-degree literal agreed; it was the arbitrary float that did not, and an arbitrary float is exactly what Frame.celsius() hands back. The package now rounds through float32 explicitly at each of the three steps the other bindings round at.
The reverse direction is not affected and is deliberately left in float64: there the result is a float, and the difference is 9.8 × 10⁻⁵ K, four orders of magnitude below the encoding's tenth-of-a-degree quantum. The same mechanism costs a whole quantum only when the result is an integer.
Everything else the SDK exposes is reachable from Python, and 608 of the 684 are exercised by this binding's own test suite, which scripts/check_binding_exercised.py reports per area.
Recording and playback
The optris_sdk package binds the whole of this chapter: recording, pre-roll, the time-lapse writer and playback. Durations are seconds, as floats, rather than the ABI's milliseconds and microseconds. optris_sdk.recording is the module, and the calls hang off Camera alongside the live ones.
A recording is a with block, because the thing that must happen on the way out is stopping it:
import optris_sdk with optris_sdk.Camera.simulated() as camera: camera.enable_pre_roll(2.0) # keep the last two seconds camera.start() while not camera.pre_roll.full: # let the buffer fill pass with camera.recording('/data/run.mkv') as run: for frame in camera.frames(300): # Frames from before the startup calibration has finished # arrive too, and are not measurements. if frame.thermal_data_reliable: print(f'{frame.min_c:.1f} to {frame.max_c:.1f} C') # After the block: the file is closed and the totals are final. print(run.stats.frames_written, 'written', run.stats.frames_lost, 'lost')
Read run.stats and do not skip it. start_recording() opens the container before it returns, so a directory that does not exist, a permission that forbids writing or a stick that is not mounted raises there (while there is still a caller to raise at), and camera.is_recording stays False. What its success cannot tell you is what happens afterwards: a disk that fills, a drive pulled mid-recording, a write refused part way through. Those surface on the frame path, not at the call. RecordingStats.frames_lost and RecordingStats.last_error are the honest answer, and camera.on_recording(handler) is the push version of the same fact.
Playing a recording back opens it as a camera:
with optris_sdk.Camera.open_recording('/data/run.mkv') as playback: print(playback.is_playback, playback.playback_duration_s) playback.playback_speed = 2.0 playback.is_looping = False playback.start() for frame in playback.frames(100): # A recording keeps the mark on the frames from before the # camera's startup calibration had finished. They are not # measurements. if not frame.thermal_data_reliable: continue share = playback.playback_position_s / playback.playback_duration_s print(f'{share:.0%} {frame.min_c:.1f} to {frame.max_c:.1f} C')
frames(), acquire(), regions and alarms all work on a playback handle unchanged, which is what lets one loop be written against live and recorded data alike. The measuring regions travel inside the recording: reopen the file and they are already there, with the names and ids they had live, so a replayed frame is measured by the region that measured the live one.
Do not add them again. A region added to a playback handle is accepted, given an id and listed by regions.ids(), and is then silently dropped when the first frame arrives and the recording's own region set is restored; measuring through the id that add() returned fails several seconds later with no region with id 2.
What only hardware can do is refused rather than faked. start_recording(), the shutter, the focus motor and the process interface all raise NotSupportedError on a playback handle. Branch on is_playback, which both kinds answer, rather than catching the exception.
save_snapshot() is not on that list. It writes the frame the replay is showing, see Taking one from a replay, or from a still for what such a file carries and which fields it can lack.
The worked example is examples/python/recording/record_and_replay.py. It records with pre-roll, writes a snapshot in each format, then reopens the file and checks every replayed frame against the one it came from, grid for grid, which is the only evidence that distinguishes a recording from a file of the right size.
Examples
Twenty-seven examples across eleven areas, at examples/python/<area>/. The same twenty-seven exist in C++, C, C# and Rust, demonstrating the same things in the same order, so they can be read side by side, see Example Applications for the full table.
python3 discovery/list_devices.py # no hardware needed python3 frames/minimal.py 21074191 # that camera, by serial
Every one of them runs with no arguments and needs no hardware: it opens a simulated camera, which is deterministic and answers the whole API. That is the safe default rather than the convenient one, for the reason given above.
Every one of them is also executed on every build of the SDK. Nothing here is compiled, so running them is the only way any of them can be known to work, and running them every time is the only way they stay working.