Comments (4)
- The
borderValue
argument tocv2.erode
is annotated ascv2.typing.Scalar
, which is defined asSequence[float]
. However, the code also works with passing a singleint
. Would it make sense to defineScalar = float | Sequence[float]
? The same applies tocolor
argument to thecv2.circle
, and probably others. cv2.filter2D
should also have at least slightly more specific type annotations.
The list of functions is quite arbitrary, I have only listed what is reported in our current code base.
Does the OpenCV Python API actually support arrays that contain np.generic
but not np.number
? These could be Booleans or any opaque data that does not allow arithmetic.
For functions that only support integer and floating point numbers (but not complex floats), np.ndarray[Any, np.dtype[np.integer | np.floating]]
could be a better choice than np.ndarray[Any, np.dtype[np.number]]
. The latter includes complex numbers, which do not support %
.
from opencv.
We get tons of new Mypy errors on OpenCV 4.9 on the following functions:
transform
bitwise_and
approxPolyDP
connectedComponents
putText
rectangle
- etc.
Of the form:
error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[generic]]", variable has type "ndarray[Any, dtype[signedinteger[_64Bit]]]") [assignment]
Variables passed into these functions are type annotated like:
input: NDArray[np.int_] = ...
Environment
- opencv-python-headless 4.9.0.80
- mypy 1.8.0
- Pythom 3.10
[tool.mypy]
ignore_missing_imports = true
strict = true
disallow_subclassing_any = false
plugins = [
"pydantic.mypy",
"numpy.typing.mypy_plugin",
]
from opencv.
Right, for these types of issues, functions that preserve the input array shape and data type would need to use a TypeVar
rather than independent cv2.typing.MatLike
. An example of the to-be-generated code would look like this:
NumPyArrayNumeric = np.ndarray[Any, np.dtype[np.number]]
ArrayT = TypeVar("ArrayT", bound=NumPyArrayNumeric)
def erode(
src: ArrayT,
kernel: cv2.typing.MatLike,
dst: ArrayT | None = ...,
anchor: cv2.typing.Point = ...,
iterations: int = ...,
borderType: int = ...,
borderValue: cv2.typing.Scalar = ...,
) -> ArrayT:
...
Whether the type of src
is preserved depends on the individual function, though. For functions like cv2.filter2D
, the ddepth
argument can only be properly accounted for using overloads (if that level of typing is desired at all). Ideally, this kind of information would be encoded in the C++ documentation comments, but I don't know how to best do this with doxygen.
from opencv.
@VadimLevin Could you take a look on this?
from opencv.
Related Issues (20)
- Extend HAL with ThresholdOtsu function
- HOG in OpenCL mode slower than it should be because internally it uses CPU resize with INTER_LINEAR_EXACT
- imgproc: doc: emoji doesn't work at section command (doxygen limitation) HOT 1
- There was an error in the code comment HOT 1
- Inpainting floating point values with Telea's algorithm gives unexpected results. HOT 4
- [doc] use 1D (row-only or column only) filter HOT 1
- vcpkg support for version 4.9.0 HOT 1
- OpenCV-Python Bindings, vector<>, Matx<> conversion
- calibrateHandEye does not work when inputting CV_32F Rodriguess matrices
- Add CORP header to opencv.js HOT 2
- DNN: CUDA backend requires cuDNN. Please resolve dependency or disable OPENCV_DNN_CUDA=OFF HOT 1
- Can't get useful results with segmentation sample. HOT 1
- OpenCL code for BFMatcher throws with w Intel Iris, works w NVidia A2000 HOT 2
- Cannot read a tensorflow model
- Cannot compile opencv5 sample on windows
- How can i use the PlaneWarperGpu?
- ENABLE_NEON=OFF is not disabling the baseline in armv7l HOT 3
- Build with MPS? HOT 4
- Add acuracy test for box filter with and without normalization
- cv::rotate is not covered by performance and accuracy tests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencv.