MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / readFlow

Function readFlow

CV/PWCNet/data/utils/flow_utils.py:6–25  ·  view source on GitHub ↗

Read .flo file in Middlebury format

(fn)

Source from the content-addressed store, hash-verified

4
5
6def readFlow(fn):
7 """ Read .flo file in Middlebury format"""
8 # Code adapted from:
9 # http://stackoverflow.com/questions/28013200/reading-middlebury-flow-files-with-python-bytes-array-numpy
10
11 # WARNING: this will work on little-endian architectures (eg Intel x86) only!
12 # print 'fn = %s'%(fn)
13 with open(fn, 'rb') as f:
14 magic = np.fromfile(f, np.float32, count=1)
15 if 202021.25 != magic:
16 print('Magic number incorrect. Invalid .flo file')
17 return None
18 else:
19 w = np.fromfile(f, np.int32, count=1)
20 h = np.fromfile(f, np.int32, count=1)
21 # print 'Reading %d x %d flo file\n' % (w, h)
22 data = np.fromfile(f, np.float32, count=2 * int(w) * int(h))
23 # Reshape data into 3D array (columns, rows, bands)
24 # The reshape here is for visualization, the original code is (w,h,2)
25 return np.resize(data, (int(h), int(w), 2))
26
27
28def writeFlow(filename, uv, v=None):

Callers

nothing calls this directly

Calls 1

resizeMethod · 0.80

Tested by

no test coverage detected