Object Tracking for Moving Objects with Kalman Filter in Matlab Code

Verified

Added on  2020/05/16

|9
|782
|76
Practical Assignment
AI Summary
This assignment presents a practical implementation of object tracking using Matlab code, focusing on the application of Kalman filtering and blob analysis to detect and track moving objects within a video. The solution begins by explaining the rationale for using Extended Kalman Filtering (EKF) over linear Kalman filtering, highlighting its suitability for non-linear state variables and measurements. The core of the assignment involves the development of Matlab code, starting with the loading of a video file, initializing object positions, and setting up a foreground detector and blob analyzer. The code then implements a loop to process each frame of the video, detect foreground objects using color information, and apply Kalman filtering for tracking. The solution includes algorithms, Matlab code, and diagrams that illustrate the tracking process. The code also incorporates logic to handle object detection, correction, and prediction based on the Kalman filter's state, providing labels for tracked objects. Finally, the code addresses the handling of partial occlusions and the recovery of tracking IDs, demonstrating a robust approach to object tracking. The assignment demonstrates a comprehensive approach to object tracking, showcasing practical application of Kalman filters and blob analysis in a real-world scenario.
Document Page
Running head: PROGRAMMING AND OTHERS 0
PROGRAMMING AND OTHERS
Name of Student
Institution Affiliation
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
PROGRAMMING AND OTHERS 2
For tracking, we adopt EKF over linear Kalman filtering because most of the times the
state variables and measurements are not linear combination of state variables, inputs to the
system and noise. The key variables used in EKF were state estimate (k x ˆ) and measurement (k
z ) whose relation can be depicted in the figure below . This is the advance research of our
previous work so comprehensive explanation of EKF can be seen below
And from the above illustration diagram we can come up with algorithms to help come up with
the matlab codes (Corke, 2011).
Document Page
PROGRAMMING AND OTHERS 3
Algorithm 1
Algorithm 2
Algorithm 3
Document Page
PROGRAMMING AND OTHERS 4
With the above algorithms it will be very easy to develop the Matlab codes
Here is the basic program for detecting and tracking moving object from a video (Using colour
information). This program first loads the video "singleball.mp4" into workspace and then by
using kalman filtering and blob analysis, the moving ball is tracked (Corke, 2011).Therefore the
below are the matlab codes for object tracking using colour information.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
PROGRAMMING AND OTHERS 5
Matlab Program for Object Tracking:
// Showing the colour information ( video )
videoReader = vision.VideoFileReader('singleball.mp4');
//Initializing the positions of the objects to be tracked
videoPlayer = vision.VideoPlayer('Position',[100,100,500,400]);
foregroundDetector =
vision.ForegroundDetector('NumTrainingFrames',10,'InitialVariance',0.05);
// giving the condition or the boundary of tracking of the object, it is false if the minimum Blob
area is 70 m.
blobAnalyzer = vision.BlobAnalysis('AreaOutputPort',false,'MinimumBlobArea',70);
kalmanFilter = []; isTrackInitialized = false;
// Introducing a while loop for the video reader.
while ~isDone(videoReader)
colorImage = step(videoReader);
// Detecting the foreground object through colour image
foregroundMask = step(foregroundDetector, rgb2gray(colorImage));
detectedLocation = step(blobAnalyzer,foregroundMask);
isObjectDetected = size(detectedLocation, 1) > 0;
Document Page
PROGRAMMING AND OTHERS 6
if ~isTrackInitialized
if isObjectDetected
// If there is a constant acceleration of the moving object and the detected location within 25 or
10 tracks then the track initialized is correct ( the position of the object is correct).
kalmanFilter = configureKalmanFilter('ConstantAcceleration',detectedLocation(1,:), [1 1 1]*1e5,
[25, 10, 10], 25);
isTrackInitialized = true;
end
label = ''; circle = zeros(0,3);
else
if isObjectDetected
predict(kalmanFilter);
// And since it is located the label will be corrected (If was in wrong direction, it will be directed
to the required direction)
trackedLocation = correct(kalmanFilter, detectedLocation(1,:));
label = 'Corrected';
else
Document Page
PROGRAMMING AND OTHERS 7
// Therefore the location of the object is the predicted one.
trackedLocation = predict(kalmanFilter);
label = 'Predicted';
end
circle = [trackedLocation, 5];
end
colorImage = insertObjectAnnotation(colorImage,'circle',circle,label,'dominant Color','dominant
color');
Foreachforeground ;
Most Frequent color= Dominant color;
ForEvery Object A;
//New Dominance color is that color after demerging while Previous Dominant color is that color
before merging.
IFNewDominanceColor= PreviousDominantColor;
ElseIf SameAs A
Else NewObject B;
Step (videoPlayer,colorImage);
If( ObjectSizeInFrame J – ObjectSizeInFrame J-1>Threshold);
//The ID is stored if object size in frame J - object size In frame J-1> 1.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
PROGRAMMING AND OTHERS 8
StoredIDandDominantColorInMerged Array;
Else
BobDisapears;
StoreCenterPoint,DominatColorInPastObjectArray;
end
release(videoPlayer);
release(videoReader);
End // The execution of the program will end at this point
The above codes will thus help showing a good tracking of moving independent and partial
occluded objects. The direction of object was maintained to recover it’s tracking ID after partial
merging and past information for 10 frames to re-track object appearing after few frames by
STGMM. And this can be witnessed from the below diagrams
References
Document Page
PROGRAMMING AND OTHERS 9
Blake, A. (2012). Active Vision . London : Mit press.
Corke, P. (2011). Robotics, Vision and control : Fundermental Algorithms in MATLAB . Hull:
Springer
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]