.flo文件读写与转换

1. 光流图像转numpy

import numpy as np

def load_flow_to_numpy(path):
    with open(path, 'rb') as f:
        magic = np.fromfile(f, np.float32, count=1)
        assert (202021.25 == magic), 'Magic number incorrect. Invalid .flo file'
        h = np.fromfile(f, np.int32, count=1)[0]
        w = np.fromfile(f, np.int32, count=1)[0]
        data = np.fromfile(f, np.float32, count=2 * w * h)
    data2D = np.resize(data, (w, h, 2))
    return data2D


if __name__ == '__main__':
    flo = load_flow_to_numpy('frame_0001.flo')
    print(flo.shape)  # (436, 1024, 2)

2. 光流图像转图像

import numpy as np
from matplotlib.colors import hsv_to_rgb
import matplotlib.pyplot as plt

def load_flow_to_numpy(path):
    with open(path, 'rb') as f:
        magic = np.fromfile(f, np.float32, count=1)
        assert (202021.25 &#

你可能感兴趣的:(光流估计,深度学习)