| 1 |
import os.path as osp |
| 2 |
|
| 3 |
import numpy as np |
| 4 |
|
| 5 |
from ..._io import imread |
| 6 |
|
| 7 |
here = osp.dirname(osp.abspath(__file__)) |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
def read_flow(filename): |
| 13 |
"""Read .flo file in Middlebury format""" |
| 14 |
|
| 15 |
with open(filename, "rb") as f: |
| 16 |
magic = np.fromfile(f, np.float32, count=1) |
| 17 |
if magic != 202021.25: |
| 18 |
raise IOError("Invalid .flo file: {}".format(filename)) |
| 19 |
|
| 20 |
w = np.fromfile(f, np.int32, count=1)[0] |
| 21 |
h = np.fromfile(f, np.int32, count=1)[0] |
| 22 |
flow_uv = np.fromfile(f, np.float32, count=2 * w * h) |
| 23 |
|
| 24 |
flow_uv = np.resize(flow_uv, (h, w, 2)) |
| 25 |
return flow_uv |
| 26 |
|
| 27 |
|
| 28 |
def middlebury(): |
| 29 |
|
| 30 |
|
| 31 |
rgb_file = osp.join(here, "grove3.png") |
| 32 |
rgb = imread(rgb_file) |
| 33 |
|
| 34 |
flow_file = osp.join(here, "grove3.flo") |
| 35 |
flow = read_flow(flow_file) |
| 36 |
|
| 37 |
data = {"rgb": rgb, "flow": flow} |
| 38 |
return data |