-
-
Notifications
You must be signed in to change notification settings - Fork 56.6k
Closed
Milestone
Description
System Information
- OpenCV Python version: 4.12.0.88
- MacOS: 15.5
- Python version: 3.13.1
Detailed description
The calib3d docs mention distCoeffs and R can be "NULL/empty" many times (the function will use all zeros or the identity matrix instead).
distCoeffs Input vector of distortion coefficients
\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$
of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.
In Python, the idiomatic equivalent is None, which is indeed allowed by the implementation but not by the type stubs. I wonder if this is more leaking a C++ implementation detail vs intended use, but being able to use None to defer to OpenCV's default is useful.
Steps to reproduce
import cv2
import numpy as np
img = np.zeros((100, 100), dtype=np.uint8)
cv2.undistort(img, np.eye(3), None)$ python3 repro.py
$ mypy repro.py
repro.py:5: error: No overload variant of "undistort" matches argument types "ndarray[tuple[int, int], dtype[unsignedinteger[_8Bit]]]", "ndarray[tuple[Any, ...], dtype[float64]]", "None" [call-overload]
repro.py:5: note: Possible overload variants:
repro.py:5: note: def undistort(src: Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]], cameraMatrix: Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]], distCoeffs: Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]], dst: Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]] | None = ..., newCameraMatrix: Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]] | None = ...) -> Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]]
repro.py:5: note: def undistort(src: UMat, cameraMatrix: UMat, distCoeffs: UMat, dst: UMat | None = ..., newCameraMatrix: UMat | None = ...) -> UMatIssue 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