-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptical_flow.m
70 lines (42 loc) · 1.36 KB
/
optical_flow.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
% reading video
videoReader = vision.VideoFileReader('viptrain.avi','ImageColorSpace','Intensity','VideoOutputDataType','uint8');
% videoReader = vision.VideoFileReader('xylophone.mp4','ImageColorSpace','Intensity','VideoOutputDataType','uint8');
% covert into images
converter = vision.ImageDataTypeConverter;
% optical flow application
opticalFlow = vision.OpticalFlow('ReferenceFrameDelay', 1);
opticalFlow.OutputValue = 'Horizontal and vertical components in complex form';
if 0
opticalFlow.Method = 'Lucas-Kanade';
opticalFlow.NoiseReductionThreshold = 0.001;
else
opticalFlow.Method = 'Horn-Schunck';
opticalFlow.Smoothness = 0.5;
end
frame = step(videoReader);
figure
subplot(121)
himg = imshow(frame);
subplot(122)
hof = imshow(frame);
while ~isDone(videoReader)
frame = step(videoReader);
im = step(converter, frame);
im=imresize(im, [128,256]);
for j=1:7
Img=im(1:128,1+64*(j-1)-32*(j-1): 64*j-32*(j-1),:);
if (SVMClassification(Img)==1)
k=1+64*(j-1)-32*(j-1);
rect = [k, 1, 64, 128];
rgb = [255, 0 , 0];
thickness = 3;
H=drawBox(frame, rect, rgb, thickness);
end
end
of = step(opticalFlow,H);
ofI = computeColor(real(of), imag(of));
set(himg, 'cdata', frame)
set(hof, 'cdata', ofI)
drawnow
end
release(videoReader);