-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessVideo.m
110 lines (96 loc) · 3.12 KB
/
processVideo.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
warning('off','images:imshow:magnificationMustBeFitForDockedFigure')
%%
bak = imread('./data/test.bkgnd.png');
msk = ~zim2bw(bak);
msk_tight = imdilate(msk, strel('square',25));
%%
input_video = fullfile('./data', 'test1.avi');
disp('Opening video...')
vob = VideoReader(input_video); %A warning about being unable to read the number of frames is due to variable frame rate (normal)
frame = vob.read(inf); %Reads to end, takes a while, but now vob knows the number of frames
vidHeight = vob.Height;
vidWidth = vob.Width;
%%
writerObj = VideoWriter('processed.avi');
writerObj.FrameRate = 6;
open(writerObj);
tau = 0.05 * 3 / writerObj.FrameRate;
xx = 0:100:vob.Width;
makeVid = false;
nFrames = 4; 100*30;
k0 = 50*30 + 15;
bk_downsample = 30 / writerObj.FrameRate;
t = 0;
thetaHat = 20;
xsecHat = [1000, 400] ; %[vob.Width , vob.Height]/2;
if makeVid
figure('visible', 'off'); clf;
set(gcf,'Renderer','zbuffer');
else
figuren('test'); clf;
% figure('visible', 'off'); clf;
% set(gcf,'Renderer','zbuffer');
end
t2slope = @(t) tand(90 - t);
s2theta = @(s) 90 - atand(s);
hHist = [];
tHist = [];
for k = k0:bk_downsample:(nFrames+k0)
if k > 2600
break
end
t = t + bk_downsample/30;
tHist(end+1) = t;
img = gread(vob, k);
imshow(img); hold on;
try
[thetaList_rad, rhoList, xsecHatNew, allTheta_rad, allRho] = ...
findLines(img, thetaHat, msk, msk_tight, xsecHat, true);
figuren('test');
newTheta = mean(abs(thetaList_rad))*180/pi;
oldSearch = thetaHat;
slopeFilt = t2slope(thetaHat) + tau*(t2slope(newTheta) - t2slope(thetaHat));
thetaHat = thetaHat + 2*tau*(newTheta - thetaHat); %s2theta(slopeFilt);
zHat = theta2z(thetaList_rad);
title(sprintf('Altitude = %.1fft [theta = %.1fdeg search near %.1f -> %.1f]', ...
zHat, newTheta, oldSearch, thetaHat ));
col = 'red';
catch
col = 'blue';
end
hHist(end+1) = zHat;
if true
for i = 1:length(allTheta_rad)
tt = allTheta_rad(i);
ct = cos(tt); st = sin(tt);
yy = -ct/st * xx + allRho(i)/st;
plot(xx,yy,'--','LineWidth',1,'Color','green');
end
end
for i = 1:length(thetaList_rad)
tt = thetaList_rad(i);
ct = cos(tt); st = sin(tt);
yy = -ct/st * xx + rhoList(i)/st;
plot(xx,yy,'-','LineWidth',1,'Color',col);
end
plot([xsecHat(1), xsecHat(1)+50*sind(180-thetaHat)],...
[xsecHat(2), xsecHat(2)+50*cosd(180-thetaHat)], '-', 'MarkerSize', 10, 'Color', 'red');
plot(xsecHat(1), xsecHat(2), 'x', 'MarkerSize', 10, 'Color', 'red');
delete(findall(gcf,'Tag','altTag'));
annotation('textbox', [0.4,0.3,0.1,0.1],'Color','red',...
'String', sprintf('Altitude = %05.2fft', zHat),...
'Tag', 'altTag');
hold off;
if makeVid
frame = getframe;
writeVideo(writerObj,frame);
end
xsecHat = xsecHat + clip(0.05*(xsecHatNew-xsecHat), -100, 100);
end
close(writerObj);
%%
figuren('hHist'); plot(tHist, hHist, 'x--')
grid on
ylim([0, 200]);
xlabel('time(s)')
ylabel('altitude(ft)');