Main Content

preview

Preview of live video data

Description

preview(obj) creates a Video Preview window that displays live video data for video input object obj. The window also displays the timestamp and video resolution of each frame, the current frame rate, and the current status of obj. The Video Preview window displays the video data at 100% magnification. The size of the preview image is determined by the value of the video input object ROIPosition property.

Components of a Video Preview Window

The Video Preview window remains active until it is either stopped using stoppreview or closed using closepreview. If you delete the object, by calling delete(obj), the Video Preview window stops previewing and closes automatically.

preview(himage,himage) displays live video data for video input object obj in the image object specified by the handle himage. preview scales the image data to fill the entire area of the image object but does not modify the values of any image object properties. Use this syntax to preview video data in a custom GUI of your own design. For more information on customized GUIs, see Previewing Data in Custom GUIs.

hpreview = preview(...) returns hpreview, a handle to the image object containing the previewed data.

example

Examples

collapse all

This example shows you how to preview image from video input, close preview window and stop previewing.

Create a customized GUI.

figure("Name","My Custom Preview Window"); 
uicontrol("String","Close","Callback","close(gcf)"); 

To check the available adaptors on your system first, use the imaqhwinfo function.

imaqhwinfo
ans = struct with fields:
    InstalledAdaptors: {'demo'  'gentl'  'gige'  'kinect'  'matrox'  'winvideo'}
        MATLABVersion: '25.1 (R2025a)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '25.1 (R2025a)'

Check the supported format for the adaptor of interest.

info = imaqhwinfo("winvideo");
info.DeviceInfo(2).SupportedFormats
ans = 1×19 cell
    {'RGB24_1024x576'}    {'RGB24_1280x720'}    {'RGB24_1600x896'}    {'RGB24_160x120'}    {'RGB24_160x88'}    {'RGB24_176x144'}    {'RGB24_1920x1080'}    {'RGB24_2304x1296'}    {'RGB24_2304x1536'}    {'RGB24_320x176'}    {'RGB24_320x240'}    {'RGB24_352x288'}    {'RGB24_432x240'}    {'RGB24_640x360'}    {'RGB24_640x480'}    {'RGB24_800x448'}    {'RGB24_800x600'}    {'RGB24_864x480'}    {'RGB24_960x720'}

Create a video object using the videoinput function. Configure the adaptorname, deviceid, and format to correspond with your device's adaptor setting.

obj = videoinput("winvideo",2,"RGB24_800X600");
vidRes = obj.VideoResolution; 
nBands = obj.NumberOfBands; 
hImage = image(zeros(vidRes(2),vidRes(1),nBands) ); 
im = preview(obj, hImage); 

Figure My Custom Preview Window contains an axes object and another object of type uicontrol. The hidden axes object contains an object of type image.

Stop the preview and close the live image preview window after 10 seconds.

pause(10);
stoppreview(obj)
closepreview(obj)

Input Arguments

collapse all

Video input object, specified as a videoinput object or an imaq.VideoDevice System object™.

Image object to display preview data, specified as an image object handle.

Output Arguments

collapse all

Image object containing the previewed data, returned as an image object handle. To obtain a handle to the figure window containing the image object, use the ancestor function. For more information about using image objects, see image. For more information about the image object returned, see Custom Update Function.

More About

collapse all

Version History

Introduced before R2006a