Skip to content
Jul 3, 2015.

Using the ZED Stereo Camera with MATLAB

This tutorial will explain how to use the ZED 3D camera with MATLAB.

Note: This is for ZED SDK 1.2 only. Please see the latest MATLAB guide here.


This tutorial will explain how to use the ZED 3D camera with MATLAB. You will learn how to capture images from the ZED and adjust camera parameters in MATLAB. Note that viewing and manipulating depth map data is not covered in this tutorial.

NOTE : when using directly the ZED camera (as a webcam), the images are not rectified.

For capturing rectified images and depth maps in MATLAB with the ZED, please refer to “How to use the ZED SDK with MATLAB".


You must have a MathWorks account (free) and MATLAB installed on your system. Of course, the ZED SDK has to be installed as well. Even if you’re new to MATLAB, this tutorial should be easy to follow.

Getting Started

Open MATLAB and in the Command Window, enter this command:

>> webcamlist

You should encounter an error if you’ve never used MATLAB with a webcam before:

Error using webcamlist (line 20). MATLAB Support Package for Webcams has not been installed. Open Support Package Installer to install the Webcam Support Package.

If you’ve encountered the error, click the link in the error log. A dialog window appears:

Click Next > and Log In. MATLAB will ask for your MathWorks account credential. Log in.

Then, read and accept the MathWorks auxiliary software license agreement. Click Next > and Install. This might take a while (around 10-15 seconds).

When the setup process is finished, uncheck the “Show support package examples” check box and click on Finish.

Now, in the MATLAB Command Window, re-enter:

>> webcamlist

and that should give you:

ans ='ZED'

Perfect! The ZED camera is properly detected. 🙂

Now grab an instance of the ZED camera with the following command line:

>> cam = webcam

and the cam variable will return the current parameters of the camera:

cam =

webcam with properties:

Name: 'ZED'
Resolution: '2560x720'
AvailableResolutions: {1x4 cell}
WhiteBalanceMode: 'auto'
Sharpness: 4
Saturation: 5
Hue: 0
Gain: 4
WhiteBalance: 4600
Contrast: 4
Brightness: 4
Exposure: 2
ExposureMode: 'auto'

Note that you can check whether the ZED camera works properly by using this command:

>> preview(cam)

You can now grab ZED frames with:

>> img = snapshot(cam);

You’ve just grabbed your first ZED frame in MATLAB. If you need real-time video capture, set up a loop. Fairly straightforward, isn’t it ? 😛

The ZED Camera will stay active as long as you keep the cam variable in MATLAB’s environment. To turn off the ZED camera, use this command:

>> clear cam

Here is a snippet that demonstrate how to open the ZED , grab the side by side images and split them:

clear all;close all;clc;

% get access to the ZED camera
zed = webcam('ZED')
% set the desired resolution
zed.Resolution = zed.AvailableResolutions{1};
% get the image size
[height width channels] = size(snapshot(zed))

% Create Figure and wait for keyboard interruption to quit
f = figure('keypressfcn','close','windowstyle','modal');
ok = 1;
% loop over frames
while ok
    %capture the current image
    img = snapshot(zed);

    % split the side by side image image into two images
    im_Left = img(:, 1 : width/2, :);
    im_Right = img(:, width/2 +1: width, :);

    % display the left and right images
    title('Image Left');
    title('Image Right');

    drawnow; %this checks for interrupts
    ok = ishandle(f); %does the figure still exist

% close the camera instance
clear cam