roboflow/supervision · error · ValueError
addWeighted fallback only supports the default output depth;
Error message
addWeighted fallback only supports the default output depth; unsupported dtype: {dtype} What it means
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.
Source
Thrown at src/supervision/_cv2/_image.py:80
fill_value = fill.reshape((1, 1, -1))
result = np.full(shape, fill_value, dtype=image.dtype)
result[top : top + height, left : left + width] = image
return result
def _add_weighted(
src1: npt.NDArray[Any],
alpha: float,
src2: npt.NDArray[Any],
beta: float,
gamma: float,
dst: npt.NDArray[Any] | None = None,
dtype: int | None = None,
) -> npt.NDArray[Any]:
"""Blend two arrays with OpenCV-compatible saturation and optional mutation."""
if dtype is not None and dtype != -1:
raise ValueError(
"addWeighted fallback only supports the default output depth; "
f"unsupported dtype: {dtype}"
)
if src1.shape != src2.shape:
raise ValueError("addWeighted inputs must have equal shapes")
result = _cast_array_like_opencv(
src1.astype(np.float64) * alpha + src2.astype(np.float64) * beta + gamma,
src1.dtype,
)
if dst is not None:
dst[...] = result
return dst
return result
def _convert_scale_abs(
image: npt.NDArray[Any], alpha: float = 1, beta: float = 0
) -> npt.NDArray[np.uint8]:View on GitHub (pinned to 7f254d9784)
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
Example fix
// before out = cv2.addWeighted(a, 0.7, b, 0.3, 0.0, dtype=cv2.CV_32F) // after out = (a.astype(np.float64) * 0.7 + b.astype(np.float64) * 0.3).astype(np.float32)
Defensive patterns
Strategy: fallback
Validate before calling
import numpy as np
def blend_portable(a, alpha: float, b, beta: float, gamma: float = 0.0, dtype=None):
"""addWeighted without the ddepth argument; optional manual output dtype."""
out = a.astype(np.float64) * alpha + b.astype(np.float64) * beta + gamma
return out.astype(dtype) if dtype is not None else out.astype(a.dtype) Prevention
- 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
When it happens
Trigger: 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.
Common situations: Image-blending code written against real OpenCV requesting a wider output depth, run in an environment without opencv-python.
Related errors
- Unsupported color conversion code: {code}
- Only BORDER_CONSTANT is supported by the fallback
- Detection annotation for image {image_path} contains non-int
- Detections class_id must be an integer for Pascal VOC export
- Detections class_id must be an integer for YOLO export, got
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/8b653b612f512b6f.
Report an issue: GitHub.