MCPcopy Create free account
hub / github.com/DragonisCV/RAM / flowwrite

Function flowwrite

ram/utils/flow_util.py:45–73  ·  view source on GitHub ↗

Write optical flow to file. If the flow is not quantized, it will be saved as a .flo file losslessly, otherwise a jpeg image which is lossy but of much smaller size. (dx and dy will be concatenated horizontally into a single image if quantize is True.) Args: flow (ndarray):

(flow, filename, quantize=False, concat_axis=0, *args, **kwargs)

Source from the content-addressed store, hash-verified

43
44
45def flowwrite(flow, filename, quantize=False, concat_axis=0, *args, **kwargs):
46 """Write optical flow to file.
47
48 If the flow is not quantized, it will be saved as a .flo file losslessly,
49 otherwise a jpeg image which is lossy but of much smaller size. (dx and dy
50 will be concatenated horizontally into a single image if quantize is True.)
51
52 Args:
53 flow (ndarray): (h, w, 2) array of optical flow.
54 filename (str): Output filepath.
55 quantize (bool): Whether to quantize the flow and save it to 2 jpeg
56 images. If set to True, remaining args will be passed to
57 :func:`quantize_flow`.
58 concat_axis (int): The axis that dx and dy are concatenated,
59 can be either 0 or 1. Ignored if quantize is False.
60 """
61 if not quantize:
62 with open(filename, 'wb') as f:
63 f.write('PIEH'.encode('utf-8'))
64 np.array([flow.shape[1], flow.shape[0]], dtype=np.int32).tofile(f)
65 flow = flow.astype(np.float32)
66 flow.tofile(f)
67 f.flush()
68 else:
69 assert concat_axis in [0, 1]
70 dx, dy = quantize_flow(flow, *args, **kwargs)
71 dxdy = np.concatenate((dx, dy), axis=concat_axis)
72 os.makedirs(os.path.dirname(filename), exist_ok=True)
73 cv2.imwrite(filename, dxdy)
74
75
76def quantize_flow(flow, max_val=0.02, norm=True):

Callers

nothing calls this directly

Calls 1

quantize_flowFunction · 0.85

Tested by

no test coverage detected