-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvid_socialDistancing.m
48 lines (41 loc) · 1.54 KB
/
vid_socialDistancing.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
[filename,pathname]=uigetfile('*.*','Select the Input Video');
filewithpath=strcat(pathname,filename);
%I = imread(filewithpath);
videoReader = vision.VideoFileReader(filewithpath);
videoPlayer = vision.VideoPlayer('Position',[300 100 1200 500]);
detector = peopleDetectorACF('caltech-50x21');
%detector = peopleDetectorACF();
%writeObj = VideoWriter('New1.avi');
%writeObj.FrameRate = 8;
%open(writeObj);
while ~isDone(videoReader)
frame = step(videoReader);
I=double(frame);
[bboxes,scores] = detect(detector,I);
cond = zeros(size(bboxes,1),1);
if ~isempty(bboxes)
for i=1:(size(bboxes,1)-1)
for j=(i+1):(size(bboxes,1)-1)
dis1_v = abs(bboxes(i,1)+bboxes(i,3)-bboxes(j,1));
dis2_v = abs(bboxes(j,1)+bboxes(j,3)-bboxes(i,1));
dis1_h = abs(bboxes(i,2)-bboxes(j,2));
dis2_h = abs(bboxes(i,2)+bboxes(i,4)-bboxes(j,2)-bboxes(j,4));
if((dis1_v<75 || dis2_v<75) && (dis1_h<50 || dis2_h<50))
cond(i)=cond(i)+1;
cond(j)=cond(j)+1;
else
cond(i)=cond(i)+0;
end
end
end
end
I = insertObjectAnnotation(I,'rectangle',bboxes((cond>0),:),'danger','color','r');
I = insertObjectAnnotation(I,'rectangle',bboxes((cond==0),:),'safe','color','g');
step(videoPlayer,I);
%frame = im2frame(I);
%writeVideo(writeObj,frame);
end
release(videoReader);
release(videoPlayer);
%close(writeObj);
%save frames to video