Documentation 
On this page… 

This example shows how to track objects at a train station and to determine which ones remain stationary. Abandoned objects in public areas concern authorities since they might pose a security risk. Algorithms, such as the one used in this example, can be used to assist security officers monitoring live surveillance video by directing their attention to a potential area of interest.
This example illustrates how to use the Blob Analysis and MATLAB® Function blocks to design a custom tracking algorithm. The example implements this algorithm using the following steps: 1) Eliminate video areas that are unlikely to contain abandoned objects by extracting a region of interest (ROI). 2) Perform video segmentation using background subtraction. 3) Calculate object statistics using the Blob Analysis block. 4) Track objects based on their area and centroid statistics. 5) Visualize the results.
Watch the Abandoned Object Detection exampleWatch the Abandoned Object Detection example.
The following figure shows the Abandoned Object Detection example model.
This example uses the first frame of the video as the background. To improve accuracy, the example uses both intensity and color information for the background subtraction operation. During this operation, Cb and Cr color channels are stored in a complex array.
If you are designing a professional surveillance system, you should implement a more sophisticated segmentation algorithm.
The Detect subsystem contains the main algorithm. Inside this subsystem, the Luminance Segmentation and Color Segmentation subsystems perform background subtraction using the intensity and color data. The example combines these two segmentation results using a binary OR operator. The Blob Analysis block computes statistics of the objects present in the scene.
Abandoned Object Tracker subsystem, shown below, uses the object statistics to determine which objects are stationary. To view the contents of this subsystem, rightclick the subsystem and select Look Under Mask. To view the tracking algorithm details, doubleclick the Abandoned Object Tracker block. The MATLAB® code in this block is an example of how to implement your custom code to augment Computer Vision System Toolbox™ functionality.
Abandoned Object Detection Results
The All Objects window marks the region of interest (ROI) with a yellow box and all detected objects with green boxes.
The Threshold window shows the result of the background subtraction in the ROI.
The Abandoned Objects window highlights the abandoned objects with a red box.
This example shows how to track objects at a train station and to determine which ones remain stationary. Abandoned objects in public areas concern authorities since they might pose a security risk. Algorithms, such as the one used in this example, can be used to assist security officers monitoring live surveillance video by directing their attention to a potential area of interest.
This example illustrates how to use the Blob Analysis and MATLAB® Function blocks to design a custom tracking algorithm. The example implements this algorithm using the following steps: 1) Eliminate video areas that are unlikely to contain abandoned objects by extracting a region of interest (ROI). 2) Perform video segmentation using background subtraction. 3) Calculate object statistics using the Blob Analysis block. 4) Track objects based on their area and centroid statistics. 5) Visualize the results.
Watch the Abandoned Object Detection exampleWatch the Abandoned Object Detection example.
The following figure shows the Abandoned Object Detection example model.
This example uses the first frame of the video as the background. To improve accuracy, the example uses both intensity and color information for the background subtraction operation. During this operation, Cb and Cr color channels are stored in a complex array.
If you are designing a professional surveillance system, you should implement a more sophisticated segmentation algorithm.
The Detect subsystem contains the main algorithm. Inside this subsystem, the Luminance Segmentation and Color Segmentation subsystems perform background subtraction using the intensity and color data. The example combines these two segmentation results using a binary OR operator. The Blob Analysis block computes statistics of the objects present in the scene.
Abandoned Object Tracker subsystem, shown below, uses the object statistics to determine which objects are stationary. To view the contents of this subsystem, rightclick the subsystem and select Look Under Mask. To view the tracking algorithm details, doubleclick the Abandoned Object Tracker block. The MATLAB® code in this block is an example of how to implement your custom code to augment Computer Vision System Toolbox™ functionality.
Abandoned Object Detection Results
The All Objects window marks the region of interest (ROI) with a yellow box and all detected objects with green boxes.
The Threshold window shows the result of the background subtraction in the ROI.
The Abandoned Objects window highlights the abandoned objects with a red box.
You can use the vision.TextInserter System object in MATLAB, or theInsert Text block in a Simulink^{®} model, to overlay text on video streams. In this Simulink model example, you add a running count of the number of video frames to a video using the Insert Text block. The model contains the From Multimedia File block to import the video into the Simulink model, a Frame Counter block to count the number of frames in the input video, and two Video Viewer blocks to view the original and annotated videos.
You can open the example model by typing
ex_vision_annotate_video_file_with_frame_numbersex_vision_annotate_video_file_with_frame_numbers
on the MATLAB^{®} command line.
For this example, the color format for the video was set to Intensity, and therefore the color value for the text was set to a scaled value. If instead, you set the color format to RGB, then the text value must satisfy this format, and requires a 3element vector.
Use the Insert Text block to annotate the video stream with a running frame count. Set the block parameters as follows:
Main pane, Text = ['Frame count' sprintf('\n') 'Source frame: %d']
Main pane, Color value = 1
Main pane, Location [x y] = [2 85]
Font pane, Font face = LucindaTypewriterRegular
By setting the Text parameter to ['Frame count' sprintf('\n') 'Source frame: %d'], you are asking the block to print Frame count on one line and the Source frame: on a new line. Because you specified %d, an ANSI C printfstyle format specification, the Variables port appears on the block. The block takes the port input in decimal form and substitutes this input for the %d in the string. You used the Location [x y] parameter to specify where to print the text. In this case, the location is 85 rows down and 2 columns over from the topleft corner of the image.
Set the configuration parameters. Open the Configuration dialog box by selecting Model Configuration Parameters from the Simulation menu. Set the parameters as follows:
Solver pane, Stop time = inf
Solver pane, Type = Fixedstep
Solver pane, Solver = Discrete (no continuous states)
When you specify the type of shape to draw, you must also specify it's location on the image. The table shows the format for the points input for the different shapes.
Shape  PTS input  Drawn Shape 

