roboflow/supervision · error · ValueError
color length ({len(color_seq)}) must match sigma length ({le
Error message
color length ({len(color_seq)}) must match sigma length ({len(sigma_seq)}) What it means
Raised by sv.Color.from_bgra_tuple when any of the four (b, g, r, a) values is outside 0-255. Like its RGBA counterpart it validates alpha as a byte too. The message echoes values in the BGRA order you supplied. This is the four-channel counterpart used when bridging OpenCV BGRA data into supervision.
Source
Thrown at src/supervision/key_points/annotators.py:299
def __init__(
self,
sigma: float | Sequence[float] = (1.0, 2.0, 3.0),
color: Color | Sequence[Color] = (Color.GREEN, Color.YELLOW, Color.RED),
max_axis: float | None = None,
) -> None:
sigma_seq: Sequence[float] = (
(sigma,) if isinstance(sigma, (int, float)) else sigma
)
color_seq: Sequence[Color] = (color,) if isinstance(color, Color) else color
if len(sigma_seq) == 0:
raise ValueError("sigma must contain at least one value")
if any(s <= 0 for s in sigma_seq):
raise ValueError("All sigma values must be positive")
if max_axis is not None and max_axis <= 0:
raise ValueError("max_axis must be positive when provided")
if len(color_seq) != len(sigma_seq):
raise ValueError(
f"color length ({len(color_seq)}) must match "
f"sigma length ({len(sigma_seq)})"
)
sorted_indices = sorted(
range(len(sigma_seq)), key=lambda i: sigma_seq[i], reverse=True
)
self.sigma = [sigma_seq[i] for i in sorted_indices]
self.color = [color_seq[i] for i in sorted_indices]
self.max_axis = max_axis
def _get_covariances(self, key_points: KeyPoints) -> npt.NDArray[np.float32]:
covariances = key_points.data.get("covariance")
if covariances is None:
raise ValueError(
"key_points.data must contain 'covariance' with shape (N, K, 2, 2)."
)
covariances_array = cast(View on GitHub (pinned to 7f254d9784)
Solutions
- Verify channel order is truly B, G, R, A — use from_rgba_tuple if your source is RGBA.
- Convert 0-1 float alpha to a byte with int(round(a * 255)).
- Clamp all four values to 0-255 before the call.
- When sampling from uint8 NumPy images, cast through int() to avoid wraparound artifacts.
Example fix
# before sv.Color.from_bgra_tuple((0, 255, 255, 0.5)) # float alpha, will raise # after sv.Color.from_bgra_tuple((0, 255, 255, int(round(0.5 * 255))))
Defensive patterns
Strategy: validation
Validate before calling
def safe_bgra(bgra: tuple) -> tuple[int, int, int, int]:
"""Clamp/cast a BGRA quad (e.g. from cv2.imread BGRA pixels) for from_bgra_tuple."""
return tuple(max(0, min(255, int(round(v)))) for v in bgra) # type: ignore[return-value] Type guard
def is_valid_bgra_tuple(t: tuple) -> bool:
"""True if t is four numbers (b, g, r, a) each within 0-255."""
return len(t) == 4 and all(isinstance(v, (int, float)) and 0 <= v <= 255 for v in t) Prevention
- Confirm BGRA order at the source (cv2.imread with IMREAD_UNCHANGED yields BGRA) before converting.
- Convert float/normalized alpha to byte alpha at the boundary.
- Wrap pixel-derived colors in a clamping helper to absorb uint8 wraparound and float means.
When it happens
Trigger: sv.Color.from_bgra_tuple((0, 255, 255, 300)), passing RGBA-ordered tuples to the BGRA method with out-of-range values, or CSS-style float alpha (0-1) in the fourth position.
Common situations: Reading BGRA pixels (e.g. PNG with alpha via cv2.imread with IMREAD_UNCHANGED) and reusing them as annotation colors; confusing RGBA and BGRA ordering between libraries; float opacity values from UI code flowing into the alpha slot.
Related errors
- All sigma values must be positive
- max_axis must be positive when provided
- Edge indices must use the 1-based convention and be within t
- sigma must contain at least one value
- module {__name__} has no attribute {name}
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/51c49d1f7849cab8.
Report an issue: GitHub.