OptrisOptrisDocumentation

Documentation/OTC SDK/Overviewv12.0

Region Statistics

The statistics that come back, how to describe a region somebody else built, how much of one crossed a limit, the per-pixel profile a line kept, and which frame a reading belongs to. The last of those is the one that surprises people.

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 region chapter is four pages, each answering one question, and the worked examples are a fifth: Region Examples.

Page Question
Regions What is a region, what kinds are there, and what do its coordinates mean?
Region Shapes How do I define, compose and edit the shape?
Apertures and Spots What exactly is a spot looking at, and where does its emissivity apply?
Region Statistics What comes back, and how do I read it per frame?

On this page

Statistics

RegionStats is recomputed every frame:

struct RegionStats {
  float min_c, max_c, mean_c, std_dev_c;
  float median_c;          // only when want_percentiles is set
  Vec2 min_loc, max_loc, centre_loc;
  uint32_t pixel_count;
  float coverage;          // measured / nominal; see below
  bool valid;
};

Always check valid before reading a temperature. It is false for a disabled region, for a region with no measurable pixel behind it at all (off the sensor, or entirely inside the unmeasurable border radial distortion correction leaves in kWide), and for a point region whose sample fell below its Aperture::min_coverage.

What an invalid region reports, exactly. Every temperature is quiet NaN, and min_loc and max_loc collapse to centre_loc. That is deliberate and it is the contract, not an accident of initialization:

  • NaN rather than zero, and rather than an out-of-band cold value, because a region the SDK itself calls invalid must not report a number that could be plotted, compared against an alarm limit or averaged into anything. Every comparison against NaN is false, so the omission shows up as a blank rather than as a plausible reading.
  • The extreme locations go with the temperatures. There is no hottest pixel to point at, so the two locations fall back to the one point that still means something: the region's own centre. A marker drawn from them sits on the region rather than in the top-left corner of the picture.
  • pixel_count and coverage are the exception and stay truthful, because they are how a caller finds out how short the sample was. An under-covered spot reports the pixels it did reach and the fraction they came to, with no temperatures.

coverage is not "1.0 for area regions": it is measured pixels over nominal pixels, and it drops below 1.0 for an aperture clipped by the region boundary or the image edge, for an area region hanging off the sensor (which is what happens the moment a camera is panned or zoomed on a The Canvas), and for pixels the SDK could not measure at all. The statistics are computed over the covered part only, so mean_c is honest about the pixels it had; this field is what separates "20 degrees across this region" from "20 degrees across the 30 per cent of it that had data". It is published as SignalField::kCoverage, so a rule can refuse to alarm below a floor.

Building one yourself, for a test or a fake camera. In C++ RegionStats is a plain aggregate. In the bindings, every property on RegionStats, RegionPercentiles, RegionShape, RegionThresholdShare, RegionBlob, RegionSample and RegionState has an init accessor in .NET and a keyword argument in Python, each defaulting to what an unmeasured region reports: NaN temperatures, valid false, rather than to a plausible 0 °C. The C structs are public and every Rust field is pub.

Percentiles (p01, p05, p95, p99) and the median cost a pass over every pixel in the region, keeping each one, so they are computed only when Region::want_percentiles is set, and land in Region::percentiles. Read them on a live camera with RegionEngine::Percentiles(id).

Honoured by every kind that measures pixels, including the point kinds, where they describe the aperture: nine values for a 3×3, and for ApertureShape::kPixel all five are that one pixel's reading. A sample refused by Aperture::min_coverage reports none of them, the same way it reports no temperatures.

All five are publishable as signals (SignalField::kMedian, kP01, kP05, kP95, kP99), so a rule or a kMeasurementField output can follow them. They are published only while RegionPercentiles::valid, together or not at all; see Alarms.

Describing a region you did not build

After LoadConfig() the camera holds the file's regions with ids the application never saw. Reading one back is how it gets shown again.

for (const uint64_t id : /* optris_sdk_imager_read_region_ids() */ ids) {
  const auto region = camera.Regions().Get(id);
  // region->name, region->kind, region->emissivity, region->enabled
  // and region->geometry are all there in C++.
}

