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)
| 91 | |
| 92 | |
| 93 | def flow_to_image(flow_uv, clip_flow=None, convert_to_bgr=False): |
| 94 | """ |
| 95 | Expects a two dimensional flow image of shape. |
| 96 | |
| 97 | Args: |
| 98 | flow_uv (np.ndarray): Flow UV image of shape [H,W,2] |
| 99 | clip_flow (float, optional): Clip maximum of flow values. Defaults to None. |
| 100 | convert_to_bgr (bool, optional): Convert output image to BGR. Defaults to False. |
| 101 | |
| 102 | Returns: |
| 103 | np.ndarray: Flow visualization image of shape [H,W,3] |
| 104 | """ |
| 105 | assert flow_uv.ndim == 3, 'input flow must have three dimensions' |
| 106 | assert flow_uv.shape[2] == 2, 'input flow must have shape [H,W,2]' |
| 107 | |
| 108 | if clip_flow is not None: |
| 109 | flow_uv = np.clip(flow_uv, 0, clip_flow) |
| 110 | |
| 111 | u = flow_uv[:,:,0] |
| 112 | v = flow_uv[:,:,1] |
| 113 | rad = np.sqrt(np.square(u) + np.square(v)) |
| 114 | rad_max = np.max(rad) |
| 115 | epsilon = 1e-5 |
| 116 | u = u / (rad_max + epsilon) |
| 117 | v = v / (rad_max + epsilon) |
| 118 | return flow_uv_to_colors(u, v, convert_to_bgr) |
| 119 | |
| 120 | |
| 121 |
nothing calls this directly
no test coverage detected