-
Notifications
You must be signed in to change notification settings - Fork 16
/
compute_horizon.m
69 lines (53 loc) · 1.57 KB
/
compute_horizon.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
function compute_horizon(imageList, out_dir, opt)
%
% imagesList: cell array storing image pathes
% out_dir: output directory
% opt: option for horizon line detector.
%
% output directory
if ~exist(out_dir, 'dir'); mkdir(out_dir); end
N = numel(imageList);
%% set up parameters
LSD_BIN_ = 'assets/lsd/lsd';
disp('loading network...')
caffe.reset_all();
caffe.set_mode_cpu();
net = caffe.Net('assets/models/deploy.net', 'assets/models/googlenet_places.caffemodel', 'test');
for ix = 1:N
%
% extract line segments
%
im = imread(imageList{ix});
[seglines, temp_dir] = extract_linesegment(im, LSD_BIN_);
fprintf('extracting LS: %d / %d\n', ix, N);
%
% extract context with CNN
%
deep = extract_context_with_cnn(im, net);
fprintf('extracting context: %d / %d\n', ix, N);
% detect horizon line
xres = size(im, 2);
yres = size(im, 1);
focal = max(xres, yres) / 2; % fake focal length
[horizon_homo, stat] = horizon_detector(seglines, xres, yres, focal, deep, opt);
hor = homo2img(horizon_homo, xres, yres, focal);
left = hor(1,:); right = hor(2,:);
prediction.name = imageList{ix};
prediction.im_sz = [yres, xres];
prediction.left = left;
prediction.right = right;
prediction.left_cnn = deep.left_cnn;
prediction.right_cnn = deep.right_cnn;
prediction.deep = deep;
prediction.stat = stat;
fprintf('detecting horizon: %d / %d\n', ix, N);
%
% save the predictions
%
save_path = sprintf('%s/%04d.mat', out_dir, ix);
save(save_path, 'prediction')
end
%% clean up
if exist(temp_dir, 'dir')
system(['rm -r ' temp_dir]);
end