Expects a two dimensional flow image of shape. Args: flow_uv (np.ndarray): Flow UV image of shape [H,W,2] clip_flow (float, optional): Clip maximum of flow values. Defaults to None. convert_to_bgr (bool, optional): Convert output image to BGR. Defaults to False.
(flow_uv, clip_flow=None, convert_to_bgr=False)
| 107 | |
| 108 | |
| 109 | def flow_to_image(flow_uv, clip_flow=None, convert_to_bgr=False): |
| 110 | """ |
| 111 | Expects a two dimensional flow image of shape. |
| 112 | |
| 113 | Args: |
| 114 | flow_uv (np.ndarray): Flow UV image of shape [H,W,2] |
| 115 | clip_flow (float, optional): Clip maximum of flow values. Defaults to None. |
| 116 | convert_to_bgr (bool, optional): Convert output image to BGR. Defaults to False. |
| 117 | |
| 118 | Returns: |
| 119 | np.ndarray: Flow visualization image of shape [H,W,3] |
| 120 | """ |
| 121 | assert flow_uv.ndim == 3, 'input flow must have three dimensions' |
| 122 | assert flow_uv.shape[2] == 2, 'input flow must have shape [H,W,2]' |
| 123 | if clip_flow is not None: |
| 124 | flow_uv = np.clip(flow_uv, 0, clip_flow) |
| 125 | u = flow_uv[:,:,0] |
| 126 | v = flow_uv[:,:,1] |
| 127 | rad = np.sqrt(np.square(u) + np.square(v)) |
| 128 | rad_max = np.max(rad) |
| 129 | epsilon = 1e-5 |
| 130 | u = u / (rad_max + epsilon) |
| 131 | v = v / (rad_max + epsilon) |
| 132 | return flow_uv_to_colors(u, v, convert_to_bgr) |
nothing calls this directly
no test coverage detected