Video Acquisition and Viewing

This documentation shows how to acquire and view video from a USB Camera or a file when running a MATLAB Function or Simulink Model directly on a desktop computer.

Contents

Acquiring Video

Setup:

To acquire video from a usb camera, you first need to setup the driver for the usb camera. This only needs to be done once. To do so type the following at the MATLAB Command Window:

>> supportPackageInstaller

If you are using a generic video camera for a Windows, Linux or Mac computer, you will need to select the "OS Generic Device" driver and install. For the purpose of this demo, we will use this support package.

If you do not have a generic video device (i.e. DCAM, GigE, Point Grey, etc...), see the following documentation to determine which support package to install:

Image Acquisition Support Packages for Hardware Adaptors

MATLAB:

To import video from a usb camera, use the imaq.VideoDevice system object:

videoReaderObject = imaq.VideoDevice('winvideo');
videoReaderObject.VideoFormat = 'MJPG_640x480';
videoReaderObject.ReturnedDataType = 'uint8';

To import video from a video file i.e. AVI OR MPEG, use the vision.VideoFileReader system object:

videoReaderObject = vision.VideoFileReader('visionface.avi');
videoReaderObject.VideoOutputDataType = 'uint8';

To extract each frame, the process is the same for both methods:

frame = step(videoReaderObject);

Simulink:

To import video from a usb camera, use the From Video Device block:

To import video from a video file i.e. AVI OR MPEG, use the From Multimedia File block:

Visualizing Video

To visualize video, use the following functions and blocks:

Other Options:

MATLAB Example

Here is an example in MATLAB that shows how to acquire and visualize video. An if-else statement is used to allow the user to switch between using the camera or file for the video source:

Open Example

Simulink Example

Here is an example in Simulink that shows how to acquire and visualize video. A Manual Switch block is used to switch the video source from a usb camera to a video file. Double click on the "Manual Switch" block to switch the video source.

Open Example