{"record":{"id":"87b8dad8e20ae2c7","repo":"roboflow/supervision","slug":"resize-dimensions-must-be-positive","errorCode":null,"errorMessage":"Resize dimensions must be positive","messagePattern":"Resize dimensions must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/_cv2/_image.py","lineNumber":145,"sourceCode":"        tuple(float(value) for value in means),\n    )\n\n\ndef _resize(\n    src: npt.NDArray[Any],\n    dsize: tuple[int, int] | None,\n    fx: float = 0,\n    fy: float = 0,\n    interpolation: int = _INTER_LINEAR,\n) -> npt.NDArray[Any]:\n    \"\"\"Resize with exact nearest or OpenCV-compatible linear sampling.\"\"\"\n    source_height, source_width = src.shape[:2]\n    width, height = dsize if dsize is not None else (0, 0)\n    if width == 0 or height == 0:\n        width = round(source_width * fx)\n        height = round(source_height * fy)\n    if min(width, height, source_width, source_height) <= 0:\n        raise ValueError(\"Resize dimensions must be positive\")\n\n    if interpolation == _INTER_NEAREST:\n        y_indices = np.minimum(\n            (np.arange(height) * source_height // height), source_height - 1\n        )\n        x_indices = np.minimum(\n            (np.arange(width) * source_width // width), source_width - 1\n        )\n        return np.ascontiguousarray(src[y_indices[:, np.newaxis], x_indices])\n\n    if interpolation != _INTER_LINEAR:\n        raise ValueError(f\"Unsupported interpolation mode: {interpolation}\")\n\n    if src.dtype == np.uint8 and (\n        src.ndim == 2 or (src.ndim == 3 and src.shape[2] == 3)\n    ):\n        from PIL import Image\n","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/_cv2/_image.py#L127-L163","documentation":"Thrown by the fallback resize when any computed or requested dimension is non-positive. dsize is unpacked into (width, height); if either is 0 the code derives dimensions from fx/fy scale factors, and if the final width, height, source width, or source height is <= 0 it raises. This guards the index-math used by both nearest and linear sampling.","triggerScenarios":"Calling resize with dsize=(0, 0) and fx=0 or fy=0; passing a negative width/height in dsize; or resizing an empty source image (source_width or source_height of 0).","commonSituations":"Computing dsize from user input or metadata that can be zero (e.g. an unset config value defaulting to 0), scaling a degenerate crop, or feeding an empty array produced by a failed load or an earlier slice.","solutions":["Pass an explicit positive dsize, e.g. (new_width, new_height), and stop relying on fx/fy with dsize=(0,0).","Check the source image is non-empty (src.shape[0] > 0 and src.shape[1] > 0) before resizing.","Validate computed dimensions upstream: clamp or reject width/height <= 0 at the config/API boundary."],"exampleFix":"# before\nresized = cv2.resize(frame, (0, 0), fx=scale, fy=0)  # fy typo -> height 0\n\n# after\nresized = cv2.resize(frame, (0, 0), fx=scale, fy=scale)","handlingStrategy":"validation","validationCode":"h, w = src.shape[:2]\nif h == 0 or w == 0:\n    raise ValueError('cannot resize an empty image')\nout_w, out_h = dsize if dsize and all(dsize) else (round(w * fx), round(h * fy))\nassert out_w > 0 and out_h > 0\nresized = cv2.resize(src, (out_w, out_h))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass dsize=(0,0) without positive fx and fy","Check src.shape[:2] > 0 before resizing","Validate dimension parameters at the config boundary"],"tags":["opencv-fallback","resize","input-validation","numpy"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}