roboflow/supervision · error · ValueError
Unsupported flip code: {flip_code}
Error message
Unsupported flip code: {flip_code} What it means
The fallback cv2.flip maps flip_code 0 to vertical, 1 to horizontal, and -1 to both axes, mirroring OpenCV's only three documented codes. Any other integer has no meaning in np.flip terms and is rejected with this ValueError instead of producing an undefined result.
Source
Thrown at src/supervision/_cv2/_image.py:30
from supervision._cv2.constants import (
_BORDER_CONSTANT,
_IMREAD_COLOR,
_IMREAD_UNCHANGED,
_INTER_LINEAR,
_INTER_NEAREST,
)
def _flip(image: npt.NDArray[Any], flip_code: int) -> npt.NDArray[Any]:
"""Flip an image vertically, horizontally, or along both axes."""
if flip_code == 0:
axes: tuple[int, ...] = (0,)
elif flip_code == 1:
axes = (1,)
elif flip_code == -1:
axes = (0, 1)
else:
raise ValueError(f"Unsupported flip code: {flip_code}")
return np.ascontiguousarray(np.flip(image, axis=axes))
def _copy_make_border(
image: npt.NDArray[Any],
top: int,
bottom: int,
left: int,
right: int,
border_type: int,
value: int | float | Sequence[int | float] = 0,
) -> npt.NDArray[Any]:
"""Add a constant border around an image."""
if border_type != _BORDER_CONSTANT:
raise ValueError("Only BORDER_CONSTANT is supported by the fallback")
if min(top, bottom, left, right) < 0:
raise ValueError("Border sizes must be non-negative")
View on GitHub (pinned to 7f254d9784)
Solutions
- Use 0 (vertical), 1 (horizontal), or -1 (both) — these are the only valid codes in OpenCV itself.
- Validate config-supplied flip values against {0, 1, -1} at load time.
Example fix
# before flipped = cv2.flip(frame, 2) # after flipped = cv2.flip(frame, -1) # flip both axes
Defensive patterns
Strategy: validation
Validate before calling
if flip_code not in (0, 1, -1):
raise ValueError(f'flip_code must be 0, 1, or -1, got {flip_code}')
flipped = cv2.flip(image, flip_code) Prevention
- Use only the three documented flip codes
- Validate config-driven flip values at load time
When it happens
Trigger: Calling cv2.flip(image, flip_code) with flip_code not in {0, 1, -1}, e.g. 2, or a bool/None coerced to an unexpected int.
Common situations: Typos (flip code 2), flip_code read from config files with wrong values, or code assuming additional codes exist. Extremely rare in practice since the three-code contract is standard.
Related errors
- Resize dimensions must be positive
- epsilon must be non-negative
- Blur kernel dimensions must be positive
- Connected-component input must be a two-dimensional image
- Only 4- and 8-connectivity are supported
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/e7ba2ce36575e1c3.
Report an issue: GitHub.