Problems with Matlab Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you Matlab Codes for Registered Members of this site only, at free service...Follow Me.

Video Surveillance Matlab


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.

Related Files

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
Figure 1 (figure__1.png)
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:
TABLE 1
SAD=Ik(i,j)Ik1(i,j)
where:
Ik(i,j)- Current Frame
Ik1(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.
Figure 2: Video Surveillance Block Diagram
Figure 2 (fig2.JPG)

Simulation

  1. Open a new Simulink model
  2. Add the blocks shown in the following table (Please refer also to Figure 3):
TABLE 2: Video Surveillance Simulink Blocks
FunctionalityBlockBlocksetQuant.
SADSubsystemSimulink / Ports & Subsystems1
DelaySignal Processing Blockset / Signal Operations1
AbsSimulink / Math Operations1
Matrix SumSignal Processing Blockset / Math Functions / Matrices and Linear Algebra / Matrix Operations2
Data Type ConversionSimulink / Signal Attributes1
Add Sum,Simulink / Math Operations1
RecordingEnabled SubsystemSimulink / Ports & Subsystems1
Add Sum,Simulink / Math Operations1
DelaySignal Processing Blockset / Signal Operations1
counterSubsystemSimulink / Ports & Subsystems1
Add Sum,Simulink / Math Operations1
DelaySignal Processing Blockset / Signal Operations1
Generate data for motion energy and threshold displayMatrix ConcatenateSimulink / Math Operations2
Compare Motion Energy against ThresholdRelational OperatorSimulink / Logic and Bit Operations1
Input VideoFrom Multimedia FileSignal Processing Blockset / Signal Processing Sources1
Display ControlConstantSignal Processing Blockset / Signal Processing Sources1
Display Motion Energy and ThresholdFloating ScopeSimulink/Sinks1
Draws formatted text on an image or video streamInsert TextVideo and Image Processing Blockset / Text & figure__1
Connected to the trigger (not used for simulation)TerminatorSimulink/Sinks1
Images’ DisplayTo Video DisplayVideo and Image Processing Blockset / Sinks2
Figure 3: Simulink Blocks for Video Surveillance
Figure 3 (figure__2.png)

Configuring the SAD blocks

  1. Configure one of the “Add” block for subtraction, you may also change its icon shape to a circular form as follows1:
    Figure 4
    Figure 4 (figure__3.png)
  2. Configure its fixed point mode of operation Configure one of the “Matrix Sum” blocks for adding rows:
    Figure 5
    Figure 5 (figure__4.png)
  3. Configure its fixed point mode of operation
    Figure 6
    Figure 6 (figure__5.png)
  4. Configure the fixed point mode of operation for the second Matrix “Column Add” block:
    Figure 7
    Figure 7 (figure__6.png)

Configuring the Input blocks

  1. Configure on of the “Video Source” "From Multimedia File" block for reading frames from the "vipmen.avi" file.
    TABLE 3
    figure__7.pngfigure__8.png
  2. Set the initial value of the "Constant" to 1e5.
    Figure 8
    Figure 8 (figure__9.png)
    Figure 9
    Figure 9 (figure__10.png)
  3. Configure "Data Type Conversion" block :
    Figure 10
    Figure 10 (figure__11.png)
  4. Configure " Relational Operator " block :
    Figure 11
    Figure 11 (figure__12.png)
  5. Configure one of the " Matrix Concatenate " block :
    Figure 12
    Figure 12 (figure__13.png)
  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:
    Figure 13
    Figure 13 (figure__14.png)
    You may keep the default configuration for "Data history".
  7. Configure the " Insert Text " block :
    Figure 14
    Figure 14 (figure__15.png)
  8. Double-click on the "Enabled Subsystem" block, and build it as shown below:
    Figure 15
    Figure 15 (figure__16.png)
  9. Double-click on one of the "Subsystem" block and build it as shown below:
    Figure 16
    Figure 16 (figure__17.png)
    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":
    Figure 17
    Figure 17 (figure__18.png)

Connecting the blocks:

  1. Connect the blocks as shown in the following figure:
    Figure 18: Video Surveillance model
    Figure 18 (figure__19.png)
  2. Save the model as "surveillance_sim.mdl".

Running the model

  1. Run the model. You should observe the following images:
    TABLE 4
    Current FrameRecorded Frame
    figure__20.pngfigure__21.png
  2. Double click the scope and you will see:
    Figure 19
    Figure 19 (fig22.JPG)
    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:
    Figure 20
    Figure 20 (figure__23.png)
  11. Connect the blocks as shown:
    Figure 21
    Figure 21 (figure__24.png)
  12. Configure the "Gain" block :
    Figure 22
    Figure 22 (figure__25.png)
  13. Configure the "Switch" block :
    Figure 23
    Figure 23 (figure__26.png)
  14. Double-click the “Surveillance Algorithm” subsystem.
  15. Configure the "Byte Unpack" block :
    Figure 24
    Figure 24 (figure__27.png)
  16. Configure the "Byte Pack" block :
    Figure 25
    Figure 25 (figure__28.png)
  17. Configure the " TCP/IP Receive " block :
    Figure 26
    Figure 26 (figure__29.png)
    Figure 27
    Figure 27 (figure__30.png)
  18. Configure the " TCP/IP Send " block :
    Figure 28
    Figure 28 (figure__31.png)
  19. Connect the “Video Frame Capture Motion Threshold ” block as shown:
    Figure 29
    Figure 29 (figure__32.png)
  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:
    TABLE 5
    figure__33.pngfigure__34.png
    fig33.JPGfig34.JPG
  24. Configure the "Byte Unpack" block :
    Figure 30
    Figure 30 (figure__35.png)
  25. Connect the block as shown:
    Figure 31
    Figure 31 (figure__36.png)
  26. Configure the " TCP/IP Receive " block :
    Figure 32
    Figure 32 (figure__37.png)
  27. Double-click the “Display” subsystem.
  28. Double-click the “Data Unpack” subsystem.
  29. Configure the "Byte Unpack" block :
    Figure 33
    Figure 33 (figure__38.png)
  30. Connect the block as shown:
    Figure 34
    Figure 34 (figure__39.png)
  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 :
    Figure 35
    Figure 35 (figure__40.png)
  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.
    Figure 36
    Figure 36 (figure__41.png)
  36. Add a "Matrix Concatenate" from the "Math Operations" group of the "Simulink" blockset.
  37. Connect the block as shown:
    Figure 37
    Figure 37 (figure__42.png)
  38. Configure the " Matrix Concatenate" block :
    Figure 38
    Figure 38 (figure__43.png)
  39. Connect the "Display" subsystem as shown:
    Figure 39
    Figure 39 (figure__44.png)
  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);   % 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 
  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:
    Figure 40
    Figure 40 (figure__45.png)
    Figure 41
    Figure 41 (figure__46.png)
    If you want to display the Absolute Differences Image, change the state of the switch from 0 to 1. You will then see:
    Figure 42
    Figure 42 (figure__47.png)

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.

0 comments:

Post a Comment

Recent Comments

Popular Matlab Topics

Share your knowledge - help others

Crazy over Matlab Projects ? - Join Now - Follow Me

Sites U Missed to Visit ?

Related Posts Plugin for WordPress, Blogger...

Latest Articles

Special Search For Matlab Projects

MATLAB PROJECTS

counter

Bharadwaj. Powered by Blogger.