{"record":{"id":"8b653b612f512b6f","repo":"roboflow/supervision","slug":"addweighted-fallback-only-supports-the-default-out","errorCode":null,"errorMessage":"addWeighted fallback only supports the default output depth; unsupported dtype: {dtype}","messagePattern":"addWeighted fallback only supports the default output depth; unsupported dtype: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/_cv2/_image.py","lineNumber":80,"sourceCode":"        fill_value = fill.reshape((1, 1, -1))\n\n    result = np.full(shape, fill_value, dtype=image.dtype)\n    result[top : top + height, left : left + width] = image\n    return result\n\n\ndef _add_weighted(\n    src1: npt.NDArray[Any],\n    alpha: float,\n    src2: npt.NDArray[Any],\n    beta: float,\n    gamma: float,\n    dst: npt.NDArray[Any] | None = None,\n    dtype: int | None = None,\n) -> npt.NDArray[Any]:\n    \"\"\"Blend two arrays with OpenCV-compatible saturation and optional mutation.\"\"\"\n    if dtype is not None and dtype != -1:\n        raise ValueError(\n            \"addWeighted fallback only supports the default output depth; \"\n            f\"unsupported dtype: {dtype}\"\n        )\n    if src1.shape != src2.shape:\n        raise ValueError(\"addWeighted inputs must have equal shapes\")\n    result = _cast_array_like_opencv(\n        src1.astype(np.float64) * alpha + src2.astype(np.float64) * beta + gamma,\n        src1.dtype,\n    )\n    if dst is not None:\n        dst[...] = result\n        return dst\n    return result\n\n\ndef _convert_scale_abs(\n    image: npt.NDArray[Any], alpha: float = 1, beta: float = 0\n) -> npt.NDArray[np.uint8]:","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/_cv2/_image.py#L62-L98","documentation":"OpenCV's `addWeighted` accepts a `dtype` (ddepth) argument to control the output type. The fallback at src/supervision/_cv2/_image.py:80 only supports the default behavior (output dtype = src1's dtype, i.e. CV_16F/CV_32F promotion aside, it casts back like the source), so any explicit dtype other than the sentinel -1 raises.","triggerScenarios":"Calling `cv2.addWeighted(a, alpha, b, beta, gamma, dtype=cv2.CV_16U)` (or CV_32F etc.) on the fallback backend — typical in HDR-style blending or when a higher-precision accumulator is wanted to avoid saturation.","commonSituations":"Image-blending code written against real OpenCV requesting a wider output depth, run in an environment without opencv-python.","solutions":["Drop the `dtype` argument and let the output inherit src1's dtype","Do the blend manually at the desired precision: `(a.astype(np.float64)*alpha + b.astype(np.float64)*beta + gamma).astype(np.float32)`","Install `opencv-python` if ddepth control is required"],"exampleFix":"// before\nout = cv2.addWeighted(a, 0.7, b, 0.3, 0.0, dtype=cv2.CV_32F)\n\n// after\nout = (a.astype(np.float64) * 0.7 + b.astype(np.float64) * 0.3).astype(np.float32)","handlingStrategy":"fallback","validationCode":"import numpy as np\n\ndef blend_portable(a, alpha: float, b, beta: float, gamma: float = 0.0, dtype=None):\n    \"\"\"addWeighted without the ddepth argument; optional manual output dtype.\"\"\"\n    out = a.astype(np.float64) * alpha + b.astype(np.float64) * beta + gamma\n    return out.astype(dtype) if dtype is not None else out.astype(a.dtype)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit the dtype/ddepth argument when calling cv2.addWeighted through supervision's backend","For a specific output precision, do the weighted sum in numpy and astype explicitly"],"tags":["cv2-fallback","blending","dtype","unsupported-operation"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}