-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathVideoDetection.m
50 lines (43 loc) · 1.4 KB
/
VideoDetection.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
clear;clc;close all;
vidObj = vision.VideoFileReader('TownCentreXVID.avi','VideoOutputDataType','uint8');
HeadDetector = vision.CascadeObjectDetector('Town2.xml'); % Finds faces by default
tracker = MultiObjectTrackerKLT;
frame = step(vidObj);
frameSize = size(frame);
bboxes = [];
while isempty(bboxes)
framergb = step(vidObj);
frame = rgb2gray(framergb);
bboxes = HeadDetector.step(frame);
end
tracker.addDetections(frame, bboxes);
%% And loop until the player is closed
frameNumber = 0;
keepRunning = true;
disp('Press Ctrl-C to exit...');
vid = VideoWriter('samp.avi');
vid.FrameRate = 25;
open(vid);
while ~isDone(vidObj)
framergb = step(vidObj);
frame = rgb2gray(framergb);
if mod(frameNumber, 5) == 0
bboxes = 1*HeadDetector.step(imresize(frame, 1));
if ~isempty(bboxes)
tracker.addDetections(frame, bboxes);
end
else
% Track faces
tracker.track(frame);
end
% fprintf('Count = %d \n',tracker.BoxIds);
% Display bounding boxes and tracked points.
displayFrame = insertObjectAnnotation(framergb, 'rectangle',...
tracker.Bboxes, tracker.BoxIds);
% displayFrame = insertMarker(displayFrame, tracker.Points);
% videoPlayer.step(displayFrame);
writeVideo(vid,displayFrame);
% imshow(displayFrame);
frameNumber = frameNumber + 1;
end
close(vid);