-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
floodFill mask argument is missing | None part of type signature #25714
Copy link
Copy link
Closed
Description
System Information
- opencv-python-headless 4.10.0.82
- numpy 1.26.4
- mypy 1.10.0
- MacOS 14.5
- Python 3.12.2
Detailed description
The floodFill method accepts None into its mask parameter, but no overload supports this type.
Steps to reproduce
Consider this code:
import cv2
import numpy as np
image = np.zeros((100, 100), dtype=np.uint8)
image = cv2.circle(image, (50, 50), 10, (255,))
cv2.floodFill(image, None, (0, 0), (255,))Running a type checker:
$ mypy main.py
main.py:5: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[integer[Any] | floating[Any]]]", variable has type "ndarray[Any, dtype[unsignedinteger[_8Bit]]]") [assignment]
main.py:6: error: No overload variant of "floodFill" matches argument types "ndarray[Any, dtype[unsignedinteger[_8Bit]]]", "None", "tuple[int, int]", "tuple[int]" [call-overload]
main.py:6: note: Possible overload variants:
main.py:6: note: def floodFill(image: Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]], mask: Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]], seedPoint: Sequence[int], newVal: Sequence[float], loDiff: Sequence[float] = ..., upDiff: Sequence[float] = ..., flags: int = ...) -> tuple[int, Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]], Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]], Sequence[int]]
main.py:6: note: def floodFill(image: UMat, mask: UMat, seedPoint: Sequence[int], newVal: Sequence[float], loDiff: Sequence[float] = ..., upDiff: Sequence[float] = ..., flags: int = ...) -> tuple[int, UMat, UMat, Sequence[int]]
Found 2 errors in 1 file (checked 1 source file)
The generated overloads are missing mask: cv2.typing.MatLike | None annotations.
Passing None as input to the mask argument is commonly used, as shown in these articles:
You can simply replace mask1 with None in the call because you're not using it.
The floodFill from opencv asks for the image, a mask (not used = None),
Mypy configuration:
[tool.mypy]
strict = true
plugins = [
"numpy.typing.mypy_plugin",
]Related to
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