MATLAB Answers

Cars detection and tracking

49 views (last 30 days)
Itai Kadosh
Itai Kadosh on 13 Jan 2017
Edited: Changoleon on 13 Jan 2017
Hi, I would like to track cars only (not peoples) on a video file, give them ID and to maintain the tracking on them for a few hours (as long as the vehicle is in the frame) even if the vehicle is standing without motion. I saw the Matlab examples "Detecting Cars Using Gaussian Mixture Models" and "Motion-Based Multiple Object Tracking", but the problem with this examples is the tracking is not maintained and the algorithm give every time new ID even if it was the same vehicle. in addition, how can I overcome the false alarms of the cars shadow as an objects? Thanks, Itai

Answers (1)

Changoleon
Changoleon on 13 Jan 2017
Edited: Changoleon on 13 Jan 2017
Hi, I have done something like this before. I'll try to help you.
VidObj = VideoReader('the name of your video');
nFrames = VidObj.NumberOfFrames;
for k = 1 : nFrames
video(:,:,k) = mean(read(VidObj,k),3);
end
start_number = ? %set the first frame
finis_number = ? %set the last frame
v2=video(:,:,start_number:finis_number); %the frames of interest (the part of the video that you want to study)
frame_1st= double(v2(:,:,1)); look at the first frame of interest as an image
figure; hold off;
imagesc(frame_1st); colormap gray; axis image
[xp,yp] = ginput(1); & use ginput to shoot at a location of the first frame that has a unique feature, this location will be for cross-correlation of the next frames
hold on; plot(xp,yp,'ro');
xp = round(xp);
yp = round(yp);
window=(v2(yp-6:yp+6,xp-6:xp+6,1)); %create a window around the point that you chose with ginput and form a new small image. This small image is a part of first image
template = window - mean(mean(window));
I'm sure you can start with this. Next you should create another template for the next frame and all other frames. Use a for loop to make it easier since I assume the number of frames will be high.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!