optris::sdk::MeasuredFrameRate
How many real frames arrived, over how long.
Read it after the camera has been streaming for a moment; see valid for what it says before then.
What counts as a frame
A frame the SDK delivered and that carried new pixels. A repeated frame -- one the SDK held and delivered again because the shutter was in the way, which FrameMetadata::is_repeated_frame marks -- does not count. That is the whole point: an application that counted callbacks would get the callback rate, which does not fall during a shutter cycle because the stream stays continuous.
The algorithm, in one line
measured_hz = real_frames / (window_ms / 1000) delivered_hz = (real_frames + repeated_frames) / (window_ms / 1000)
a count of real frames over a sliding window ending now. Both numbers on the right are reported, so the figure on the left can be re-derived and its resolution worked out: the count quantises the answer to one frame per window, which is 1000 / window_ms Hz.
The window
Long enough to hold at least eight frames at the rate the source is configured for, and then bounded to between 1 and 4 seconds. So a 32 Hz camera is measured over 1 s (32 samples), a 125 Hz camera over 1 s (125 samples, a 0.8 % resolution), and a 4 Hz camera over 2 s (8 samples) rather than over a second that holds four of its frames.
What it does on the cases that matter
- A shutter cycle.
measured_hzdips towards zero for the length of the closure and recovers, whiledelivered_hzstays at the camera's nominal rate. Deliberately not smoothed across it: a number that hid the closure would be the configured number wearing a different hat.delivered_hzandrepeated_framesare what distinguish a healthy camera mid-cycle from one that has stopped, and a consumer that treats a lowmeasured_hzas a lost camera would report every shutter cycle as a fault. - A dropped frame. Never observed, so never counted. The rate falls, which is the truth.
- Subsampling. Only delivered frames are observed, so this reports the subsampled rate -- what the application is actually given.
- A stalled camera. Both rates read 0 Hz with
validset, which is a measurement. Distinct fromvalidbeing false, which means nothing has been measured yet.
Which number to use
measured_hz for how often the scene was actually measured over the last window, closures included. delivered_hz for deciding whether the camera is still there. They are equal whenever nothing is being held, which is most of the time. For a figure shown to a user beside a picture, LiveFrameRate: the same count with the shutter closures and the pauses of a replay left out, so it does not read 0 through either.
Public attributes
valid
bool valid = false
False until there is something to report: fewer than two frames have been delivered, or the first one arrived too recently to divide by. Every other field is then at its default and means nothing.
Not the same as a measured zero. A stalled camera reports valid == true and measured_hz == 0; a camera that has not started reports valid == false.
measured_hz
float measured_hz = 0.0F
Real frames per second over the window, in Hz.
How often the scene was measured over the last window of wall time. It falls during a shutter closure, because during one the scene is not being measured, and falls to zero across a paused replay. LiveFrameRate::hz is the same count with those intervals left out, and is the figure to show a user.
delivered_hz
float delivered_hz = 0.0F
All frames per second over the same window, repeats included.
This is the rate to decide whether the camera is alive. The two answer different questions and both are needed: a camera mid-closure has measured_hz near zero and delivered_hz at its nominal rate, while a camera that has actually stopped has both at zero. Treating a low measured_hz as a lost camera would report every healthy shutter cycle as a fault.
Exactly (real_frames + repeated_frames) / (window_ms / 1000), so it adds no fact that is not already here -- it is named rather than left for a caller to derive, because the derivation is the part that gets got wrong.
window_ms
float window_ms = 0.0F
The window measured_hz was counted over, in milliseconds.
Normally the window described above. Shorter while the stream is younger than that, so a usable figure is available early rather than after four seconds of nothing; it grows to the full window and stays there.
real_frames
std::uint32_t real_frames = 0
Real frames counted in the window. The numerator of measured_hz.
repeated_frames
std::uint32_t repeated_frames = 0
Repeated frames delivered in the same window.
Why measured_hz is below FrameRateInfo::effective_hz, when it is. A shutter cycle shows up here; frames lost under load do not, because a frame that was never delivered was never counted either way.
total_real_frames
std::uint64_t total_real_frames = 0
Every real frame delivered since the stream started. Does not wrap in any realistic run: 2^64 frames at 1 kHz is half a billion years.
total_repeated_frames
std::uint64_t total_repeated_frames = 0
Every repeated frame delivered since the stream started.