New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Numpy 2.0 support in Python bindings #25455
Comments
I've checked builds with recent NumPy versions on Ubuntu 22, it seems that with 2.x everything just works 🙂 See my experimental repository: https://github.com/mshabunin/opencv-numpy-check The only modification I made was in Python tests - NumPy 2.x doesn't support diff --git a/modules/python/test/test_misc.py b/modules/python/test/test_misc.py
index bcd3152699..08ab04d53d 100644
--- a/modules/python/test/test_misc.py
+++ b/modules/python/test/test_misc.py
@@ -451,7 +451,7 @@ class Arguments(NewOpenCVTests):
try_to_convert = partial(self._try_to_convert, cv.utils.dumpFloat)
min_float, max_float = get_limits(ctypes.c_float)
for convertible in (2, -13, 1.24, np.float32(32.45), float(32), np.double(12.23),
- np.float32(-12.3), np.float64(3.22), np.float_(-1.5), min_float,
+ np.float32(-12.3), np.float64(3.22), min_float,
max_float, np.inf, -np.inf, float('Inf'), -float('Inf'),
np.double(np.inf), np.double(-np.inf), np.double(float('Inf')),
np.double(-float('Inf'))):
@@ -495,7 +495,7 @@ class Arguments(NewOpenCVTests):
min_float, max_float = get_limits(ctypes.c_float)
min_double, max_double = get_limits(ctypes.c_double)
for convertible in (2, -13, 1.24, np.float32(32.45), float(2), np.double(12.23),
- np.float32(-12.3), np.float64(3.22), np.float_(-1.5), min_float,
+ np.float32(-12.3), np.float64(3.22), min_float,
max_float, min_double, max_double, np.inf, -np.inf, float('Inf'),
-float('Inf'), np.double(np.inf), np.double(-np.inf),
np.double(float('Inf')), np.double(-float('Inf'))): OpenCV built with NumPy 2.x works with NumPy 1.x (not vice versa). I haven't checked NumPy versions older than 1.21.5 though. See https://github.com/mshabunin/opencv-numpy-check/blob/d2e5f9b4ccd7c689263b5992c5036b60a2c716b6/run.sh#L44-L48 |
@what about backward compatibility with 1.x? D we need extra opencv-python packages for it? |
Theoretically builds with 2.x should work with 1.x too, our python tests pass with this configuration and this is what NumPy developers recommend (run OpenCV built with 1.x in environment with NumPy 2.x):
I think that we should:
|
Created #25541 with test fixes for 2.0 |
Describe the feature and motivation
Note that numpy 2.0.0rc1 is now publicly available: numpy/numpy#24300 (comment)
Additional context
No response
The text was updated successfully, but these errors were encountered: