Skip to main content

Color threshold detection

color_threshold_detection finds connected regions that fall within configured HSV ranges. It returns one detection per contour after optional blur and morphology cleanup.

Inputs

  • frame: a three-channel BGR NumPy image.

Outputs

  • detections: a list of dictionaries with bbox, class_id, color_name, and area.

bbox is [x1, y1, x2, y2], normalized against the unpadded image content. area is measured in pixels on the letterboxed image.

When to use

Use this operation when the target has a predictable color and a trained detection model is unnecessary. HSV ranges usually need retuning when lighting or camera exposure changes.

Configuration

SettingDefaultNotes
camera_bus_idrequiredCamera whose calibration is used to undistort box corners. Requires restart.
target_size320Square letterbox size, 64 to 1024. Requires restart.
color_rangesrequiredList of objects containing name, class_id, lower_hsv, and upper_hsv.
min_area100Reject contours smaller than this letterboxed pixel area.
max_area50000Reject contours larger than this letterboxed pixel area.
blur_kernel_size0Gaussian kernel size. Use 0 to disable it; nonzero values must be odd.
morphology_kernel_size5Opening and closing kernel size. It must be odd.
morphology_iterations0Use 0 to disable morphology. The editor currently validates configured nonzero values from 1 to 10.

HSV hue uses 0 to 179. Saturation and value use 0 to 255.

{
"camera_bus_id": "0-1",
"color_ranges": [
{
"name": "red",
"class_id": 0,
"lower_hsv": [0, 100, 100],
"upper_hsv": [10, 255, 255]
}
]
}

Important behavior and limitations

The operation rejects monochrome frames. One physical object can produce several detections if its mask has disconnected regions. Bounds may extend outside 0 to 1 after padding removal or point undistortion because the implementation does not clip them.