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
- Describing a region you did not build
- How much of a region crossed a limit
- The profile a line measured
- Reading state per frame
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; };
typedef struct optris_sdk_region_stats { uint32_t struct_size; float min_c, max_c, mean_c, std_dev_c; float median_c; /* only when want_percentiles is set */ optris_sdk_vec2 min_loc, max_loc, centre_loc; uint32_t pixel_count; float coverage; /* measured / nominal; see below */ uint8_t valid; } optris_sdk_region_stats;
public readonly record struct RegionStats { public float Minimum { get; init; } public float Maximum { get; init; } public float Mean { get; init; } public float StandardDeviation { get; init; } public float Median { get; init; } // only with KeepPercentiles public Vector2 MinimumLocation { get; init; } public Vector2 MaximumLocation { get; init; } public Vector2 Centre { get; init; } public int PixelCount { get; init; } public float Coverage { get; init; } // measured / nominal public bool IsValid { get; init; } }
class RegionStats: __slots__ = ('min_c', 'max_c', 'mean_c', 'std_dev_c', 'median_c', 'min_loc', 'max_loc', 'centre_loc', 'pixel_count', 'coverage', 'valid')
pub struct RegionStats { pub min_c: f32, pub max_c: f32, pub mean_c: f32, pub std_dev_c: f32, pub median_c: f32, // only when want_percentiles is set pub min_loc: Vec2, pub max_loc: Vec2, pub centre_loc: Vec2, pub pixel_count: u32, pub coverage: f32, // measured / nominal; see below pub valid: bool, }
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_countandcoverageare 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++. }
uint64_t ids[64]; char region_name[OPTRIS_SDK_MAX_NAME]; optris_sdk_region_kind kind; size_t id_count = 0; size_t n; optris_sdk_imager_read_region_ids(imager, ids, 64, &id_count); for (n = 0; n < id_count; ++n) { /* One accessor at a time, against a copy of the region. */ optris_sdk_region *held = NULL; optris_sdk_imager_copy_region(imager, ids[n], &held); optris_sdk_region_get_name(held, region_name, sizeof(region_name), NULL); optris_sdk_region_get_kind(held, &kind); printf("%s\n", region_name); optris_sdk_region_free(held); }
foreach (ulong id in camera.GetRegionIds()) { using Region held = camera.GetRegion(id); // held.Name, held.Kind, held.Emissivity and held.IsEnabled all // read through to the region rather than from a cache. Console.WriteLine(held.Name); }
for held_id in camera.regions.ids(): held = camera.regions.copy(held_id) # held.name, held.kind, held.emissivity and held.enabled all read # through to the region rather than from a cache. print(held.name)
for held_id in camera.region_ids()? { let held = camera.region(held_id)?; // held.name(), held.kind(), held.emissivity() and // held.is_enabled() all read through to the region rather than // from a cache. println!("{}", held.name()?); }
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.Namein .NET,Region.namein Python andRegion::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 fromoptris_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 idadd_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); }
optris_sdk_vec2 disc_centre = {0.5F, 0.375F}; optris_sdk_threshold_config limit; optris_sdk_region_threshold_share share; optris_sdk_region *disc = NULL; uint64_t disc_id = 0; optris_sdk_region_create_circle(disc_centre, 0.2F, &disc); optris_sdk_threshold_config_init(&limit, sizeof(limit)); limit.enabled = 1; limit.threshold_c = 200.0F; limit.direction = OPTRIS_SDK_THRESHOLD_ABOVE; optris_sdk_region_set_threshold_config(disc, &limit); optris_sdk_imager_add_region(imager, disc, &disc_id); optris_sdk_region_free(disc); optris_sdk_region_threshold_share_init(&share, sizeof(share)); optris_sdk_imager_get_region_threshold_share(imager, disc_id, &share); if (share.valid) { printf("%.1f%% of the disc is over 200 C\n", (double)share.share * 100.0); }
using Region disc = Region.Circle(new Vector2(0.5f, 0.375f), 0.2f); disc.Threshold = RegionThreshold.Above(200.0f); ulong discId = camera.AddRegion(disc); RegionThresholdShare share = camera.GetRegionThresholdShare(discId); if (share.IsValid) { Console.WriteLine($"{share.Share:P1} of the disc is over 200 C"); }
disc = optris_sdk.Region.circle((0.5, 0.375), 0.2) disc.threshold = optris_sdk.RegionThreshold( threshold_c=200.0, direction=optris_sdk.THRESHOLD_ABOVE) disc_id = camera.regions.add(disc) share = camera.regions.threshold_share(disc_id) if share.valid: print(f"{share.share * 100.0:.1f}% of the disc is over 200 C")
let mut disc = Region::circle((0.5, 0.375), 0.2)?; disc.set_threshold_config(ThresholdConfig::above(200.0))?; let disc_id = camera.add_region(&disc)?; // None where the other bindings answer valid = false: a region that // did not ask for a threshold, or one that measured nothing. So there // is no second test here. if let Some(share) = camera.region_threshold_share(disc_id)? { println!("{:.1}% of the disc is over 200 C", share.share * 100.0); }
- 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 rulecoveragealready follows. That keeps the two separable:coveragesays how much of the region had data at all,sharesays 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
kAboveandkBelowat 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::validis 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::kThresholdSharepublishes 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 inkOrphaned.- Not called "coverage". That word is already
RegionStats::coverageand 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); } }
optris_sdk_vec2 line_a = {0.15F, 0.375F}; optris_sdk_vec2 line_b = {0.85F, 0.375F}; optris_sdk_region_sample profile[1024]; optris_sdk_region *line = NULL; uint64_t line_id = 0; size_t sample_count = 0; size_t s; optris_sdk_region_create_line(line_a, line_b, &line); optris_sdk_region_set_want_samples(line, 1); /* opt-in */ optris_sdk_imager_add_region(imager, line, &line_id); optris_sdk_region_free(line); /* ... a frame later. position * frame width is the distance in * pixels; value_c is NaN where the pixel was not measurable. */ optris_sdk_imager_read_region_samples(imager, line_id, profile, sizeof(profile[0]), 1024, &sample_count); for (s = 0; s < sample_count; ++s) { printf("%.3f %.1f\n", (double)profile[s].position, (double)profile[s].value_c); }
using Region line = Region.Line(new Vector2(0.15f, 0.375f), new Vector2(0.85f, 0.375f)); line.KeepSamples = true; // opt-in ulong lineId = camera.AddRegion(line); // ... a frame later. Position * frame width is the distance in // pixels; Value is NaN where the pixel was not measurable. foreach (RegionSample s in camera.ReadRegionSamples(lineId)) { Console.WriteLine($"{s.Position:F3} {s.Value:F1}"); }
line = optris_sdk.Region.line((0.15, 0.375), (0.85, 0.375)) line.want_samples = True # opt-in line_id = camera.regions.add(line) # ... a frame later. position * camera.width is the distance in # pixels; value_c is NaN where the pixel was not measurable. for s in camera.regions.samples(line_id): print(f"{s.position:.3f} {s.value_c:.1f}")
let mut line = Region::line((0.15, 0.375), (0.85, 0.375))?; line.want_samples(true)?; // opt-in let line_id = camera.add_region(&line)?; // ... a frame later. position * frame width is the distance in // pixels; value_c is None where the pixel was not measurable, which // is how Rust spells the NaN the other bindings report. for s in camera.region_samples(line_id)? { println!("{:.3} {:?}", 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 sameLineTolerance()), somax_cis always the largestvalue_cin the profile and the two can never drift apart. Nothing is interpolated between pixel centres. positionis 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 withpixel_x/pixel_ysaying exactly where each came from.- An unmeasurable pixel is present with
value_cNaN, 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 frompixel_count, so the profile can be longer than the pixel count beside it, and that difference is the measurable half ofcoverage. - 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
kAreaandkBlobGroup(which is whatRegion::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); }
if (stats.coverage < 1.0F) { printf("only %.0f%% of the region had data\n", (double)stats.coverage * 100.0); }
if (stats.Coverage < 1.0f) { Console.WriteLine($"only {stats.Coverage:P0} of the region had data"); }
if stats.coverage < 1.0: print(f"only {stats.coverage * 100.0:.0f}% of the region had data")
if stats.coverage < 1.0 { println!("only {:.0}% of the region had data", stats.coverage * 100.0); }
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); }
optris_sdk_region_state states[64]; size_t state_count = 0; size_t k; optris_sdk_imager_read_region_states(imager, states, sizeof(states[0]), 64, &state_count); for (k = 0; k < state_count; ++k) { if (!states[k].stats.valid) { continue; } printf("%llu %.1f %d\n", (unsigned long long)states[k].region_id, (double)states[k].stats.max_c, (int)states[k].alarm); }
foreach (RegionState state in camera.ReadRegionStates()) { if (!state.Stats.IsValid) { continue; } Console.WriteLine($"{state.Id} {state.Stats.Maximum:F1} " + $"{state.Alarm}"); }
for state in camera.regions.states(): if not state.stats.valid: continue print(state.region_id, f"{state.stats.max_c:.1f}", state.alarm)
for state in camera.read_region_states()? { if !state.stats.valid { continue; } println!("{} {:.1} {:?}", 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); }
for (k = 0; k < state_count; ++k) { if (!states[k].stats.valid) { continue; } if (states[k].has_frame_metadata && states[k].frame_sequence != sequence_in_hand) { /* The statistics belong to another capture. Flag it rather than * charting it against the frame you are holding. */ continue; } printf("%.1f\n", (double)states[k].stats.mean_c); }
foreach (RegionState state in camera.ReadRegionStates()) { if (!state.Stats.IsValid) { continue; } if (state.HasFrame && state.FrameSequence != sequenceInHand) { // The statistics belong to another capture. Flag it rather // than charting it against the frame you are holding. continue; } Console.WriteLine($"{state.Stats.Mean:F1}"); }
for state in camera.regions.states(): if not state.stats.valid: continue if state.has_frame and 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 print(f"{state.stats.mean_c:.1f}")
for state in camera.read_region_states()? { if !state.stats.valid { continue; } if state.has_frame && 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; } println!("{:.1}", 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.