MCPcopy Create free account
hub / github.com/CUT3R/CUT3R / writeFlowFile

Function writeFlowFile

datasets_preprocess/flow_IO.py:40–67  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

38
39
40def 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
70def readFloFlow(filepath):

Callers

nothing calls this directly

Calls 5

writeFloFlowFunction · 0.85
writePngFlowFunction · 0.85
writeNpyFileFunction · 0.85
writeFlo5FileFunction · 0.70
printFunction · 0.50

Tested by

no test coverage detected