Preview of live video data
preview(obj)
preview(obj,himage)
himage = preview(...)
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(obj,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 (see Examples).
himage = preview(...)
returns himage
,
a handle to the image object containing the previewed data. 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
.
See the Custom Update Function section for more information about
the image object returned.
The behavior of the Video Preview window depends on the video input object's current state and trigger configuration.
Object State | Preview Window Behavior |
---|---|
| Displays a live view of the image being acquired from
the device, for all trigger types. The image is updated to reflect
changes made to configurations of object properties. (The |
| If If |
| Video Preview window might drop some data frames, but this will not affect the frames logged to memory or disk. |
Note
The Image Acquisition Toolbox™ Preview
window and the Preview window that is built into the Image Acquisition
Tool support the display of up to 16-bit image data. The Preview window
was designed to only show 8-bit data, but many cameras return 10-,
12-, 14-, or 16-bit data. The Preview window display supports these
higher bit-depth cameras. However, larger bit data is scaled to 8-bit
for the purpose of displaying previewed data. If you need the full
resolution of the data, use the getsnapshot
or getdata
functions.
preview
creates application-defined data
for the image object, himage
, assigning it the
name 'UpdatePreviewWindowFcn'
and setting its value
to an empty array ([]
). You can configure the value
of the 'UpdatePreviewWindowFcn'
application data
and retrieve its value using the MATLAB® setappdata
and getappdata
functions,
respectively.
The 'UpdatePreviewWindowFcn'
will not necessarily
be called for every frame that is acquired. If a new frame is acquired
and the 'UpdatePreviewWindowFcn'
for the previous
frame has not yet finished executing, no update will be generated
for the new frame. If you need to execute a function for every acquired
frame, use the FramesAcquiredFcn
instead.
You can use this function to define custom processing of the
previewed image data. When preview
invokes the
function handle you specify, it passes three arguments to your function:
obj
— The video input object
being previewed
event
— An event structure
containing image frame information. For more information, see below.
himage
— A handle to the
image object that is being updated
The event structure contains the following fields:
Field | Description |
---|---|
| Current image frame specified as an H-by-W-by-B matrix
where H and W are the image height and width, respectively, as specified
in the |
| Character vector specifying current image width and height,
as defined by the |
| Character vector describing the current acquisition status of the video input object. |
| Character vector specifying the timestamp associated with the current image frame. |
| Character vector specifying the current frame rate of the video input object in frames per second. |
Create a customized GUI.
figure('Name', 'My Custom Preview Window'); uicontrol('String', 'Close', 'Callback', 'close(gcf)');
Create an image object for previewing.
vidRes = obj.VideoResolution; nBands = obj.NumberOfBands; hImage = image( zeros(vidRes(2), vidRes(1), nBands) ); preview(obj, hImage);
For more information on customized GUIs, see Previewing Data in Custom GUIs.
ancestor
| closepreview
| image
| imaqhelp
| stoppreview