(fn)
Read .flo file in Middlebury format
Read .flo file in Middlebury format
Read . flo file in Middlebury format
def readFlow(fn):
    """ Read .flo file in Middlebury format"""
    # Code adapted from:
    # http://stackoverflow.com/questions/28013200/reading-middlebury-flow-files-with-python-bytes-array-numpy

    # WARNING: this will work on little-endian architectures (eg Intel x86) only!
    # print 'fn = %s'%(fn)
    with open(fn, 'rb') as f:
        magic = np.fromfile(f, np.float32, count=1)
        if 202021.25 != magic:
            print('Magic number incorrect. Invalid .flo file')
            return None
        else:
            w = np.fromfile(f, np.int32, count=1)
            h = np.fromfile(f, np.int32, count=1)
            # print 'Reading %d x %d flo file\n' % (w, h)
            data = np.fromfile(f, np.float32, count=2*int(w)*int(h))
            # Reshape data into 3D array (columns, rows, bands)
            # The reshape here is for visualization, the original code is (w,h,2)
            return np.resize(data, (int(h), int(w), 2))
def readFlow ( fn ) : # Code adapted from: # http://stackoverflow.com/questions/28013200/reading-middlebury-flow-files-with-python-bytes-array-numpy # WARNING: this will work on little-endian architectures (eg Intel x86) only! # print 'fn = %s'%(fn) with open ( fn , 'rb' ) as f : magic = np . fromfile ( f , np . float32 , count = 1 ) if 202021.25 != magic : print ( 'Magic number incorrect. Invalid .flo file' ) return None else : w = np . fromfile ( f , np . int32 , count = 1 ) h = np . fromfile ( f , np . int32 , count = 1 ) # print 'Reading %d x %d flo file\n' % (w, h) data = np . fromfile ( f , np . float32 , count = 2 * int ( w ) * int ( h ) ) # Reshape data into 3D array (columns, rows, bands) # The reshape here is for visualization, the original code is (w,h,2) return np . resize ( data , ( int ( h ) , int ( w ) , 2 ) )