Single Rectangle  Fourelement row vector [x y width height] where


M Rectangles  Mby4 matrix $$\left[\begin{array}{cccc}{x}_{1}& {y}_{1}& widt{h}_{1}& heigh{t}_{1}\\ {x}_{2}& {y}_{2}& widt{h}_{2}& heigh{t}_{2}\\ \vdots & \vdots & \vdots & \vdots \\ {x}_{M}& {y}_{M}& widt{h}_{M}& heigh{t}_{M}\end{array}\right]$$ where each row of the matrix corresponds to a different rectangle and is of the same form as the vector for a single rectangle. 

You can draw one or more lines, and one or more polylines. A polyline contains a series of connected line segments.
Shape  PTS input  Drawn Shape 

Single Line  Fourelement row vector [x_{1} y_{1} x_{2} y_{2}] where


M Lines  Mby4 matrix $$\left[\begin{array}{cccc}{x}_{11}& {y}_{11}& {x}_{12}& {y}_{12}\\ {x}_{21}& {y}_{21}& {x}_{22}& {y}_{22}\\ \vdots & \vdots & \vdots & \vdots \\ {x}_{M1}& {y}_{M1}& {x}_{M2}& {y}_{M2}\end{array}\right]$$ where each row of the matrix corresponds to a different line and is of the same form as the vector for a single line. 

Single Polyline with (L1) Segments  Vector of size 2L, where L is
the number of vertices, with format, [x_{1},
y_{1}, x_{2}, y_{2},
..., x_{L}, y_{L}].


M Polylines with (L1) Segments  2LbyN matrix $$\left[\begin{array}{ccccccc}{x}_{11}& {y}_{11}& {x}_{12}& {y}_{12}& \cdots & {x}_{1L}& {y}_{1L}\\ {x}_{21}& {y}_{21}& {x}_{22}& {y}_{22}& \cdots & {x}_{2L}& {y}_{2L}\\ \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ {x}_{M1}& {y}_{M1}& {x}_{M2}& {y}_{M2}& \cdots & {x}_{ML}& {y}_{ML}\end{array}\right]$$ where each row of the matrix corresponds to a different polyline and is of the same form as the vector for a single polyline. When you require one polyline to contain less than (L–1) number of segments, fill the matrix by repeating the coordinates of the last vertex. The block produces an error message if the number of rows is less than two or not a multiple of two. 

You can draw one or more polygons.
Shape  PTS input  Drawn Shape 

Single Polygon with L line segments  Row vector of size 2L, where L is
the number of vertices, with format, [x_{1} y_{1} x_{2} y_{2} ...
x_{L} y_{L}] where


M Polygons with the largest number of line segments in any line being L  Mby2L matrix $$\left[\begin{array}{ccccccc}{x}_{11}& {y}_{11}& {x}_{12}& {y}_{12}& \cdots & {x}_{1L}& {y}_{1L}\\ {x}_{21}& {y}_{21}& {x}_{22}& {y}_{22}& \cdots & {x}_{2L}& {y}_{2L}\\ \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ {x}_{M1}& {y}_{M1}& {x}_{M2}& {y}_{M2}& \cdots & {x}_{ML}& {y}_{ML}\end{array}\right]$$ where each row of the matrix corresponds to a different polygon and is of the same form as the vector for a single polygon. If some polygons are shorter than others, repeat the ending coordinates to fill the polygon matrix. The block produces an error message if the number of rows is less than two or is not a multiple of two. 

You can draw one or more circles.
Shape  PTS input  Drawn Shape 

Single Circle  Threeelement row vector [x y radius] where


M Circles  Mby3 matrix $$\left[\begin{array}{ccc}{x}_{1}& {y}_{1}& radiu{s}_{1}\\ {x}_{2}& {y}_{2}& radiu{s}_{2}\\ \vdots & \vdots & \vdots \\ {x}_{M}& {y}_{M}& radiu{s}_{M}\end{array}\right]$$ where each row of the matrix corresponds to a different circle and is of the same form as the vector for a single circle. 
