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)
| 26 | |
| 27 | |
| 28 | def writeFlow(filename, uv, v=None): |
| 29 | """ Write optical flow to file. |
| 30 | |
| 31 | If v is None, uv is assumed to contain both u and v channels, |
| 32 | stacked in depth. |
| 33 | Original code by Deqing Sun, adapted from Daniel Scharstein. |
| 34 | """ |
| 35 | nBands = 2 |
| 36 | |
| 37 | if v is None: |
| 38 | assert (uv.ndim == 3) |
| 39 | assert (uv.shape[2] == 2) |
| 40 | u = uv[:, :, 0] |
| 41 | v = uv[:, :, 1] |
| 42 | else: |
| 43 | u = uv |
| 44 | |
| 45 | assert (u.shape == v.shape) |
| 46 | height, width = u.shape |
| 47 | f = open(filename, 'wb') |
| 48 | # write the header |
| 49 | f.write(TAG_CHAR) |
| 50 | np.array(width).astype(np.int32).tofile(f) |
| 51 | np.array(height).astype(np.int32).tofile(f) |
| 52 | # arrange into matrix form |
| 53 | tmp = np.zeros((height, width * nBands)) |
| 54 | tmp[:, np.arange(width) * 2] = u |
| 55 | tmp[:, np.arange(width) * 2 + 1] = v |
| 56 | tmp.astype(np.float32).tofile(f) |
| 57 | f.close() |
nothing calls this directly
no outgoing calls
no test coverage detected