In C++ a Region is a value and carries everything. Through the ABI and the bindings it is reached one accessor at a time, and until v12 several of those accessors did not exist:

  • optris_sdk_region_get_name(). There was a setter and no getter, so every binding cached whatever it last wrote and a region it did not build reported an empty name. Region.Name in .NET, Region.name in Python and Region::name() in Rust now read through to the region.
  • optris_sdk_region_get_kind(), _get_emissivity(), _get_enabled(), and _get_want_percentiles(), _get_want_samples(), _get_blob_config(), _get_threshold_config().
  • optris_sdk_region_get_shape_count() and _get_shape(). A region's geometry is a boolean tree of placed shapes, and these report its leaves in tree order: the order the per-frame recording format stores leaf transforms in. Index 0 is the shape _get_centre(), _get_size() and _get_rotation() already described. A ring has two leaves, and reporting the outer circle for both is how a ring came back as a disc.
  • optris_sdk_region_read_shape_points(), for a polygon's vertices or a spline's control points, already placed by the leaf's transform. For a polygon those are the points to draw; for a spline they are the handles, and the curve comes from optris_sdk_region_read_shape_curve() instead. An ellipse has neither, which is an answer and not an error.
  • optris_sdk_imager_read_region_ids(). Before this the only ways to find a region were to remember the id add_region() returned and to look one up by name, neither of which helps for a region the application never added. Top level only: children are reached through their parent.

RegionShape::has_shear is the honesty valve. centre, size and rotation_rad decompose the leaf's matrix and cannot represent a shear; it is false for every region the constructors build, and true says "these three are an approximation".

