forked from tehret/blind-denoising
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadFlowFile.py
More file actions
34 lines (26 loc) · 1.14 KB
/
readFlowFile.py
File metadata and controls
34 lines (26 loc) · 1.14 KB
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
# compute colored image to visualize optical flow file .flo
# According to the matlab code of Deqing Sun and c++ source code of Daniel Scharstein
# Contact: dqsun@cs.brown.edu
# Contact: schar@middlebury.edu
# Author: Johannes Oswald, Technical University Munich
# Contact: johannes.oswald@tum.de
# Date: 26/04/2017
# For more information, check http://vision.middlebury.edu/flow/
import numpy as np
import os
TAG_FLOAT = 202021.25
def read_flow(file):
assert type(file) is str, "file is not str %r" % str(file)
assert os.path.isfile(file) is True, "file does not exist %r" % str(file)
assert file[-4:] == '.flo', "file ending is not .flo %r" % file[-4:]
f = open(file,'rb')
flo_number = np.fromfile(f, np.float32, count=1)[0]
assert flo_number == TAG_FLOAT, 'Flow number %r incorrect. Invalid .flo file' % flo_number
w = np.fromfile(f, np.int32, count=1)
h = np.fromfile(f, np.int32, count=1)
data = np.fromfile(f, np.float32, count=2*w[0]*h[0])
#if error try: data = np.fromfile(f, np.float32, count=2*w*h)
# Reshape data into 3D array (columns, rows, bands)
flow = np.resize(data, (int(h), int(w), 2))
f.close()
return flow