Documentation

imaq.VideoDevice

Acquire one frame at a time from video device

Syntax

obj = imaq.VideoDevice
obj = imaq.VideoDevice(adaptorname)
obj = imaq.VideoDevice(adaptorname, deviceid)
obj = imaq.VideoDevice(adaptorname, deviceid, format)
obj = imaq.VideoDevice(adaptorname, deviceid, format, P1, V1, ...)
frame = step(obj)
[frame metadata] = step(obj)

Description

The VideoDevice System object allows single-frame image acquisition and code generation from MATLAB®. You use theimaq.VideoDevicefunction to create the System object. It supports the same adaptors and hardware that thevideoinputobject supports; however, it has different functions and properties associated with it. For example, the System object uses thestepfunction to acquire single frames.

obj = imaq.VideoDevicecreates a VideoDevice System object,obj, that acquires images from a specified image acquisition device. When you specify no parameters, by default, it selects the first available device for the first adaptor returned byimaqhwinfo.

obj = imaq.VideoDevice(adaptorname)creates a VideoDevice System object,obj, using the first device of the specifiedadaptorname.adaptornameis a character vector that specifies the name of the adaptor used to communicate with the device. Use theimaqhwinfofunction to determine the adaptors available on your system.

obj = imaq.VideoDevice(adaptorname, deviceid)creates a VideoDevice System object,obj, with the default format for specifiedadaptornameanddeviceid.deviceidis a numeric scalar value that identifies a particular device available through the specifiedadaptorname. Use theimaqhwinfo(adaptorname)syntax to determine the devices available and corresponding values fordeviceid.

obj = imaq.VideoDevice(adaptorname, deviceid, format)creates a VideoDevice System object,obj, whereformatis a character vector that specifies a particular video format supported by the device or a device configuration file (also known as a camera file).

obj = imaq.VideoDevice(adaptorname, deviceid, format, P1, V1, ...)Creates a VideoDevice System object,obj, with the specified property values. If an invalid property name or property value is specified, the object is not created.

Specifying properties at the time of object creation is optional. They can also be specified after the object is created. See the table below for a list of applicable properties.

frame = step(obj)acquires a single frame from the VideoDevice System object,obj.

[frame metadata] = step(obj)acquires a single image frame from the VideoDevice System object,obj, plus metadata from the Kinect®for Windows®Depth sensor. You can return Kinect for Windows skeleton data using the VideoDevice System object on the Kinect Depth sensor. For information on how to do this, seeKinect for Windows Metadata.

Properties

You can specify properties at the time of object creation, or they can be specified and changed after the object is created. Properties that can be used with the VideoDevice System object include:

Property Description
Device Device from which to acquire images.

Specify the image acquisition device to use to acquire a frame. It consists of the device name, adaptor, and device ID. The default device is the first device returned byimaqhwinfo.

VideoFormat Video format to be used by the image acquisition device.

Specify the video format to use while acquiring the frame. The default value ofVideoFormatis the default format returned byimaqhwinfofor the selected device. To specify a Video Format using a device file, set theVideoFormatproperty to'From device file'This option exists only if your device supports device configuration files.

DeviceFile Name of file specifying video format. This property is only visible whenVideoFormatis set to'From device file'.
DeviceProperties Object containing properties specific to the image acquisition device.
ROI 的收购。这是设置为the default ROI value for the specified device, which is the maximum resolution possible for the specified format. You can change the value to change the size of the captured image. The format is 1-based, that is, it is specified in pixels in a 1-by-4 element vector[x y width height].

Note that this differs from thevideoinputobject, the Image Acquisition Tool, and the From Video Device block, all of which are 0-based.

HardwareTriggering Turn hardware triggering on/off. Set this property to'on'to enable hardware triggering to acquire images. The property is visible only when the device supports hardware triggering.
TriggerConfiguration Specifies the trigger source and trigger condition before acquisition. The triggering condition must be met via the trigger source before a frame is acquired. This property is visible only whenHardwareTriggeringis set to'on'.
ReturnedColorSpace Specify the color space of the returned image. The default value of the property depends on the device and the video format selected. Possible values are {rgb|grayscale|YCbCr} when the default returned color space for the device is notgrayscale. Possible values are {rgb|grayscale|YCbCr|bayer} when the default returned color space for the device isgrayscale
BayerSensorAlignment Character vector indicating the 2x2 sensor alignment. Specifies Bayer patterns returned by hardware. Specify the sensor alignment for Bayer demosaicing. The default value of this property is'grbg'. Possible values are {grbg|gbrg|rggb|bggr}. Visible only ifReturnedColorSpaceis set to'bayer'.
ReturnedDataType The returned data type of the acquired frame. The defaultReturnedDataTypeissingle.

The setting of properties for the System object supports tab completion for enumerated properties while coding in MATLAB. Using the tab completion is an easy way to see available property values. After you type the property name, type a comma, then a space, then the first quote mark for the value, then hit tab to see the possible values.

You can also use thesetfunction with the object name and property name to get a list of available values for that property. For example:

set(obj, 'ReturnedColorSpace')

gets the list of available color space settings for the VideoDevice System object,obj.

Note that once you have done a step, in order to change a property or set a new one, you need to release the object using thereleasefunction, before setting the new property.

Note

To get a list of options you can use on a function, press theTabkey after entering a function on the MATLAB command line. The list expands, and you can scroll to choose a property or value. For information about using this advanced tab completion feature, seeUsing Tab Completion for Functions.

Functions

You can use these functions with the VideoDevice System object.

Function Purpose
step Acquire a single frame from the image acquisition device.

frame = step(obj);

acquires a single frame from the VideoDevice System object,obj.

Note that the first time you call step, it acquires exclusive use of the hardware and will start streaming data.

release Release VideoDevice resources and allow property value changes.

release(obj)

releases system resources (such as memory, file handles, or hardware connections) of System object,obj, and allows all its properties and input characteristics to be changed.

isLocked Returns a value that indicates if the VideoDevice resource is locked. (Usereleaseto unlock.)

L = isLocked(obj)

returns a logical value,L, which indicates whether properties are locked for the System object, obj. The object performs an internal initialization the first time thestepfunction is executed. This initialization locks properties and input specifications. Once this occurs, theisLockedfunction returns a value oftrue.

preview Activate a live image preview window.

preview(obj)

creates a Video Preview window that displays live video data for the VideoDevice System object,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 VideoDevice System objectROIproperty. If not specified, it uses the default resolution for the device.

closepreview Close live image preview window.

closepreview(obj)

closes the live preview window for VideoDevice System object,obj.

imaqhwinfo Returns information about the object.

imaqhwinfo(obj)

displays information about the VideoDevice System object,obj.

Examples

构造一个VideoDevice系统对象相关的with the Winvideo adaptor with device ID of 1.

vidobj = imaq.VideoDevice('winvideo', 1);

Set an object-level property, such asReturnedColorSpace. The syntax for an object-level property uses the object name, property name, and property value.

vidobj.ReturnedColorSpace = 'grayscale';

Set a device-specific property, such asBrightness. The syntax for a device-specific property uses theDevicePropertiesobject, the property name, and property value.

vidobj.DeviceProperties.Brightness = 150;

Preview the image.

preview(vidobj)

Acquire a single frame.

frame = step(vidobj);

Display the acquired frame.

imshow(frame)

Release the hardware resource.

release(vidobj);

Clear the VideoDevice System object.

clear vidobj;

Extended Capabilities

Introduced in R2012a

Was this topic helpful?