Optical flow is the motion of objects between the consecutive frames of the sequence, caused by the relative motion between the camera and the object. It can be of two types-Sparse Optical flow and Dense Optical flow.
Dense Optical flow
Dense Optical flow computes the optical flow vector for every pixel of the frame which may be responsible for its slow speed but leading to a better accurate result. It can be used for detecting motion in the videos, video segmentation, learning structure from motion. There can be various kinds of implementations of dense optical flow. The example below will follow the Farneback method along with OpenCV.
The first step is that the method approximates the windows of image frames by a quadratic polynomial with the help of the polynomial expansion transform. Next, by observing how the polynomial transforms under the state of motion. i.e. to estimate displacement fields. Dense optical flow is computed, after a series of refinements.
For OpenCV’s implementation, the magnitude and direction of optical flow from a 2-D channel array of flow vectors are computed for the optical flow problem. The angle (direction) of flow by hue is visualized and the distance (magnitude) of flow by the value of HSV color representation. The strength of HSV is always set to a maximum of 255 for optimal visibility.
The method defined is caclopticalFlowFarneback() .
Below is the implementation.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python OpenCV: Optical Flow with Lucas-Kanade method
- OpenCV - The Gunnar-Farneback optical flow
- Mahotas - Getting SURF Dense Points
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Transition from OpenCV 2 to OpenCV 3.x
- Python | Reading contents of PDF using OCR (Optical Character Recognition)
- Draw Control Flow Graph using pycfg | Python
- PyQt5 QListWidget - Setting its Flow
- PyQt5 QListWidget - Getting its Flow
- Opencv Python program for Face Detection
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- OpenCV Python Program to analyze an image using Histogram
- Detection of a specific color(blue here) using OpenCV with Python
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Erosion and Dilation of images using OpenCV in python
- Line detection in python with OpenCV | Houghline method
- Template matching using OpenCV in Python
- Addition and Blending of images using OpenCV in Python
- Reading an image in OpenCV using Python
- Python | Play a video in reverse mode using OpenCV
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.