{"record":{"id":"51c49d1f7849cab8","repo":"roboflow/supervision","slug":"color-length-len-color-seq-must-match-sigma-l","errorCode":null,"errorMessage":"color length ({len(color_seq)}) must match sigma length ({len(sigma_seq)})","messagePattern":"color length \\((.+?)\\) must match sigma length \\((.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/key_points/annotators.py","lineNumber":299,"sourceCode":"    def __init__(\n        self,\n        sigma: float | Sequence[float] = (1.0, 2.0, 3.0),\n        color: Color | Sequence[Color] = (Color.GREEN, Color.YELLOW, Color.RED),\n        max_axis: float | None = None,\n    ) -> None:\n        sigma_seq: Sequence[float] = (\n            (sigma,) if isinstance(sigma, (int, float)) else sigma\n        )\n        color_seq: Sequence[Color] = (color,) if isinstance(color, Color) else color\n\n        if len(sigma_seq) == 0:\n            raise ValueError(\"sigma must contain at least one value\")\n        if any(s <= 0 for s in sigma_seq):\n            raise ValueError(\"All sigma values must be positive\")\n        if max_axis is not None and max_axis <= 0:\n            raise ValueError(\"max_axis must be positive when provided\")\n        if len(color_seq) != len(sigma_seq):\n            raise ValueError(\n                f\"color length ({len(color_seq)}) must match \"\n                f\"sigma length ({len(sigma_seq)})\"\n            )\n\n        sorted_indices = sorted(\n            range(len(sigma_seq)), key=lambda i: sigma_seq[i], reverse=True\n        )\n        self.sigma = [sigma_seq[i] for i in sorted_indices]\n        self.color = [color_seq[i] for i in sorted_indices]\n        self.max_axis = max_axis\n\n    def _get_covariances(self, key_points: KeyPoints) -> npt.NDArray[np.float32]:\n        covariances = key_points.data.get(\"covariance\")\n        if covariances is None:\n            raise ValueError(\n                \"key_points.data must contain 'covariance' with shape (N, K, 2, 2).\"\n            )\n        covariances_array = cast(","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/key_points/annotators.py#L281-L317","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nsv.Color.from_bgra_tuple((0, 255, 255, 0.5))  # float alpha, will raise\n\n# after\nsv.Color.from_bgra_tuple((0, 255, 255, int(round(0.5 * 255))))","handlingStrategy":"validation","validationCode":"def safe_bgra(bgra: tuple) -> tuple[int, int, int, int]:\n    \"\"\"Clamp/cast a BGRA quad (e.g. from cv2.imread BGRA pixels) for from_bgra_tuple.\"\"\"\n    return tuple(max(0, min(255, int(round(v)))) for v in bgra)  # type: ignore[return-value]","typeGuard":"def is_valid_bgra_tuple(t: tuple) -> bool:\n    \"\"\"True if t is four numbers (b, g, r, a) each within 0-255.\"\"\"\n    return len(t) == 4 and all(isinstance(v, (int, float)) and 0 <= v <= 255 for v in t)","tryCatchPattern":null,"preventionTips":["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."],"tags":["validation","color","bgra","alpha","opencv","range","valueerror"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}