Documentation

Saving Video Data to a File

Introduction

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.

Step 1: Open the Image Acquisition Toolbox Library

To use the From Video Device block, you must open the Image Acquisition Toolbox™ block library. To open it, start the Simulink® Library Browser and select the Image Acquisition Toolbox™ entry from the list.

To start the Simulink Library Browser, enter

simulink

at the MATLAB® prompt. (For more information about opening the library, see Opening the Image Acquisition Toolbox Block Library.)

Step 2: Open a Model or Create a New Model

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

To create a new model, click the New model button on the Simulink Library Browser toolbar. Simulink opens an empty model. To assign the new model a name, use the Save option.

Step 3: Drag the From Video Device Block into the 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

Step 4: Drag Other Blocks to Complete the 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 System Toolbox™.

Open the Computer Vision System 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

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 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 Y, Cb, Cr and the input ports on the To Multimedia File block are 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

Step 6: Specify From Video Device Block Parameter Values

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.

Step 7: Run the Simulation

To run the simulation, click the green Run button on the Simulink Editor toolbar. You can use toolbar options to specify how long to run the simulation and to stop it. You can also start the simulation by selecting Simulation > Run.

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.

Was this topic helpful?