I am looking for full-time (applied) research opportunities in industry, involving (trustworthy and robust) machine learning or (3D) computer vision, starting early 2022. Check out my CV and get in touch on LinkedIn!


Optical Flow I/O with OpenCV

This article presents an OpenCV wrapper for the Flow I/O code provided by the Sintel dataset [2].


Recently, while implementing Efficient Hierarchical Graph-Based Video Segmentation, I needed to compare different algorithms for computing dense optical flow. While there are several optical flow benchmarks available online, for example the Middlebury benchmark [1], the Sintel benchmark [2] or the KITTI benchmark [3], I wanted to visualize the results first. After some attempts to visualize 2-channel optical flow images using OpenCV, guided by this StackOverflow question, I finally wrote a simple OpenCV wrapper for the C code provided by the Sintel dataset [2]. Note that the provided C code is based on imageLib, a lightweight C++ image library based on the StereoMatcher [4] code.

The code is available on GitHub:

OpenCV Flow I/O on GitHub


The code can be compiled using CMake (tested on Ubuntu 12.04, 14.04 and 14.10) and is based on OpenCV and Boost.

$ cd flow-io-opencv
$ mkdir build
$ cd build
$ cmake ..
$ make


The provided command line tool can be used to convert .flo files to .txt in cv::FileStorage format and optionally visualize the optical flow files:

$ ./cli/cli --help
Allowed options:
  --help                produce help message
  --input-dir arg       input directory
  --output-dir arg      output directory
  --vis-dir arg         visualize results in a separate directory

The wrapper can also be used to read .flo files into a cv::Mat or visualize optical flow available as 2-channel cv::Mat:

cv::Mat flow = FlowIOOpenCVWrapper::read(flo_file);
cv::Mat image = FlowIOOpenCVWrapper::flowToColor(flow);


The GitHub repository provides several frames on the alley_1 sequence and figure 1 shows a visualization:

Figure 1 (click to enlarge): Visualized optical flow from the alley_1 sequence.


  • [1] S. Baker, D. Scharstein, J. P. Lewis, S. Roth, M. J. Black, R. Szeliski. A Database and Evaluation Methodology for Optical Flow. International Journal of Computer Vision, volume 92, 2011.
  • [2] D. J. Butler, J. Wulff, G. B. Stanley, M. J. Black. A naturalistic open source movie for optical flow evaluation. European Conference on Computer Vision, 2012.
  • [3] M. Menze, A. Geiger. Object Scene Flow for Autonomous Vehicles. Conference on Computer Vision and Pattern Recognition, 2015.
  • [4] D. Scharstein, R. Szeliski. A taxonomy and evaluation of dense two-frame stereo correspondence algorithms. Technical Report MSR-TR-2001-81, Microsoft Research, 2001.

What is your opinion on this article? Did you find it interesting or useful? Let me know your thoughts in the comments below: