Skip to content

Commit 78e0075

Browse files
authored
Merge pull request #259 from stereolabs/r5.1.0
r5.1.0
2 parents 219d5fa + b5eda1c commit 78e0075

File tree

5 files changed

+3651
-2720
lines changed

5 files changed

+3651
-2720
lines changed

README.md

Lines changed: 142 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,48 @@
22

33
This package lets you use the ZED stereo camera in Python 3. The Python API is a wrapper around the ZED SDK which is written in C++ optimized code. We make the ZED SDK accessible from external Python code using Cython.
44

5+
## Table of Contents
6+
7+
- [Getting started](#getting-started)
8+
- [Prerequisites](#prerequisites)
9+
- [Installing the Python API](#installing-the-python-api)
10+
- [Running the install script](#running-the-install-script)
11+
- [Use the plugin](#use-the-plugin)
12+
- [Code](#code)
13+
- [Run the tutorials](#run-the-tutorials)
14+
- [Run the examples](#run-the-examples)
15+
- [GPU data retrieval using CuPy](#GPU-data-retrieval-using-CuPy)
16+
- [Validate your CuPy setup](#validate-your-CuPy-setup)
17+
- [Troubleshooting](#troubleshooting)
18+
- ["Numpy binary incompatibility"](#numpy-binary-incompatibility)
19+
- ["PyTorch on Jetson requiring NumPy 1.x while pyzed requires NumPy 2.x"](#pytorch-on-jetson-requiring-numpy-1x-while-pyzed-requires-numpy-2x)
20+
- ["CuPy failed to load libnvrtc.so.1x"](#cupy-failed-to-load-libnvrtc-so1x)
21+
- [Compiling the Python API from source (only for developers of the python wrapper)](#compiling-the-python-api-from-source-only-for-developers-of-the-python-wrapper)
22+
- [Support](#support)
23+
524
## Getting started
625

726
- First, download the latest version of the ZED SDK on [stereolabs.com](https://www.stereolabs.com/developers)
827
- For more information, read the ZED [Documentation](https://www.stereolabs.com/docs/app-development/python/install/) and [API documentation](https://www.stereolabs.com/docs/api/python/) or our [Community page](https://community.stereolabs.com)
928

1029
### Prerequisites
1130

12-
To start using the ZED SDK in Python, you will need to install the following dependencies on your system:
13-
14-
- [ZED SDK 5.0](https://www.stereolabs.com/developers/) and its dependency [CUDA](https://developer.nvidia.com/cuda-downloads)
15-
16-
For the ZED SDK 4.2 compatible version, use the [zedsdk_4.X branch](https://github.com/stereolabs/zed-python-api/tree/zedsdk_4.X) or the [4.2 release tag](https://github.com/stereolabs/zed-python-api/releases/tag/v4.2)
31+
To start using the ZED SDK in Python, you will need to install the following dependencies on your system:
1732

18-
- Python 3.8+ x64
19-
- [Cython >= 3.0.0](http://cython.org/#download)
20-
- [Numpy >= 2.0](https://numpy.org/install/)
21-
- OpenCV Python (optional)
22-
- PyOpenGL (optional)
33+
- To use pyzed
34+
- [ZED SDK 5.1](https://www.stereolabs.com/developers/) and its dependency [CUDA](https://developer.nvidia.com/cuda-downloads)
35+
- For the ZED SDK 5.0 compatible version, use the [zedsdk_5.X branch](https://github.com/stereolabs/zed-python-api/tree/zedsdk_5.X) or the [5.0.7 release tag](https://github.com/stereolabs/zed-python-api/releases/tag/v5.0.7)
36+
- For the ZED SDK 4.2 compatible version, use the [zedsdk_4.X branch](https://github.com/stereolabs/zed-python-api/tree/zedsdk_4.X) or the [4.2 release tag](https://github.com/stereolabs/zed-python-api/releases/tag/v4.2)
37+
- Python 3.8 to Python 3.14
38+
- [Cython >= 3.0.0](http://cython.org/#download)
39+
- [Numpy >= 2.0](https://numpy.org/install/)
40+
- To use most of our samples (optional)
41+
- OpenCV Python
42+
- PyOpenGL
43+
- To profit from the GPU acceleration and getting the data on the GPU (optional)
44+
- [CuPy](https://cupy.dev/)
2345

24-
Please check your python version with the following command. The result should be 3.8 or higher.
46+
Please check your python version with the following command. The result should be between 3.8 and 3.14.
2547

2648
```
2749
python --version
@@ -65,19 +87,19 @@ $ python get_python_api.py
6587
Detected platform:
6688
linux_x86_64
6789
Python 3.11
68-
ZED SDK 5.0
90+
ZED SDK 5.1
6991
# Downloads and install the whl package
70-
-> Checking if https://download.stereolabs.com/zedsdk/5.0/whl/linux_x86_64/pyzed-5.0-cp311-cp311-linux_x86_64.whl exists and is available
71-
-> Found ! Downloading python package into /home/user/pyzed-5.0-cp311-cp311-linux_x86_64.whl
92+
-> Checking if https://download.stereolabs.com/zedsdk/5.1/whl/linux_x86_64/pyzed-5.1-cp311-cp311-linux_x86_64.whl exists and is available
93+
-> Found ! Downloading python package into /home/user/pyzed-5.1-cp311-cp311-linux_x86_64.whl
7294
-> Installing necessary dependencies
7395
...
74-
Successfully installed pyzed-5.0
96+
Successfully installed pyzed-5.1
7597
```
7698
7799
To install it later or on a different environment run :
78100
79101
```bash
80-
$ python -m pip install --ignore-installed /home/user/pyzed-5.0-cp311-cp311-linux_x86_64.wh
102+
$ python -m pip install --ignore-installed /home/user/pyzed-5.1-cp311-cp311-linux_x86_64.wh
81103
```
82104
83105
That's it ! The Python API is now installed.
@@ -91,8 +113,7 @@ Import the packages in your Python terminal or file like this:
91113
import pyzed.sl as sl
92114
```
93115
94-
Vectors operations like norm, sum, square, dot, cross, distance but also simple operations can be done with
95-
Numpy package.
116+
Vectors operations like norm, sum, square, dot, cross, distance but also simple operations can be done with numpy package on CPU or CuPy package on GPU.
96117
97118
### Run the tutorials
98119
@@ -102,16 +123,95 @@ The [tutorials](https://github.com/stereolabs/zed-examples/tree/master/tutorials
102123
103124
Please refer to the [examples](https://github.com/stereolabs/zed-examples) README for more informations.
104125
126+
## GPU data retrieval using CuPy
127+
128+
`CuPy` is a NumPy/SciPy-compatible Array Library for GPU-accelerated Computing with Python (see https://cupy.dev/) and the ZED Python API support getting data in its format.
129+
130+
Calling `mat.get_data(sl.MEM_GPU, deep_copy=False)` on a `sl.Mat` object will give you a `cupy.ndarray` object.
131+
132+
### Validate your CuPy setup
133+
134+
**Prerequisites**:
135+
- A plugged camera
136+
- pyzed
137+
- [Numpy >= 2.0](https://numpy.org/install/)
138+
- [CuPy](https://cupy.dev/) (corresponding to your CUDA version)
139+
140+
You can use script the script `cupy/test_cupy_integration.py`. The script will:
141+
- Open a connected ZED camera.
142+
- Retrieve an image.
143+
- Run some operations and benchmark on the retrieved image.
144+
- Display on the terminal the results of the tests.
145+
146+
Without deep-diving into the script content, you can just look at what it prints to validate everything is fine with your setup.
147+
148+
For example, on an Orin NX16 with a ZED X
149+
150+
```
151+
> python test_cupy_integration.py
152+
✅ CuPy detected - GPU acceleration available
153+
CuPy version: 13.5.1
154+
CUDA version: 12080
155+
ZED SDK CuPy Integration Test
156+
========================================
157+
Opening ZED camera...
158+
[2025-07-31 12:54:15 UTC][ZED][INFO] Logging level INFO
159+
[2025-07-31 12:54:16 UTC][ZED][INFO] Using GMSL input... Switched to default resolution HD1200
160+
[2025-07-31 12:54:19 UTC][ZED][INFO] [Init] Camera FW version: 2001
161+
[2025-07-31 12:54:19 UTC][ZED][INFO] [Init] Video mode: HD1200@30
162+
[2025-07-31 12:54:19 UTC][ZED][INFO] [Init] Serial Number: S/N 48922857
163+
[2025-07-31 12:54:19 UTC][ZED][INFO] [Init] Depth mode: NEURAL
164+
ZED camera opened successfully.
165+
Retrieving image data...
166+
Retrieved image on GPU: 1920x1200
167+
168+
🧪 Testing GPU image processing (basic grayscale conversion)...
169+
Input image: (1200, 1920, 4)
170+
Processed image: (1200, 1920)
171+
✅ GPU processing test passed!
172+
========================================
173+
174+
💾 Testing memory allocation strategies...
175+
CPU allocation: (480, 640, 4), float32
176+
GPU allocation: (480, 640, 4), float32
177+
CPU->GPU transfer: (480, 640, 4)
178+
GPU->CPU transfer: (480, 640, 4)
179+
✅ Memory allocation test passed!
180+
========================================
181+
182+
🔍 Testing GPU memory usage...
183+
Initial GPU memory usage: 0.0 MB
184+
After allocation: 15.3 MB
185+
After cleanup: 0.0 MB
186+
✅ GPU memory test passed!
187+
========================================
188+
189+
🔬 Testing data integrity...
190+
Data integrity verified: (2, 2, 4)
191+
✅ Data integrity test passed!
192+
========================================
193+
194+
⚡ Running performance benchmark...
195+
Benchmark image size: 1920x1200
196+
CPU processing (10 iterations): 538.658 milliseconds
197+
GPU processing (10 iterations): 93.961 milliseconds
198+
Speedup: 5.7x
199+
🚀 GPU processing is faster!
200+
========================================
201+
202+
🎉 All tests completed!
203+
Your system is ready for GPU-accelerated ZED processing with the Python API!
204+
```
105205
106206
## Troubleshooting
107207
108-
### "Numpy binary incompatiblity"
208+
### "Numpy binary incompatibility"
109209
110210
```
111211
Traceback (most recent call last):
112212
...
113213
File "__init__.pxd", line 918, in init pyzed.sl
114-
ValueError: numpy.ufunc size changed, may indicate binary incompatiblity. Expected 216 from C header, got 192 from PyObject
214+
ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject
115215
```
116216
117217
This error usually means numpy isn't installed. To install it, simply run these commands :
@@ -122,6 +222,28 @@ python3 -m pip install cython
122222
python3 -m pip install numpy
123223
```
124224
225+
### "PyTorch on Jetson requiring NumPy 1.x while pyzed requires NumPy 2.x"
226+
227+
By default, PyTorch on Jetson requires NumPy 1.x (see NVidia's doc [Install PyTorch on Jetson Platform](https://docs.nvidia.com/deeplearning/frameworks/install-pytorch-jetson-platform/index.html)). Since pyzed requires NumPy 2.x, it can lead to:
228+
229+
```
230+
A module that was compiled using NumPy 1.x cannot be run in
231+
NumPy 2.2.6 as it may crash. To support both 1.x and 2.x
232+
versions of NumPy, modules must be compiled with NumPy 2.0.
233+
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
234+
235+
If you are a user of the module, the easiest solution will be to
236+
downgrade to 'numpy<2' or try to upgrade the affected module.
237+
We expect that some modules will need time to support NumPy 2.
238+
```
239+
240+
To fix this, until NVidia releases its wheels for PyTorch on Jetson with NumPy 2.x, you can either:
241+
- compile PyTorch from source with NumPy 2.x: see [this post](https://forums.developer.nvidia.com/t/pytorch-environment-and-zed-sdk-conflicts-on-jetpack-6-2/334056/5) for more information.
242+
- compile pyzed from source with NumPy 1.x: see [zed-python-api/src](https://github.com/stereolabs/zed-python-api/tree/master/src) for more information.
243+
244+
### "CuPy failed to load libnvrtc.so.1x"
245+
246+
If an __error__ like `CuPy failed to load libnvrtc.so.12` happens when using GPU retrieval, it indicates a mismatch between the installed CuPy version (e.g. cupy-cuda11x) and the CUDA runtime libraries (e.g. 12.x)
125247
126248
## Compiling the Python API from source (only for developers of the python wrapper)
127249

0 commit comments

Comments
 (0)