The VideoDevice System object™ supports code generation in MATLAB® via
codegen function. To use the
you must have a MATLAB Coder™ license. System objects also support
code generation using the MATLAB Function block in Simulink®.
You can also use the System object with MATLAB Compiler™.
Note: The MATLAB Compiler software supports System objects for use inside MATLAB functions. The MATLAB Compiler does not support System objects for use in MATLAB scripts.
If you use the
For more information see the documentation for the MATLAB
The VideoDevice System object generates code with limited portability. The System object uses precompiled shared libraries, such as DLLs, to support I/O for specific types of devices. The shared library locations that the generated executable requires are as follows:
Specific MathWorks shared libraries under [MATLABROOT]\bin\<ARCH>\
MathWorks adaptor libraries under [MATLABROOT]\toolbox\imaq\imaqadaptors\<ARCH>\ specific to the device selected.
You will need to add the above folders to your system path before running the generated executable outside of MATLAB.
Assign System objects to persistent variables.
Global variables are not supported.
Initialize System objects once by embedding the object
handles in an
if statement with a call to
Call the constructor exactly once for each System object.
Set arguments to System object constructors as compile-time constants.
Use the object constructor to set System object properties
because you cannot use dot notation for code generation. You can use
get function to display properties.
Test your code in simulation before generating code.
The following shows an example of some of these rules.
% Note: System Objects created for Codegen have to be persistent variables. persistent vid; % Construct the IMAQ VideoDevice System Object. if isempty(vid) % Note: All required parameters must be passed to the System Object at % the point of construction. vid = imaq.VideoDevice('winvideo', 1, 'MJPG_320x240', ... 'ROI', [1 1 320 240], ... 'ReturnedColorSpace', 'rgb', ... 'DeviceProperties.Brightness', 130, ... 'DeviceProperties.Sharpness', 220); end
Ensure that the value assigned to a nontunable or public property is a constant and that there is at most one assignment to that property (including the assignment in the constructor). Do not set any properties during code generation.
The only System object functions supported in code generation are:
Do not set System objects to become outputs from the MATLAB Function block.
Do not pass a System object as an example input argument to
a function being compiled with
Do not pass a System object to functions declared as extrinsic
(i.e., functions called in interpreted mode) using the
Do not return System objects from any extrinsic functions.