Regions
What a region is, what kinds there are, and the coordinate system they all live in. Read this first; the pages after it are the shape, the aperture and the numbers.
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
Overview
A region is a measuring area on the thermal frame. It is the single model for what earlier versions split across Roi and MeasurementField: it carries geometry, per-region emissivity, styling, hierarchy, blob configuration and motion, it is measured on every frame, and its alarms belong to it rather than sitting in a parallel list that refers to it.
Regions live on the camera, reached through Imager::Regions(), a RegionEngine that measures every added region on every frame. There is no separate container to keep in step with the camera.
A Player exposes the same RegionEngine, and a replayed frame is measured the same way a live one is, with three caveats:
- A recording made with regions carries a per-frame record of what they measured, and applying it prunes any region the record does not name. A region you add to such a recording is therefore gone again by the end of the frame. Regions you add yourself survive on a recording that carried none.
- A replay cannot apply a per-region emissivity: the correction needs the camera's characteristic curve to invert, and a file does not carry one. Numbers restored from the record were corrected when the file was written; numbers from the replay's own measuring pass were not.
- A picture recording (one written as colorized video, which
Player::IsPicture()reports) holds no temperatures, so nothing measures.
auto zone = optris::sdk::Region::Rect({0.5f, 0.375f}, {0.4f, 0.3f}); zone.name = "Furnace"; const auto id = imager->Regions().Add(std::move(zone));
optris_sdk_vec2 centre = {0.5F, 0.375F}; optris_sdk_vec2 size = {0.4F, 0.3F}; optris_sdk_region *zone = NULL; uint64_t zone_id = 0; optris_sdk_region_create_rect(centre, size, 0.0F, &zone); optris_sdk_region_set_name(zone, "Furnace"); optris_sdk_imager_add_region(imager, zone, &zone_id); optris_sdk_region_free(zone); /* the camera took a copy */
using Region zone = Region.Rect(new Vector2(0.5f, 0.375f), new Vector2(0.4f, 0.3f)); zone.Name = "Furnace"; ulong zoneId = camera.AddRegion(zone);
zone = optris_sdk.Region.rect((0.5, 0.375), (0.4, 0.3)) zone.set_name('Furnace') zone_id = camera.regions.add(zone)
let mut zone = Region::rect((0.5, 0.375), (0.4, 0.3), 0.0)?; zone.set_name("Furnace")?; let zone_id = camera.add_region(&zone)?;
Geometry is a canonical unit primitive, either the unit circle or the unit square spanning (-1,-1) to (1,1), placed by a 3×3 affine transform. Position, size, rotation and shear are inherent in that matrix, so no primitive carries its own parameters and a moving region records as a handful of floats per frame. You do not have to think about the matrix: see Creating a region.
For alarms, see Alarms. For worked examples, see Region Examples.
Coordinates
Region coordinates are frame-normalized and isotropic: the origin is the top-left of the frame and both axes are divided by the frame width.
xruns 0 … 1 across the image.yruns 0 … height/width: 0.75 on a 4:3 camera, not 1.0.
This is deliberate, and it is the one thing to get right when porting. Under the older Roi scheme, which divided y by the height, a "circle" was an ellipse in pixels on every non-square sensor, and a sampling radius covered a different number of pixels horizontally than vertically. Dividing both axes by the width makes a circle round and gives a radius one meaning.
Converting to and from pixels. C++ and Python ship a helper; C, .NET and Rust do not, and the conversion is one division either way because both axes are the frame width:
const auto px = optris::sdk::ToPixels({0.5f, 0.375f}, width, height); const auto rg = optris::sdk::FromPixels({320.0f, 240.0f}, width, height); // The y extent of the region space for this frame shape. const float bottom = optris::sdk::RegionSpaceHeight(width, height);
uint32_t frame_w = 0; uint32_t frame_h = 0; optris_sdk_vec2 rg; optris_sdk_imager_get_width(imager, &frame_w); optris_sdk_imager_get_height(imager, &frame_h); rg.x = 320.0F / (float)frame_w; rg.y = 240.0F / (float)frame_w; /* The y extent of the region space for this frame shape. */ float bottom = (float)frame_h / (float)frame_w;
float frameWidth = camera.Width; var rg = new Vector2(320.0f / frameWidth, 240.0f / frameWidth); var px = new Vector2(0.5f * frameWidth, 0.375f * frameWidth); // The y extent of the region space for this frame shape. float bottom = camera.Height / frameWidth;
rg = camera.from_pixels(320.0, 240.0) px = camera.to_pixels((0.5, 0.375)) # The y extent of the region space for this frame shape. bottom = camera.height / camera.width
let frame_width = camera.width()? as f32; let rg = (320.0 / frame_width, 240.0 / frame_width); let px = (0.5 * frame_width, 0.375 * frame_width); // The y extent of the region space for this frame shape. let bottom = camera.height()? as f32 / frame_width;
Do the division; do not pass pixels to a region constructor. A region placed at a pixel coordinate lands far off frame, where it measures nothing and reports valid = false rather than raising.
If you already have pixel geometry, convert it rather than porting it by hand:
auto region = optris::sdk::RegionFromGeometry( optris::sdk::Rectangle{10, 10, 40, 30}, width, height);
Because coordinates are relative to the frame, regions survive a change of resolution (an operation-mode switch, or a subsampled window) without moving.
Region kinds
RegionKind says what the region is for; it is orthogonal to its geometry. The constructors set it: Region::Spot() builds kSpot (as does Region::FromDrag(Primitive::kPoint, ...)) and every other constructor, including Region::Line(), builds kArea. Nothing constructs kHotSpot, kColdSpot, kBlobGroup or kLabel; set Region::kind yourself after building the geometry. The kind reads back as set in every language.
| Kind | Behaviour |
|---|---|
kArea |
Statistics over every pixel inside the geometry. |
kSpot |
Measured at a fixed point, through its aperture. |
kHotSpot |
Tracks the maximum inside its parent (or the frame). |
kColdSpot |
Tracks the minimum inside its parent (or the frame). |
kBlobGroup |
Statistics exactly as kArea, and the search area for blob detection. Every field of its blobs settings (BlobConfig) is honoured; the blobs are read back with Regions().Blobs(id) and SignalField::kBlobCount reports how many were found this frame. Detection is confined to the region, so a hot area straddling the boundary is clipped to it. See Blob detection. |
kLabel |
Annotation only; never measured. |
Blob detection
A kBlobGroup region finds connected hot areas inside itself, every frame, on the measured temperatures.
auto group = Region::Rect({0.5f, 0.375f}, {0.4f, 0.4f}); group.kind = RegionKind::kBlobGroup; group.blobs.threshold = 45.0f; // the band's floor, in C group.blobs.threshold_max = 0.0f; // no ceiling group.blobs.min_size = 20; // in member pixels const auto id = imager->Regions().Add(std::move(group)); // ... later, per frame. Blobs() is nullopt for an unknown id and an // empty vector for a region that found nothing, so test it. if (const auto blobs = imager->Regions().Blobs(id)) { for (const auto &blob : *blobs) { std::printf("%u px, max %.1f C at (%.3f, %.3f)\n", blob.pixel_count, blob.max_c, blob.centre.x, blob.centre.y); } }
optris_sdk_vec2 group_centre = {0.5F, 0.375F}; optris_sdk_vec2 group_size = {0.4F, 0.4F}; optris_sdk_blob_config detection; optris_sdk_blob found[64]; optris_sdk_region *group = NULL; uint64_t group_id = 0; size_t blob_count = 0; size_t b; optris_sdk_region_create_rect(group_centre, group_size, 0.0F, &group); optris_sdk_region_set_kind(group, OPTRIS_SDK_REGION_BLOB_GROUP); /* The defaults come from the library rather than from this page. */ optris_sdk_blob_config_init(&detection, sizeof(detection)); detection.threshold_c = 45.0F; /* the band's floor, in C */ detection.threshold_max_c = 0.0F; /* no ceiling */ detection.min_size_pixels = 20; /* in member pixels */ optris_sdk_region_set_blob_config(group, &detection); optris_sdk_imager_add_region(imager, group, &group_id); optris_sdk_region_free(group); /* ... later, per frame. An unknown id is an error; a region that * found nothing answers a count of zero. */ optris_sdk_imager_read_region_blobs(imager, group_id, found, sizeof(found[0]), 64, &blob_count); for (b = 0; b < blob_count; ++b) { printf("%u px, max %.1f C at (%.3f, %.3f)\n", found[b].pixel_count, (double)found[b].max_c, (double)found[b].centre.x, (double)found[b].centre.y); }
using Region group = Region.Rect(new Vector2(0.5f, 0.375f), new Vector2(0.4f, 0.4f)); group.Kind = RegionKind.BlobGroup; group.BlobDetection = BlobDetection.Default with { Threshold = 45.0f, // the band's floor, in C ThresholdMax = 0.0f, // no ceiling MinSizePixels = 20, // in member pixels }; ulong groupId = camera.AddRegion(group); // ... later, per frame. An unknown id throws; a region that found // nothing answers an empty array. foreach (RegionBlob blob in camera.ReadRegionBlobs(groupId)) { Console.WriteLine($"{blob.PixelCount} px, max {blob.Max:F1} C " + $"at ({blob.Centre.X:F3}, {blob.Centre.Y:F3})"); }
group = optris_sdk.Region.rect((0.5, 0.375), (0.4, 0.4)) group.kind = optris_sdk.BLOB_GROUP # The defaults come from the library rather than from this page. detection = group.blobs detection.threshold_c = 45.0 # the band's floor, in C detection.threshold_max_c = 0.0 # no ceiling detection.min_size_pixels = 20 # in member pixels group.blobs = detection group_id = camera.regions.add(group) # ... later, per frame. An unknown id raises; a region that found # nothing answers an empty list. for blob in camera.regions.blobs(group_id): print(f"{blob.pixel_count} px, max {blob.max_c:.1f} C " f"at ({blob.centre.x:.3f}, {blob.centre.y:.3f})")
let mut group = Region::rect((0.5, 0.375), (0.4, 0.4), 0.0)?; group.set_kind(RegionKind::BlobGroup)?; // The defaults come from the library rather than from this page. let mut detection = BlobConfig::new()?; detection.threshold_c = 45.0; // the band's floor, in C detection.threshold_max_c = 0.0; // no ceiling detection.min_size_pixels = 20; // in member pixels group.set_blob_config(detection)?; let group_id = camera.add_region(&group)?; // ... later, per frame. An unknown id is an Err; a region that found // nothing answers an empty Vec. for blob in camera.region_blobs(group_id)? { println!("{} px, max {:.1} C at ({:.3}, {:.3})", blob.pixel_count, blob.max_c, blob.centre.x, blob.centre.y); }
Confinement. Only pixels whose centres the region contains can join a blob: the same Contains() test the statistics were taken over. A hot area straddling the boundary is therefore clipped to the region rather than accepted or rejected whole, which is what makes a blob group a search area rather than a filter on centroids.
Coordinates. RegionBlob::centre, size and contour are in region coordinates, the same space Region::geometry is in: both axes normalised by the frame width. Multiply by the frame width to get pixels. The outline and its own bounding box agree, which they do not in the lower-level view::Blob the detector returns.
Blobs are results, not children. Nothing is added to Region::children, no region id churns, and no rule is orphaned. This is deliberate: region ids and signal slots are generational, so destroying and recreating a child per blob per frame would permanently orphan any rule attached to one, and would cost an extra recursive measurement pass per blob on the frame thread. The consequence is that a blob carries no identity across frames: the vector is rebuilt each frame and the entry at index 3 is not promised to be the thing that was at index 3 last frame. Alarm on SignalField::kBlobCount, or on the region's own statistics, rather than on an individual blob.
Cost. Detection scans the region's clamped pixel box once. BlobRenderMode::kContour is the expensive switch: tracing an outline costs blob count times region area, rather than growing with the number of hot pixels. Leave render_mode at kBox whenever the box is all that gets drawn.
For movement rather than temperature, use a motion zone (Imager::Motion()) and SignalField::kMotionBlobCount.
Drawing and labels
Region::style (RegionStyle) says how the region is drawn in the overlay, and nothing else: it does not change what is measured, and it is saved into the region document a recording and a camera configuration carry. The outline colour and width, the marker shape and size for the point kinds, and the label settings all live there. The same surface is optris_sdk_region_style in C (optris_sdk_region_set_style() / optris_sdk_region_get_style(), added at API version 33), Region.Style in .NET, region.style in Python and Region::set_style() in Rust, so a region added from any language can look different from its neighbours; before version 33 every region drew with the defaults, a 2 px red outline with a 5 px crosshair, and a hot spot was indistinguishable from a cold spot in the picture.
Labels. show_label draws the region's name and reading beside it, in text_color, placed by label_anchor and label_margin, sized by font_size (0 lets the renderer choose a height that suits the frame). The reading follows the kind, which is the number an operator watches that region for: the hottest pixel of a hot spot, the coldest of a cold spot, and the mean of everything else that measures; a kLabel region shows its name alone, as does any region whose statistics are not valid this frame. The font is the SDK's own upper-case bitmap font: a lower-case name is drawn folded to upper case, and a character outside A to Z, 0 to 9 and basic punctuation is drawn as a blank rather than a wrong glyph.
Two things the style does not override. While an alarm rule on the region rings, the outline draws pure red whatever color says; the stored colour is untouched and returns when the alarm clears. And show_aperture needs want_samples, because what it draws is the sampled set itself; Apertures says why.
Finding and removing
A region is looked up by the name it was given and removed by id.
const auto id = imager->Regions().FindId("middle"); // 0 if absent const bool removed = imager->Regions().Remove(id); imager->Regions().Clear();
uint64_t middle = 0; /* OPTRIS_SDK_ERROR_NOT_FOUND when nothing carries that name: one * call, and the status is the answer. */ if (optris_sdk_imager_get_region_id_by_name(imager, "middle", &middle) == OPTRIS_SDK_OK) { optris_sdk_imager_remove_region(imager, middle); } optris_sdk_imager_clear_regions(imager);
ulong id = camera.GetRegionId("middle"); // throws if absent bool found = camera.TryGetRegionId("middle", out id); // does not bool removed = camera.RemoveRegion(id); // false if it was not there camera.ClearRegions();
middle = camera.regions.id_of('middle') # raises if absent camera.regions.remove(middle) camera.regions.clear()
// Option rather than an error: an absent name is a question here, so // there is one call and not a Try pair. if let Some(middle) = camera.region_id_by_name("middle")? { camera.remove_region(middle)?; } camera.clear_regions()?;
Removing a region that is not there is the state you wanted, so it answers false rather than raising. Looking one up is the other way round: the plain form raises for a name nothing carries and the Try form does not, because an absent name is a fault in one case and a question in the other.
Migrating from Roi and MeasurementField
| Was | Now |
|---|---|
Roi / RoiContainer |
Region, on Imager::Regions() |
RoiAlarm |
a Rule on the region, see Alarms |
MeasurementField |
Region |
MeasurementStats |
RegionStats |
public AlarmMode |
Compare on a rule's condition |
Imager::AddMeasurementField() |
Imager::Regions().Add() |
Imager::GetMeasurementStats(id) |
Imager::Regions().Get(id)->stats |
Imager::SwapMeasurementFieldIndices() |
no equivalent; regions are addressed by id, not index |
roi.rect = {x, y, w, h} |
Region::Rect(centre, size) |
RoiType::PointMax / PointMin |
RegionKind::kHotSpot / kColdSpot |
roi.stats.avg_temp |
region.stats.mean_c |
The pixel-space geometry values (Point, Rectangle, Circle, Line, Ellipse, Polygon) survive in optris/sdk/measurement.h as inputs to RegionFromGeometry().
Roi itself remains, deprecated, but it is no longer reachable from Imager: AddRoi(), GetRois(), SetViewRois() and the rest are gone, and the overlay is drawn from the regions. What survives is the type and two converters, so code holding a stored preset or an editor model in the old shape can convert at the boundary. Convert with ToRegion() and ToRoi() rather than copying fields: the conversion applies the vertical coordinate change described in Coordinates, and hand-porting field by field silently misplaces every region by the aspect ratio.
auto region = optris::sdk::ToRegion(old_roi, width, height);