Real-time optical flow with Matlab

Did you know that a fly cannot see real stereo? It sees two “images” that have only a small area of the same visual field. So the fly cannot estimate distances by using stereo images, it detects obstacles by “optical flow”. Optical flow is the perceived visual motion of objects as the observer (here the fly) moves relative to them.

I have experimented with optical flow code (based on Horn and Schunck’s optical flow algorithm) these days, and I could manage to visualize the optical flow with it in real-time using 100% Matlab code. The code uses a camera (320×240 pixels) for capturing real-time image frames, computes the optical flow field with the current and the last frame (also called image velocity field) and shows the field in the image.

Optical flow screenshot

The field is calculated for each pixel of the image. The angle of the arrow shows in which direction the specified pixel was moved, the distance shows how much that pixel did move.

How can this optical flow field be used? Well, you could e.g. use the field to estimate the distance to obstacles for a moving vehicle when mounted a camera on it. A nice approach of detecting obstacles for a robot vehicle :-)

Here’s the Matlab code to download (ovcam.zip).

4 comments for “Real-time optical flow with Matlab

  1. nasibe
    January 8, 2009 at 3:28 pm

    hi
    i want this matlab code and movie .
    tancks a lot

  2. May 2, 2009 at 5:37 pm

    Hi, netter Post aber wie adde ich den denn zu meinen RSS Feeds? Bin ich zu bloed?

  3. Jasim
    July 21, 2010 at 3:18 pm

    I need a video,Becoz I want to see the result.Becoz I write my own code.

  4. André Caron
    September 30, 2010 at 7:49 pm

    What parameters (alpha,iterations) do you use to achieve real-time computation?

Leave a Reply

Your email address will not be published. Required fields are marked *

IMPORTANT! To be able to proceed, please enter the magic word 'gendaa' so we know hat you are a human)

Enter the magic word:
Please leave these two fields as-is: