MCPcopy Create free account
hub / github.com/drinkingcoder/NeuralMarker / writeFlow

Function writeFlow

core/utils/frame_utils.py:70–99  ·  view source on GitHub ↗

Write optical flow to file. If v is None, uv is assumed to contain both u and v channels, stacked in depth. Original code by Deqing Sun, adapted from Daniel Scharstein.

(filename,uv,v=None)

Source from the content-addressed store, hash-verified

68 return data
69
70def writeFlow(filename,uv,v=None):
71 """ Write optical flow to file.
72
73 If v is None, uv is assumed to contain both u and v channels,
74 stacked in depth.
75 Original code by Deqing Sun, adapted from Daniel Scharstein.
76 """
77 nBands = 2
78
79 if v is None:
80 assert(uv.ndim == 3)
81 assert(uv.shape[2] == 2)
82 u = uv[:,:,0]
83 v = uv[:,:,1]
84 else:
85 u = uv
86
87 assert(u.shape == v.shape)
88 height,width = u.shape
89 f = open(filename,'wb')
90 # write the header
91 f.write(TAG_CHAR)
92 np.array(width).astype(np.int32).tofile(f)
93 np.array(height).astype(np.int32).tofile(f)
94 # arrange into matrix form
95 tmp = np.zeros((height, width*nBands))
96 tmp[:,np.arange(width)*2] = u
97 tmp[:,np.arange(width)*2 + 1] = v
98 tmp.astype(np.float32).tofile(f)
99 f.close()
100
101
102def readFlowKITTI(filename):

Callers 1

synthesis_dataFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected