# Connexions

You are here: Home » Content » Video Surveillance

### Lenses

What is a lens?

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

#### Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
• TI DSP

This module is included inLens: Texas Instruments DSP Lens
By: Texas InstrumentsAs a part of collection: "From MATLAB and Simulink to Real-Time with TI DSP's"

Click the "TI DSP" link to see all content affiliated with them.

Click the tag icon to display tags associated with this content.

#### Also in these lenses

• Lens for Engineering

This module is included inLens: Lens for Engineering
By: Sidney Burrus

Click the "Lens for Engineering" link to see all content selected in this lens.

### Recently Viewed

This feature requires Javascript to be enabled.

### Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

# Video Surveillance

Module by: Jacob Fainguelernt. E-mail the author

Summary: This module describes the design flow of a motion detection system based video surveillance system based on the DM6437 Digital Video Development Platform (DVDP). The system will be able to identify and record only “interesting” video frames containing motion.

## Introduction

Continuous-scene monitoring applications, such as ATM booths, parking lots or traffic monitoring systems, generate large volumes of data. Recording and archiving such volumes of data is a real problem, and one way to solve this is to reduce the size of the data stream right at the source.

In addition to traditional methods for compressing individual video images, we could identify and record only “interesting” video images, such as those images with significant amounts of motion in the field of view. That could significantly help reduce the data rates for surveillance-specific applications.

In this section, we’ll illustrate the design flow of a motion detection system based video surveillance system. The system will be able to identify and record only “interesting” video frames containing motion.

The development process will follow the following three steps:

1. Functional Requirements
2. System modeling and simulation
3. Code generation and implementation

### Hardware and Software Requirements

This laboratory was originally developed using the following hardware and software:

• MATLAB® R2008a
• Code Composer Studio (CCS) v3.3
• Texas Instruments DM6437 hardware.

## Video Surveillance

In this session we will show how to create the line detection model, and how it can be integrated in Simulation and Real-Time Implementations.

Figure 1: The Motion Detection Process

### The Motion Energy Estimation

The Motion Energy estimation is based on the calculation of the Sum of Absolute Differences (SAD)” according to the following equation:

 SAD = ∑ i ∑ j ∣ I k i , j − I k − 1 i , j ∣ SAD = ∑ i ∑ j ∣ I k i , j − I k − 1 i , j ∣ size 12{ ital "SAD"= Sum cSub { size 8{i} } { Sum cSub { size 8{j} } { lline I rSub { size 8{k} } left (i,j right ) - I rSub { size 8{k - 1} } left (i,j right ) rline } } } {} where: I k i , j I k i , j size 12{I rSub { size 8{k} } left (i,j right )} {} - Current Frame I k − 1 i , j I k − 1 i , j size 12{I rSub { size 8{k - 1} } left (i,j right )} {} - Previous Frame

### Functional Description

The Video Surveillance system block diagram is shown in Figure 2. The source video is displayed and played back through the system. This incoming video stream is processed by a subsystem that estimates the motion within the scene and captures the interesting video frames. The system can display either the recorded video frame or the Absolute Differences (AD) image.

The user can configure the motion energy threshold value and select which image will be displayed (Display Control). The system outputs include, besides the displayed image, the following features:

• A graph of the motion energy as a function of time. This graph displays the threshold value as well.
• The Frame count of the recorded image
• An output signal triggered by motion detection (Trigger)

While the generated code is running on the target, a host side Simulink® model simultaneously sends video frames to the target via TCP/IP protocol using TCP/IP Blocks from Instrument Control Toolbox™. The target receives video frames sent by the host side Simulink model, computes the sum of the absolute value of differences (SAD) between successive video frames, and returns an estimate of motion. When the motion estimate value exceeds a threshold, the target increments a counter and sends the corresponding frame back to the host.

## Simulation

1. Open a new Simulink model
2. Add the blocks shown in the following table (Please refer also to Figure 3):

1. Configure one of the “Add” block for subtraction, you may also change its icon shape to a circular form as follows1:
2. Configure its fixed point mode of operation Configure one of the “Matrix Sum” blocks for adding rows:
3. Configure its fixed point mode of operation
4. Configure the fixed point mode of operation for the second Matrix “Column Add” block:

### Configuring the Input blocks

1. Configure on of the “Video Source” "From Multimedia File" block for reading frames from the "vipmen.avi" file.
2. Set the initial value of the "Constant" to 1e5.
3. Configure "Data Type Conversion" block :
4. Configure " Relational Operator " block :
5. Configure one of the " Matrix Concatenate " block :
6. The “Floating Scope” will be used to display the motion energy and the threshold2 as a function of time. Double-Click the block. A cope screen will appear, you should then click the icon as shown in the following picture: You may keep the default configuration for "Data history".
7. Configure the " Insert Text " block :
8. Double-click on the "Enabled Subsystem" block, and build it as shown below:
9. Double-click on one of the "Subsystem" block and build it as shown below:Save the subsystem as: "Motion Energy"
10. Double-click on one the remaining "Subsystem" block,build it as shown below and name it "Frame Counter":

### Connecting the blocks:

1. Connect the blocks as shown in the following figure:
2. Save the model as "surveillance_sim.mdl".

### Running the model

1. Run the model. You should observe the following images:
 Current Frame Recorded Frame
