-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathcomposeDepth.m
157 lines (121 loc) · 6.32 KB
/
composeDepth.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
function composeDepth( depth_path, normal_path, normal_weight_path, dataset, output_path, param )
%COMPOSEDEPTH Generate complete depth from DNN estimation
depth2depth_path = '../gaps/bin/x86_64/depth2depth';
switch dataset
case 'realsense'
if ~exist(output_path,'dir')
mkdir(output_path);
end
test_files = dir([normal_path '/*_normal_est.h5']);
raw_depth_path_pattern = [depth_path '/%s/%s_depth_open.png'];
normal_path_pattern = [normal_path '/%s_%s_normal_est.h5'];
for a = 1:length(test_files)
tmp = regexp(test_files(a).name, '_', 'split');
fprintf('>>>>>%d/%d<<<<<<<\n', a, length(test_files));
input_depth_png = sprintf(raw_depth_path_pattern, tmp{1}, tmp{2});
input_normal_h5 = sprintf(normal_path_pattern, tmp{1}, tmp{2});
for b = 1:size(param,1)
output_depth_png = sprintf('%s/%s_%s_%d.png', output_path, tmp{1}, tmp{2}, b);
cmd = sprintf('%s %s %s -xres %f -yres %f -fx %f -fy %f -cx %f -cy %f -inertia_weight %f -smoothness_weight %f', ...
depth2depth_path, input_depth_png, output_depth_png, ...
320, 240, 308.331, 308.331, 165.7475, 119.8889, ...
param(b,1), param(b,2));
if ~isempty(normal_path)
cmd = sprintf('%s -tangent_weight %f -input_normals %s', cmd, param(b,3), input_normal_h5);
end
if ~isempty(normal_weight_path)
cmd = sprintf('%s -input_tangent_weight %s/%s_%s_weight.png', cmd, normal_weight_path, tmp{1}, tmp{2});
end
system(cmd);
end
end
case 'scannet'
raw_root = depth_path;
list = '../torch/data_list/scannet_test_list_small.txt';
fp = fopen(list);
tmp = textscan(fp, '%s');
test_data_name = tmp{1};
fclose(fp);
sid = cell(length(test_data_name),1);
vidc = cell(length(test_data_name),1);
vidd = cell(length(test_data_name),1);
for a = 1:length(test_data_name)
tmp = regexp(test_data_name{a}, '/', 'split');
sid{a} = tmp{1};
vidc{a} = tmp{3};
vidd{a} = strrep(vidc{a}, '_suffix', '');
end
raw_depth_path_pattern = [raw_root '/%s/depth/%s.png'];
normal_path_pattern = [result_root normal_path '/%s_%s_normal_est.h5'];
if ~exist(output_path,'dir')
mkdir(output_path);
end
save([output_path '/param.mat'], 'param', 'raw_root', 'normal_path', 'normal_weight_path');
load('scannettestcamera.mat');
testcamera = scannettestcamera;
for a = 1:length(test_data_name)
fprintf('>>>>>%d/%d<<<<<<<\n', a, length(test_data_name));
input_depth_png = sprintf(raw_depth_path_pattern, sid{a}, vidd{a});
input_normal_h5 = sprintf(normal_path_pattern, sid{a}, vidc{a});
for b = 1:size(param,1)
output_depth_png = sprintf('%s/%s_%s_%d.png', output_path, sid{a}, vidc{a}, b);
cmd = sprintf('%s %s %s -xres %f -yres %f -fx %f -fy %f -cx %f -cy %f -inertia_weight %f -smoothness_weight %f', ...
depth2depth_path, input_depth_png, output_depth_png, ...
testcamera(b,1), testcamera(b,2), testcamera(b,3), testcamera(b,4), testcamera(b,5), testcamera(b,6), ...
param(b,1), param(b,2));
if ~isempty(normal_path)
cmd = sprintf('%s -normal_weight %f -input_normals %s', cmd, param(b,3), input_normal_h5);
end
if ~isempty(normal_weight_path)
cmd = sprintf('%s -input_normal_weight %s/%s_%s_weight.png', cmd, normal_weight_path, sid{a}, vidc{a});
end
system(cmd);
end
end
case 'mp_render'
raw_root = depth_path;
list = '../torch/data_list/mp_test_list_horizontal.txt';
fp = fopen(list);
tmp = textscan(fp, '%s');
test_data_name = tmp{1};
fclose(fp);
sid = cell(length(test_data_name),1);
vidc = cell(length(test_data_name),1);
vidd = cell(length(test_data_name),1);
for a = 1:length(test_data_name)
tmp = regexp(test_data_name{a}, '/', 'split');
sid{a} = tmp{1};
vidc{a} = tmp{3}(1:end-4);
vidd{a} = strrep(vidc{a}, '_i', '_d');
end
raw_depth_path_pattern = [raw_root '/%s/undistorted_depth_images/%s.png'];
normal_path_pattern = [normal_path '/%s_%s_normal_est.h5'];
if ~exist(output_path,'dir')
mkdir(output_path);
end
save([output_path '/param.mat'], 'param', 'depth_path', 'normal_path', 'normal_weight_path');
load('matterporttestcamera.mat');
testcamera = testcamera;
for a = 1:length(test_data_name)
fprintf('>>>>>%d/%d<<<<<<<\n', a, length(test_data_name));
input_depth_png = sprintf(raw_depth_path_pattern, sid{a}, vidd{a});
input_normal_h5 = sprintf(normal_path_pattern, sid{a}, vidd{a});
for b = 1:size(param,1)
output_depth_png = sprintf('%s/%s_%s_%d.png', output_path, sid{a}, vidd{a}, b);
cmd = sprintf('%s %s %s -xres %f -yres %f -fx %f -fy %f -cx %f -cy %f -inertia_weight %f -smoothness_weight %f', ...
depth2depth_path, input_depth_png, output_depth_png, ...
testcamera(b,1), testcamera(b,2), testcamera(b,3), testcamera(b,4), testcamera(b,5), testcamera(b,6), ...
param(b,1), param(b,2));
if ~isempty(normal_path)
cmd = sprintf('%s -normal_weight %f -input_normals %s', cmd, param(b,3), input_normal_h5);
end
if ~isempty(normal_weight_path)
cmd = sprintf('%s -input_normal_weight %s/%s_%s_weight.png', cmd, normal_weight_path, sid{a}, vidd{a});
end
system(cmd);
end
end
otherwise
fprintf('Unknown dataset!\n');
end
end