Git Product home page Git Product logo

dense-optical-flow's Introduction

Dense-Optical-Flow

Big thanks to Adrian Rosebrock for the tutorial.
The goal is to calculate dense optical flow for a video with moving cars using Gunnar Farneback algorithm.

Initial video was taken from here

alt text

Prepare the video and read first frame

For working with video and images OpenCV will be used.
First of all, we will create a VideoCapture object and read first frame.
Input video can be of different sizes, so we have to resize it.
Also, it is useful to create a mask (will be used later in HSV format) and set it's saturation to maximum value.

Calculate dense optical flow for subsequent frames

While video is playing, we will read frames each 10 ms.
Each read frame should be converted to gray scale format and resized.
The actual calculation will be performed by cv2.calcOpticalFlowFarneback()
You can find more info about this function in opencv documentation If you want to read more about algorithm we will use, please, refer to Two-Frame Motion Estimation Based on Polynomial Expansion paper
We also need to calculate magnitude and angle of 2D vectors, using cv2.cartToPolar().
Then we apply these values to the mask, so we could have different colors for different colors for different movement direction.
Finally, we will combine mask and initial frame to get dense optical flow image.
alt text

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.