2. Double click the scope and you will see:In this scope display, yellow represents the motion estimate from each video frame, and magenta is the threshold level. In the Motion Threshold scope here, we see that we identified five frames with motion above the threshold that were captured and recorded.

## Real Time Implementation

### Video Surveillance using TCP/IP

1. Open the “video_sim.mdl” Simulink model (generated in the "A Framework for Video Processing with the DM6437 DVDP" module).
2. Rename the model "my_dm6437evmsurveil_tcpip.mdl".
3. Rename the “R_W Algorithm” subsystem to “Surveillance Algorithm”.
4. Double-click the “Surveillance Algorithm” block.
5. In this block, add a Add the “Function- Call Subsystem” from the “Ports & Subsystems" group of the "Simulink" Blockset.
6. Rename “Function- Call Subsystem” to “Video Frame Capture Motion Threshold” and Double-click it.
7. Open the model "surveillance_sim.mdl", created in section and copy it into “Video Frame Capture Motion Threshold ”.
8. Add three input ports "In1" from the "Sources" group of the "Simulink" blockset and three output ports "Out1" from the "Sinks" group of the "Simulink" blockset.
9. Add a "Switch" from the "Signal Routing" group of the "Simulink" blockset and a "Gain" from the "Math Operation" group of the "Simulink" blockset.
10. Double-click the “Motion Energy” block and add him another output port as shown:
11. Connect the blocks as shown:
12. Configure the "Gain" block :
13. Configure the "Switch" block :
14. Double-click the “Surveillance Algorithm” subsystem.
15. Configure the "Byte Unpack" block :
16. Configure the "Byte Pack" block :
17. Configure the " TCP/IP Receive " block :
18. Configure the " TCP/IP Send " block :
19. Connect the “Video Frame Capture Motion Threshold ” block as shown:
20. Open the “RW_pcl_tcpip.mdl” model, created in the "Video R_W" file
21. Rename the model "my_pc_surveil_tcpip.mdl".
22. Add the "Manual Switch" from the "Signal Routing" group of the "Simulink" blockset and three "Constant" blocks from the "Signal Processing" group of the "Signal Processing" blockset.
23. Configure the " Constant " blocks:
24. Configure the "Byte Unpack" block :
25. Connect the block as shown:
26. Configure the " TCP/IP Receive " block :
27. Double-click the “Display” subsystem.
28. Double-click the “Data Unpack” subsystem.
29. Configure the "Byte Unpack" block :
30. Connect the block as shown:
31. Add to the "Display" subsystem the "Insert Text" from the " Text & figure__" group of the " Video and Image Processing " blockset, " Floating Scope" from the "Sinks" group of the "Simulink" blockset.
32. Configure the " Insert Text " block :
33. Add the “Subsystem” from the “Ports & Subsystems" group of the "Simulink" Blockset
34. Rename it "Combine Count"
35. Add a "Frame Counter" subsystem as we did in paragraph 14 at the first section.
36. Add a "Matrix Concatenate" from the "Math Operations" group of the "Simulink" blockset.
37. Connect the block as shown:
38. Configure the " Matrix Concatenate" block :
39. Connect the "Display" subsystem as shown:
40. Open a new m-file, copy the following code and save it as "my_tcpip_surveil_script.m" at the same directory as the model.

function my_tcpip_surveil_script(hostModelName)
%my_tcpip_surveil_script controls host-side TCP/IP processing for
%  Video Surveillance demo:
%  1) Builds and runs the target application
%********** Initialization ********************
% Get model name
modelName = gcs;

% Connect to CCS
CCS_Obj = connectToCCS(modelName);
saved_visibility = CCS_Obj.isvisible;
CCS_Obj.visible(1);

% Run application
fprintf('Running application: %s\n', modelName);
CCS_Obj.run;

% Allow some time for DHCP address acquisition
pause(3);

% Retrieve target's host name
boardType = get_param([modelName '/IP Config'], 'boardType');
userPrompt = sprintf('Enter the IP address or the host name of the %s board: ', boardType);
hostName = inputdlg(userPrompt, 'Target IP address');
if isempty(hostName)
errordlg('You have to provide a valid IP address or host name to run the demo.', ...
'TCP/IP Surveillance Recording', 'modal');
return;
end
hostName = strtrim(hostName{1});

% Launch host side UDP receive / Video display model
fprintf('Launching host side application: %s\n', hostModelName);
open_system(hostModelName);

% Update host side TCP/IP blocks with target's IP address
set_param([hostModelName '/TCP//IP Send'], 'Host', hostName);
fprintf('Click on play button to start running the host side application!\n\n')

%[EOF] tcpip_surveil_script.m

41. Open a new m-file, copy the following code and save it as "my_tcpip_surveil_script.m" at the same directory as the model.
42. now we have two models ("my_pc_surveil_tcpip.mdl" and "my_dm6437evmsurveil_tcpip.mdl") and one MATLAB file ("my_tcpip_surveil_script.m")

### Running the Real-time Model

1. Build load and run the project from the "my_dm6437evmsurveil_tcpip.mdl" model. Double-click the " Build / Reload & Run" block.
2. Running the script, you will see:If you want to display the Absolute Differences Image, change the state of the switch from 0 to 1. You will then see:

## Footnotes

1. The symbol “|” is used to place the “+” and “-“ perpendicular to each other
2. The threshold is changed upon a user command. The simultaneous display of the threshold and motion energy will enable the user to follow-up the process of recording frames.

## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks