vid5

Create custom video preview

Instead of using the toolbox's Video Preview window, you can use the preview function to direct the live video stream to any Handle Graphics image object. In this way, you can incorporate the toolbox's previewing capability in a GUI of your own creation.

To use this capability, create an image object and then call the preview function, specifying a handle to the image object as an argument. The preview function outputs the live video stream to the image object you specify.

The following example creates a figure window and then creates an image object in the figure, the same size as the video frames. The example then calls the preview function, specifying a handle to the image object.

% Create a video input object.
vid = videoinput('winvideo',1,'YUY2_640x480');
set(vid,'ReturnedColorSpace','rgb');
% Create a figure window. This example turns off the default
% toolbar, menubar, and figure numbering.

figure('Toolbar','none',...
       'Menubar', 'none',...
       'NumberTitle','Off',...
       'Name','My Preview Window');

% Create the image object in which you want to display
% the video preview data. Make the size of the image
% object match the dimensions of the video frames.

vidRes = get(vid, 'VideoResolution');
nBands = get(vid, 'NumberOfBands');
hImage = image( zeros(vidRes(2), vidRes(1), nBands) );

% Display the video data in your GUI.

preview(vid, hImage);
pause(5);