-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Closed
Description
System Information
- Python 3.12.2
- opencv-python-headless 4.11.0.86
- macOS ARM64 14.6.1
- mypy 1.14.1
- Numpy 2.2.2
Detailed description
The color parameter to cv2.line is overly strict. The parameter is marked as a Scalar value which is typed as Sequence[float]. However, for single channel images, the functions also accept a standard float.
Consider this program:
import cv2
import numpy as np
image = np.zeros((10, 10), dtype=np.uint8)
cv2.line(image, (1, 1), (8, 8), color=255)With the following Mypy configuration:
[tool.mypy]
strict = true
plugins = [
"numpy.typing.mypy_plugin",
]Running Mypy produces an error:
$ mypy main.py
main.py:5: error: No overload variant of "line" matches argument types "ndarray[tuple[int, int], dtype[unsignedinteger[_8Bit]]]", "tuple[int, int]", "tuple[int, int]", "int" [call-overload]
main.py:5: note: Possible overload variants:
main.py:5: note: def line(img: Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]], pt1: Sequence[int], pt2: Sequence[int], color: Sequence[float], thickness: int = ..., lineType: int = ..., shift: int = ...) -> Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]]
main.py:5: note: def line(img: UMat, pt1: Sequence[int], pt2: Sequence[int], color: Sequence[float], thickness: int = ..., lineType: int = ..., shift: int = ...) -> UMat
Found 1 error in 1 file (checked 1 source file)
But the program executes fine.
This same issue also affects floodFill's newVal parameter
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)
Reactions are currently unavailable