-
Notifications
You must be signed in to change notification settings - Fork 9
/
depth_read.m
executable file
·57 lines (40 loc) · 1.34 KB
/
depth_read.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
function depth = depth_read(filename)
% Reads a depth file FILENAME into depth image DEPTH.
% Adapted from Deqing Sun and Daniel Scharstein's optical
% flow code.
% Copyright (c) 2015 Jonas Wulff
% Max Planck Institute for Intelligent Systems, Tuebingen, Germany.
TAG_FLOAT = 202021.25; % check for this when READING the file
% sanity check
if isempty(filename) == 1
error('depth_read: empty filename');
end;
idx = findstr(filename, '.');
idx = idx(end);
if length(filename(idx:end)) == 1
error('depth_read: extension required in filename %s', filename);
end;
if strcmp(filename(idx:end), '.dpt') ~= 1
error('depth_read: filename %s should have extension ''.dpt''', filename);
end;
fid = fopen(filename, 'r');
if (fid < 0)
error('depth_read: could not open %s', filename);
end;
tag = fread(fid, 1, 'float32');
width = fread(fid, 1, 'int32');
height = fread(fid, 1, 'int32');
% sanity check
if (tag ~= TAG_FLOAT)
error('depth_read(%s): wrong tag (possibly due to big-endian machine?)', filename);
end;
if (width < 1 || width > 99999)
error('depth_read(%s): illegal width %d', filename, width);
end;
if (height < 1 || height > 99999)
error('depth_read(%s): illegal height %d', filename, height);
end;
% arrange into matrix form
tmp = fread(fid, inf, 'float32');
depth = reshape(tmp, [width, height])';
fclose(fid);