lizhihao6 / Forward-Warp

An optical flow forward warp's lib with backpropagation using pytorch.
MIT License
109 stars 17 forks source link

support flo file #6

Closed fjremnav closed 3 years ago

fjremnav commented 3 years ago

How do I use test.py with optical flow info from a .flo file instead of .pkl?

Thanks,

lizhihao6 commented 3 years ago
def read_flo_file(filename, memcached=False):
    """
    Read from Middlebury .flo file
    :param flow_file: name of the flow file
    :return: optical flow data in matrix
    """
    if memcached:
        filename = io.BytesIO(filename)
    f = open(filename, 'rb')
    magic = np.fromfile(f, np.float32, count=1)[0]
    data2d = None

    if 202021.25 != magic:
        print('Magic number incorrect. Invalid .flo file')
    else:
        w = np.fromfile(f, np.int32, count=1)[0]
        h = np.fromfile(f, np.int32, count=1)[0]
        data2d = np.fromfile(f, np.float32, count=2 * w * h)
        # reshape data into 3D array (columns, rows, channels)
        data2d = np.resize(data2d, (1, h, w, 2))
    f.close()
    np.save("xxx.pkl", data2d)
    return data2d
noobtoob4lyfe commented 2 years ago

Why did you close this? did you find a solution?