write optical flow to file. Supports flo (Sintel), png (KITTI) and npy (numpy) file format. flow: optical flow with shape height x width x 2. Invalid values should be represented as np.nan filepath: file path where to write the flow
(flow, filepath)
| 38 | |
| 39 | |
| 40 | def writeFlowFile(flow, filepath): |
| 41 | """write optical flow to file. Supports flo (Sintel), png (KITTI) and npy (numpy) file format. |
| 42 | flow: optical flow with shape height x width x 2. Invalid values should be represented as np.nan |
| 43 | filepath: file path where to write the flow |
| 44 | """ |
| 45 | if not filepath: |
| 46 | raise ValueError("writeFlowFile: empty filepath") |
| 47 | |
| 48 | if len(flow.shape) != 3 or flow.shape[2] != 2: |
| 49 | raise IOError( |
| 50 | f"writeFlowFile {filepath}: expected shape height x width x 2 but received {flow.shape}" |
| 51 | ) |
| 52 | |
| 53 | if flow.shape[0] > flow.shape[1]: |
| 54 | print( |
| 55 | f"write flo file {filepath}: Warning: Are you writing an upright image? Expected shape height x width x 2, got {flow.shape}" |
| 56 | ) |
| 57 | |
| 58 | if filepath.endswith(".flo"): |
| 59 | return writeFloFlow(flow, filepath) |
| 60 | elif filepath.endswith(".png"): |
| 61 | return writePngFlow(flow, filepath) |
| 62 | elif filepath.endswith(".npy"): |
| 63 | return writeNpyFile(flow, filepath) |
| 64 | elif filepath.endswith(".flo5"): |
| 65 | return writeFlo5File(flow, filepath) |
| 66 | else: |
| 67 | raise ValueError(f"writeFlowFile: Unknown file format for {filepath}") |
| 68 | |
| 69 | |
| 70 | def readFloFlow(filepath): |
nothing calls this directly
no test coverage detected