diff --git a/readFlowFile.py b/readFlowFile.py index 7efaa08..4d0c7ba 100644 --- a/readFlowFile.py +++ b/readFlowFile.py @@ -26,7 +26,11 @@ def read(file): w = np.fromfile(f, np.int32, count=1) h = np.fromfile(f, np.int32, count=1) #if error try: data = np.fromfile(f, np.float32, count=2*w[0]*h[0]) - data = np.fromfile(f, np.float32, count=2*w*h) + try: #try first option + data = np.fromfile(f, np.float32, count=2*w*h) + except: + # if TypeError: only integer scalar arrays can be converted to a scalar index raise + data = np.fromfile(f, np.float32, count=2*w[0]*h[0]) # Reshape data into 3D array (columns, rows, bands) flow = np.resize(data, (int(h), int(w), 2)) f.close()