Main Content

Save Video Data to a File

This example shows how to build a simple model using the From Video Device block in conjunction with blocks from other blockset libraries.

Note

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.

Step 1: Create a New Model

To start Simulink® and create a new model, enter the following in the MATLAB® Command Window.

simulink

On the Simulink start page, click Blank Model and then Create Model. An empty Editor window opens.

In the Editor, click Save on the Simulation tab to assign a name to your new model.

Step 2: Open the Image Acquisition Toolbox Library

In the model Editor window, click the Library Browser button on the Simulation tab.

The Simulink Library Browser opens. Its left pane contains a tree of available block libraries in alphabetical order. Click the Image Acquisition Toolbox node.

To use a block, add it to an existing model or create a new model.

Step 3: Drag the From Video Device Block into the Model

To use the From Video Device block in a model, drag the block 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 parameters dialog box by double-clicking the block.

Step 4: Drag Other Blocks to Complete the Model

To illustrate how to use the block, this example creates a simple model that acquires data and then returns the data to a file in 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 drag the block into the Simulink Editor.

Step 5: Connect the Blocks

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 display them in the 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.

The input ports of the To Multimedia File block are RGB, but you can use a camera that has either YCbCr or RGB output ports.

Step 6: Specify From Video Device Block Parameter Values

To check From Video Device block parameter settings, double-click the block icon in the Simulink Editor. The parameters dialog box for the From Video Device block opens. Use the various fields in the dialog box to set or change the values of the From Video Device block parameters.

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 details, see From Video Device.

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.

Step 7: Run the Simulation

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. When the simulation finishes, the software saves an AVI file to the current working directory.

See Also