Tutorial - Retrieve Tensor
Tutorial - Retrieve Tensor
This tutorial shows how to use Camera::retrieveTensor() to get a pre-processed image tensor directly from the ZED camera — resized, normalized and laid out in NCHW format — ready to feed into a deep learning inference pipeline without writing custom pre-processing code.
Getting Started
- First, download the latest version of the ZED SDK.
- Download the Retrieve Tensor sample code in C++.
Code Overview
Open the camera
As in previous tutorials, we create, configure and open the ZED. Depth is not needed for this tutorial, so we set DEPTH_MODE::NONE.
Configure the tensor parameters
TensorParameters describes the output format expected by your inference pipeline: target resolution, batch size, memory layout (NCHW/NHWC), pixel type, color format, and the normalization to apply (scale, mean, std). Here we target a 501x501 RGB float tensor on GPU memory, scaled to [0, 1] with no additional mean/std normalization.
For the full list of available options, see the TensorParameters API documentation.
Retrieve the tensor
On each grab(), retrieveTensor() fills the Tensor object with the pre-processed image data, ready for inference. The sample captures 50 frames and prints the tensor dimensions every 10 frames.
The full sample also includes a helper function that downloads the tensor from GPU to CPU and reverses the normalization to save it back as a PNG image, which is a convenient way to visually check your pre-processing pipeline. See the source code for the full implementation.

