diff --git a/supervision/validators/__init__.py b/supervision/validators/__init__.py index 7b1f00eb..4d21493b 100644 --- a/supervision/validators/__init__.py +++ b/supervision/validators/__init__.py @@ -1,4 +1,4 @@ -from typing import Any, Dict +from typing import Any, Dict, Tuple import numpy as np @@ -140,11 +140,18 @@ def validate_keypoints_fields( validate_data(data, n) -def validate_resolution(resolution): +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