Ref:
http://vision.middlebury.edu/flow/code/flow-code/README.txt
http://www.it1352.com/481373.html
http://www.open-open.com/lib/view/open1453163505917.html
http://blog.csdn.net/junmuzi/article/details/75671572
See flowIO.cpp for sample code for reading and writing .flo files.
Here's an excerpt from this file describing the flow file format:
// ".flo" file format used for optical flow evaluation
//
// Stores 2-band float image for horizontal (u) and vertical (v) flow components.
// Floats are stored in little-endian order.
// A flow value is considered "unknown" if either |u| or |v| is greater than 1e9.
//
// bytes contents
//
// 0-3 tag: "PIEH" in ASCII, which in little endian happens to be the float 202021.25
// (just a sanity check that floats are represented correctly)
// 4-7 width as an integer
// 8-11 height as an integer
// 12-end data (width*height*2*4 bytes total)
// the float values for u and v, interleaved, in row order, i.e.,
// u[row0,col0], v[row0,col0], u[row0,col1], v[row0,col1], ...
//
Python:
# cat flo2xyflow.py
import numpy as npprint 'Specify a .flo file on the command line.'
=================================================
C:
#include "CCC/COMCV.h"
#include <fstream>
void writeFlow(Mat_<Point2f> &flow, string outpath)
{
ofstream out(outpath, ios_base::binary);
string tag = "PIEH";//文件标志
out.write(tag.c_str(), tag.size());
out.write((const char*)(&flow.cols), sizeof(int));//行数
out.write((const char*)(&flow.rows), sizeof(int));//列数
for (int i = 0; i < flow.rows; i++)
for (int j = 0; j < flow.cols; j++)
{
out.write((const char*)(&flow(i, j).x), sizeof(float));
out.write((const char*)(&flow(i, j).y), sizeof(float));
}
}
void readFlow(Mat_<Point2f> &flow, string path)
{
ifstream in(path, ios_base::binary);
string tag(4, '0');//文件标志
in.read((char*)tag.data(), 4);
int rows, cols;
in.read((char*)(&cols), sizeof(int));//行数
in.read((char*)(&rows), sizeof(int));//列数
flow.create(rows, cols);
for (int i = 0; i < flow.rows; i++)
for (int j = 0; j < flow.cols; j++)
{
in.read((char*)(&(flow(i, j).x)), sizeof(float));
in.read((char*)(&(flow(i, j).y)), sizeof(float));
}
}