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.VideoDevice
function to create the System object. It supports the same adaptors and hardware that thevideoinput
object supports; however, it has different functions and properties associated with it. For example, the System object uses thestep
function to acquire single frames.
obj = imaq.VideoDevice
creates 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
.adaptorname
is a character vector that specifies the name of the adaptor used to communicate with the device. Use theimaqhwinfo
function to determine the adaptors available on your system.
obj = imaq.VideoDevice(adaptorname, deviceid)
creates a VideoDevice System object,obj
, with the default format for specifiedadaptorname
anddeviceid
.deviceid
is 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
, whereformat
is 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 by |
VideoFormat |
Video format to be used by the image acquisition device. Specify the video format to use while acquiring the frame. The default value of |
DeviceFile |
Name of file specifying video format. This property is only visible whenVideoFormat is 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 the |
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 whenHardwareTriggering is 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 ifReturnedColorSpace is set to'bayer' . |
ReturnedDataType |
The returned data type of the acquired frame. The defaultReturnedDataType issingle . |
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 theset
function 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 therelease
function, 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, 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, |
isLocked |
Returns a value that indicates if the VideoDevice resource is locked. (Userelease to unlock.)
L = isLocked(obj) returns a logical value, |
preview |
Activate a live image preview window.
preview(obj) creates a Video Preview window that displays live video data for the VideoDevice System object, |
closepreview |
Close live image preview window.
closepreview(obj) closes the live preview window for VideoDevice System object, |
imaqhwinfo |
Returns information about the object.
imaqhwinfo(obj) displays information about the VideoDevice System object, |
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 theDeviceProperties
object, 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;