The best way to learn about the From Video Device block is to see an example. This section provides a step-by-step example that builds a simple model using the block in conjunction with blocks from other blockset libraries.
Block names are not shown by default in the model. To display the hidden block names while working in the model, select Display and clear the Hide Automatic Names check box.
To start Simulink® and create a new model, enter the following at the MATLAB® command prompt:
In the Simulink start page, click Blank Model, and then Create Model. An empty Editor window opens.
In the Editor, click Save button in the Simulation tab to assign a name to your new model.
In the model Editor window, click the Library Browser button in the Simulation tab.
The Simulink Library Browser opens. Its left pane contains
a tree of available block libraries in alphabetical order. Click the
Acquisition Toolbox node.
To use a block, add it to an existing model or create a new model.
To use the From Video Device block in a model, click the block in the library and, holding the mouse button down, drag it into the Simulink Editor. Note how the name on the block changes to reflect the device connected to your system that is associated with the block. If you have multiple devices connected, you can choose the device to use in the Source Block Parameters dialog box by double-clicking the block.
Drag From Video Device Block into Model
To illustrate using the block, this example creates a simple model that acquires data and then outputs the data to a file in Audio Video Interleave (AVI) format. To create this model, this example uses a block from Computer Vision Toolbox™.
Open the Computer Vision Toolbox library. In the library window, open the Sinks subsystem. From this subsystem, click the To Multimedia File block in the library and, holding the mouse button down, drag the block into the Simulink Editor.
Drag Output Block to Model
Connect the three outputs from the From Video Device block to the three corresponding inputs on the To Multimedia File block. If the ports are not displayed, you can choose the option to display them in the Source Block Parameters dialog box by double-clicking the block. One quick way to make all three connections at once is to select the From Video Device block, press and hold the Ctrl key, and then click the To Multimedia File block.
Note that your camera might have output ports that are
Cb, Cr and the input ports on the To Multimedia File block
R, G, B. Some devices designate color band
by YCbCr and some devices designate it by RGB. Both are valid and
will work together.
Connect the From Video Device Block to the To Multimedia File Block
To check From Video Device block parameter settings, double-click the block's icon in the Simulink Editor. This opens the Source Block Parameters dialog box for the From Video Device block, shown in the following figure. Use the various fields in the dialog box to determine the current values of From Video Device block parameters or change the values.
For example, using this dialog box, you can specify the device you want to use, select the video format you want to use with the device, or specify the block sample time. For more details, see the From Video Device block reference page.
You can set parameters for any of the blocks you include in your model. For example, to specify the name of the AVI file, double-click the To Multimedia File block. Make sure that you have write permission to the directory into which the block writes the AVI file.
To run the simulation, click the green Run button on the Simulink Editor toolstrip. You can use toolstrip options to specify how long to run the simulation and to stop it.
While the simulation is running, the status bar at the bottom of the Simulink Editor indicates the progress of the simulation. After the simulation finishes, check the directory in which you ran the simulation to verify that an AVI file was created.