Skip to main content
When processing sensor streams, you often want to reduce frequency while keeping the best quality data. For discrete data like images that can’t be averaged or merged, instead of blindly dropping frames, quality_barrier selects the highest quality item within each time window.

The Problem

A camera outputs 30fps, but your ML model only needs 2fps. Simple approaches:
  • sample(0.5) - Takes whatever frame happens to land on the interval tick
  • throttle_first(0.5) - Takes the first frame, ignores the rest
Both ignore quality. You might get a blurry frame when a sharp one was available.

The Solution: quality_barrier

session=qb

Image Sharpness Filtering

For camera streams, we provide sharpness_barrier which uses the image’s sharpness score. Let’s use real camera data from the Unitree Go2 robot to demonstrate. We use the Sensor Storage & Replay toolkit, which provides access to recorded robot data:
skip session=qb
Using sharpness_barrier to select the sharpest frames:
skip session=qb
Visualizing which frames were selected (green border = selected as sharpest in window):
skip session=qb output=assets/frame_mosaic.jpg
output
skip session=qb output=assets/sharpness_graph.svg
output Let’s request a higher frequency.
skip session=qb
skip session=qb output=assets/frame_mosaic2.jpg
output
skip session=qb output=assets/sharpness_graph2.svg
output As we can see the system is trying to strike a balance between requested frequency and quality that’s available

Usage in Camera Module

Here’s how it’s used in the actual camera module:
skip

How Sharpness is Calculated

The sharpness score (0.0 to 1.0) is computed using Sobel edge detection: from Image.py
skip session=qb

Custom Quality Functions

You can use quality_barrier with any quality metric:
session=qb

API Reference

quality_barrier(quality_func, target_frequency)

RxPY pipe operator that selects the highest quality item within each time window. Returns: A pipe operator for use with .pipe()

sharpness_barrier(target_frequency)

Convenience wrapper for images that uses image.sharpness as the quality function. Returns: A pipe operator for use with .pipe()