Optical flow is a critical concept in computer vision, describing the motion of objects across a sequence of images. It quantifies displacement as a vector field where each vector represents the movement of points from one frame to the next. This repository contains a C++ implementation of the Horn-Schunck algorithm, which is used to compute optical flow by minimizing a global energy functional, leading to a solution of a system of partial differential equations.
Optical flow has applications in:
- Video compression
- Object tracking
- Autonomous driving
- Robotics
The Horn-Schunck algorithm focuses on minimizing an energy function which can be described by a set of partial differential equations. A finite difference discretization approach is used for practical computation.
- Read image sequence: Utilizes the CImg library to load image data.
- Compute image derivatives: Combines images into a 3D structure to compute gradients.
- Construct matrices A and b: Forms part of a linear equation system from the discrete versions of the partial differential equations.
- Solve the linear system: Uses the Eigen library to solve for the optical flow vectors.
- Extract and process the flow vectors (u, v): Retrieves the flow vectors from the solution and processes them (normalization and quantization).
- C++ compiler
- CImg library for image processing
- Eigen library for solving linear algebra problems
-
Clone the repository: git clone Optical-Flow-Horn-Schunck
-
Ensure the CImg and Eigen libraries are included in your project or install them: sudo apt-get install cimg-dev sudo apt-get install libeigen3-dev
To run the program: cd [project-directory] g++ -o optical_flow main.cpp -lX11 -lpthread ./optical_flow
Below are examples of optical flow vectors u
and v
computed from a given image sequence:
Contributions to enhance or extend the functionality are welcome. Please fork the repository and submit a pull request.