roboflow/supervision · error · ValueError
Both dimensions in resolution must be positive. Got ({w}, {h
Error message
Both dimensions in resolution must be positive. Got ({w}, {h}). What it means
Raised by supervision.validators._validate_resolution when both elements are ints but one is zero or negative. Pixel dimensions must be strictly positive; zero/negative resolution would make any downstream canvas or geometry math invalid.
Source
Thrown at src/supervision/validators/__init__.py:351
def _validate_resolution(resolution: Any) -> tuple[int, int]:
if not (isinstance(resolution, tuple) and len(resolution) == 2):
raise ValueError(
f"""
resolution must be a tuple of two integers, got
{type(resolution)} with value {resolution}
"""
)
w, h = resolution
if not (isinstance(w, int) and isinstance(h, int)):
raise ValueError(
f"""
Both elements in resolution must be integers.
Got types ({type(w)}, {type(h)})
"""
)
if w <= 0 or h <= 0:
raise ValueError(
f"Both dimensions in resolution must be positive. Got ({w}, {h})."
)
return w, h
@deprecated( # type: ignore[untyped-decorator]
target=_validate_resolution,
deprecated_in="0.29.0",
remove_in="0.32.0",
)
def validate_resolution(resolution: Any) -> tuple[int, int]:
return void(resolution) # type: ignore[no-any-return]
View on GitHub (pinned to 7f254d9784)
Solutions
- Guard computed dimensions: resolution=(max(1, w), max(1, h)).
- Check your scale factor is > 0 before applying it.
- Log/inspect frame dimensions before constructing resolution-dependent objects if streams may be malformed.
Example fix
# before resolution = (int(w * scale), int(h * scale)) # scale == 0.0 -> (0, 0) # after assert scale > 0 resolution = (max(1, int(w * scale)), max(1, int(h * scale)))
Defensive patterns
Strategy: validation
Validate before calling
w, h = int(resolution[0]), int(resolution[1])
if w <= 0 or h <= 0:
raise ValueError(f"resolution must be positive, got ({w}, {h})")
obj = SomeAPI(resolution=(w, h)) Type guard
def is_positive_resolution(resolution: tuple[int, int]) -> bool:
return resolution[0] > 0 and resolution[1] > 0 Prevention
- Clamp computed dimensions with max(1, value).
- Assert scale factors are > 0 before applying them to dimensions.
- Reject unreadable/zero-size frames before deriving resolution.
When it happens
Trigger: Passing resolution=(0, 1080), resolution=(-1920, 1080), or a resolution computed as w - margin where margin >= w.
Common situations: Arithmetic underflow when downscaling (int(w * 0) from a bad scale factor); passing through a zero-dimension video stream or an unreadable frame; sign errors from signed offsets.
Related errors
- resolution must be a tuple of two integers, got
- Both elements in resolution must be integers.
- prefetch must be >= 0, got {prefetch}
- `slice_wh` must be an int or a tuple of two positive integer
- `overlap_wh` must be an int or a tuple of two non negative i
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/edb4379188e3fe8b.
Report an issue: GitHub.