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:
- Functional Requirements
- System modeling and simulation
- 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.
Related Files
- Powerpoint Presentation - Surveillance.ppt
- Simulink Model for Simulation - surveillance.mdl
- Video-clip viplane.avi
- MATLAB script my_tcpip_surveil_script.m
- Simulink Model for Real-Time (DM6437) - my_dm6437evmsurveil_tcpip.mdl
- Simulink Model for Real-Time Lane Detection (PC) - my_pc_surveil_tcpip.mdl
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=∑∑∣Ik(i,j)−Ik−1(i,j)∣ | |
where: | |
Ik(i,j) | - Current Frame |
Ik−1(i,j) | - 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
- Open a new Simulink model
- Add the blocks shown in the following table (Please refer also to Figure 3):
Functionality | Block | Blockset | Quant. |
SAD | Subsystem | Simulink / Ports & Subsystems | 1 |
Delay | Signal Processing Blockset / Signal Operations | 1 | |
Abs | Simulink / Math Operations | 1 | |
Matrix Sum | Signal Processing Blockset / Math Functions / Matrices and Linear Algebra / Matrix Operations | 2 | |
Data Type Conversion | Simulink / Signal Attributes | 1 | |
Add Sum, | Simulink / Math Operations | 1 | |
Recording | Enabled Subsystem | Simulink / Ports & Subsystems | 1 |
Add Sum, | Simulink / Math Operations | 1 | |
Delay | Signal Processing Blockset / Signal Operations | 1 | |
counter | Subsystem | Simulink / Ports & Subsystems | 1 |
Add Sum, | Simulink / Math Operations | 1 | |
Delay | Signal Processing Blockset / Signal Operations | 1 | |
Generate data for motion energy and threshold display | Matrix Concatenate | Simulink / Math Operations | 2 |
Compare Motion Energy against Threshold | Relational Operator | Simulink / Logic and Bit Operations | 1 |
Input Video | From Multimedia File | Signal Processing Blockset / Signal Processing Sources | 1 |
Display Control | Constant | Signal Processing Blockset / Signal Processing Sources | 1 |
Display Motion Energy and Threshold | Floating Scope | Simulink/Sinks | 1 |
Draws formatted text on an image or video stream | Insert Text | Video and Image Processing Blockset / Text & figure__ | 1 |
Connected to the trigger (not used for simulation) | Terminator | Simulink/Sinks | 1 |
Images’ Display | To Video Display | Video and Image Processing Blockset / Sinks | 2 |
Configuring the SAD blocks
- Configure one of the “Add” block for subtraction, you may also change its icon shape to a circular form as follows1:
Figure 4 - Configure its fixed point mode of operation Configure one of the “Matrix Sum” blocks for adding rows:
Figure 5 - Configure its fixed point mode of operation
Figure 6 - Configure the fixed point mode of operation for the second Matrix “Column Add” block:
Figure 7
Configuring the Input blocks
- Configure on of the “Video Source” "From Multimedia File" block for reading frames from the "vipmen.avi" file.
TABLE 3 - Set the initial value of the "Constant" to 1e5.
Figure 8 Figure 9 - Configure "Data Type Conversion" block :
Figure 10 - Configure " Relational Operator " block :
Figure 11 - Configure one of the " Matrix Concatenate " block :
Figure 12 - 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".
Figure 13 - Configure the " Insert Text " block :
Figure 14 - Double-click on the "Enabled Subsystem" block, and build it as shown below:
Figure 15 - Double-click on one of the "Subsystem" block and build it as shown below:Save the subsystem as: "Motion Energy"
Figure 16 - Double-click on one the remaining "Subsystem" block,build it as shown below and name it "Frame Counter":
Figure 17
Connecting the blocks:
- Connect the blocks as shown in the following figure:
Figure 18: Video Surveillance model - Save the model as "surveillance_sim.mdl".
Running the model
- Run the model. You should observe the following images:
TABLE 4 Current Frame Recorded Frame - 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.
Figure 19
Real Time Implementation
Video Surveillance using TCP/IP
- Open the “video_sim.mdl” Simulink model (generated in the "A Framework for Video Processing with the DM6437 DVDP" module).
- Rename the model "my_dm6437evmsurveil_tcpip.mdl".
- Rename the “R_W Algorithm” subsystem to “Surveillance Algorithm”.
- Double-click the “Surveillance Algorithm” block.
- In this block, add a Add the “Function- Call Subsystem” from the “Ports & Subsystems" group of the "Simulink" Blockset.
- Rename “Function- Call Subsystem” to “Video Frame Capture Motion Threshold” and Double-click it.
- Open the model "surveillance_sim.mdl", created in section and copy it into “Video Frame Capture Motion Threshold ”.
- 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.
- Add a "Switch" from the "Signal Routing" group of the "Simulink" blockset and a "Gain" from the "Math Operation" group of the "Simulink" blockset.
- Double-click the “Motion Energy” block and add him another output port as shown:
Figure 20 - Connect the blocks as shown:
Figure 21 - Configure the "Gain" block :
Figure 22 - Configure the "Switch" block :
Figure 23 - Double-click the “Surveillance Algorithm” subsystem.
- Configure the "Byte Unpack" block :
Figure 24 - Configure the "Byte Pack" block :
Figure 25 - Configure the " TCP/IP Receive " block :
Figure 26 Figure 27 - Configure the " TCP/IP Send " block :
Figure 28 - Connect the “Video Frame Capture Motion Threshold ” block as shown:
Figure 29 - Open the “RW_pcl_tcpip.mdl” model, created in the "Video R_W" file
- Rename the model "my_pc_surveil_tcpip.mdl".
- 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.
- Configure the " Constant " blocks:
TABLE 5 - Configure the "Byte Unpack" block :
Figure 30 - Connect the block as shown:
Figure 31 - Configure the " TCP/IP Receive " block :
Figure 32 - Double-click the “Display” subsystem.
- Double-click the “Data Unpack” subsystem.
- Configure the "Byte Unpack" block :
Figure 33 - Connect the block as shown:
Figure 34 - 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.
- Configure the " Insert Text " block :
Figure 35 - Add the “Subsystem” from the “Ports & Subsystems" group of the "Simulink" Blockset
- Rename it "Combine Count"
- Add a "Frame Counter" subsystem as we did in paragraph 14 at the first section.
Figure 36 - Add a "Matrix Concatenate" from the "Math Operations" group of the "Simulink" blockset.
- Connect the block as shown:
Figure 37 - Configure the " Matrix Concatenate" block :
Figure 38 - Connect the "Display" subsystem as shown:
Figure 39 - 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); % Load application loadApp(modelName, CCS_Obj); % 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); set_param([hostModelName '/TCP//IP Receive'], 'Host', hostName); fprintf('Click on play button to start running the host side application!\n\n') %[EOF] tcpip_surveil_script.m
- 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.
- 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
- Build load and run the project from the "my_dm6437evmsurveil_tcpip.mdl" model. Double-click the " Build / Reload & Run" block.
- Running the script, you will see:
Figure 40 If you want to display the Absolute Differences Image, change the state of the switch from 0 to 1. You will then see:Figure 41 Figure 42
0 comments:
Post a Comment