The equivalent for alarm rules: optris_sdk_imager_get_rule_region() gives the region a rule was added to (a region rule's own input names a generational slot, not a region id), and optris_sdk_rule_get_action() reads its actions back.

How much of a region crossed a limit

An operator watching a process usually cares less about the single hottest pixel in a region than about how much of it has gone over a line: what fraction of a brake disc is above 200 C, how much of a pane is still below its setpoint, whether a heated bed has reached temperature across its area rather than at one point. That number moves smoothly where a maximum jumps around.

Region disc = Region::Circle({0.5F, 0.375F}, 0.2F);
disc.threshold = ThresholdConfig{true, 200.0F, ThresholdDirection::kAbove};
const auto id = camera.Regions().Add(std::move(disc));

const auto share = camera.Regions().ThresholdShare(id);
if (share && share->valid) {
  std::printf("%.1f%% of the disc is over 200 C\n", share->share * 100.0F);
}
  • Both numbers are over the region's measurable pixels: RegionStats::pixel_count. An unmeasurable pixel is in neither the numerator nor the denominator, which is the rule coverage already follows. That keeps the two separable: coverage says how much of the region had data at all, share says how much of that data crossed the limit. Dividing by the nominal area instead would make the same scene report a different share depending only on how far off the sensor edge the region had been dragged.
  • The comparison is strict on both sides, so kAbove and kBelow at one threshold never both count the same pixel.
  • Off by default, and "off" is reported as invalid rather than as a share of zero, which would read as "none of it is hot". RegionThresholdShare::valid is false for a region that did not ask, and for one that measured nothing.
  • It costs one comparison per pixel on the pass that is already running: no selection and no storage, unlike percentiles. It is opt-in only because a threshold nobody chose has no meaningful value. Honoured by every kind that measures pixels, including the point kinds, where it describes the aperture.
  • SignalField::kThresholdShare publishes it, as the fraction 0..1 rather than a percentage, so a rule can say "alarm when more than a fifth of this is over 200 C". A rule on a region with no threshold sits in kOrphaned.
  • Not called "coverage". That word is already RegionStats::coverage and the two answer different questions; confusing them in a user interface is the failure this naming avoids.

Through the bindings: optris_sdk_region_set_threshold_config() and optris_sdk_imager_get_region_threshold_share() in C, Region.Threshold and ThermalCamera.GetRegionThresholdShare() in .NET, Region.threshold and camera.regions.threshold_share() in Python, Region::set_threshold_config() and Camera::region_threshold_share() in Rust.

The profile a line measured

RegionStats is a reduction. The pixels it was reduced from are available too, for the chart a line region exists to draw: temperature against distance across a weld, a heater track or a seam.

auto line = Region::Line({0.15f, 0.375f}, {0.85f, 0.375f});
line.want_samples = true;            // opt-in; see the cost note below
const auto id = imager->Regions().Add(std::move(line));

// ... a frame later
if (auto profile = imager->Regions().Samples(id)) {
  for (const RegionSample &s : *profile) {
    // s.position * frame_width is the distance in pixels along the
    // line; s.value_c is NaN where the pixel was not measurable.
    Plot(s.position, s.value_c);
  }
}

Four properties, each of which is a decision rather than an accident:

  • A sample is one pixel, not a resampled point. The samples are exactly the pixels the statistics were computed over (the same Contains() test at the same LineTolerance()), so max_c is always the largest value_c in the profile and the two can never drift apart. Nothing is interpolated between pixel centres.
  • position is the distance from the line's first endpoint, in region coordinates, and the samples are sorted by it. Multiply by the frame width for pixels. It is NaN for any geometry that is not a single line segment; there is no honest distance-along an ellipse or a boolean tree, and those samples arrive in scan order with pixel_x / pixel_y saying exactly where each came from.
  • An unmeasurable pixel is present with value_c NaN, not omitted. A gap the caller cannot see is worse than one it can: a chart draws a break rather than a straight line across the hole. Such pixels are excluded from pixel_count, so the profile can be longer than the pixel count beside it, and that difference is the measurable half of coverage.
  • A line is one pixel per step. A line region is rasterised: along whichever axis the segment covers more of, each step takes exactly the one pixel the segment passes through, including both end pixels. So a horizontal line across 100 columns measures exactly 100 pixels, whatever sub-pixel height it was drawn at. This is the same rule the pipeline's own line measurement uses.
  • It is opt-in. An area region can cover the whole frame and keeping every pixel costs four bytes per pixel per frame. Honoured by kArea and kBlobGroup (which is what Region::Line() builds) and, since API version 12, by the point kinds as well, where it reports the aperture's clipped set (see Setting one, and seeing what it did). The storage is reused frame to frame, so a steady region allocates nothing after the first.

There is no separate "profile" region kind, and that is deliberate: a profile is a line region that kept its samples, so the profile and the statistics are two views of one measurement rather than two measurements that could disagree.

Through the bindings: optris_sdk_region_set_want_samples() and optris_sdk_imager_read_region_samples() in C, Region.KeepSamples and ThermalCamera.ReadRegionSamples() in .NET, Region.want_samples and camera.regions.samples() in Python, Region::want_samples() and Camera::region_samples() in Rust. A runnable example exists in every one of those languages: line_profile in examples/cpp/measurement/, examples/c/measurement/, examples/csharp/measurement/, examples/rust/measurement/ and examples/python/measurement/.

Coverage

Coverage is the fraction of a region that actually had sensor behind it, and it is 1.0 in the ordinary case. Below that the statistics are still honest, because they cover only the part that had data, and that is what separates "20 degrees across this region" from "20 degrees across the 30 per cent of it that had data".

if (stats.coverage < 1.0f) {
  std::println("only {:.0f}% of the region had data",
               stats.coverage * 100.0f);
}

Reading state per frame

For a live display, read the dense array rather than querying region by region. It is one lock and one copy:

for (const auto &state : imager->Regions().States()) {
  if (!state.stats.valid) continue;
  Draw(state.region_id, state.stats.max_c, state.alarm);
}

RegionState carries the id, the statistics, the rolled-up alarm state for that region, how many of its rules are active or warning, and which frame the statistics were measured on. Regions().ReadStates(buffer, capacity) fills a caller-provided buffer, returns how many it wrote, and allocates nothing.

Which frame a read belongs to, and why you have to ask. The SDK hands a frame to your callback or stream before it runs the measuring pass, so a consumer holding frame N can read a store that still holds N−1, or N+k once it has fallen behind, which is the worse case because it looks current. RegionState::frame_sequence and frame_timestamp_us name the capture the statistics came from, so the mismatch is detectable instead of silent.

Read has_frame_metadata first. Sequence 0 is a real frame, the first of the stream, so no value of frame_sequence can mean "nobody said"; the flag is the only thing that can. It is false before the first measuring pass and for a standalone RegionStore measured from a bare buffer, which is also why RegionStore::Measure() takes an optional trailing const FrameMetadata *: the identity travels with the pass rather than being set beside it, so it cannot get out of step with the statistics it names.

for (const auto &state : imager->Regions().States()) {
  if (!state.stats.valid) continue;
  if (state.has_frame_metadata && state.frame_sequence != sequence_in_hand) {
    // The statistics belong to another capture. Flag it rather than
    // charting it against the frame you are holding.
    continue;
  }
  Chart(state.region_id, state.stats.mean_c);
}

Regions().Get(id) returns a copy of one region including its readings, or nothing for an unknown id. It is a copy: changing it changes nothing on the camera; use Edit() for that. Regions().FindId(name) returns the id of the region with that name, or 0. List(), Count(), Remove(id) and Clear() complete the set; removing a region also removes every rule attached to it.