Git Product home page Git Product logo

pytorch-eight-point-algorithm-essential-matrix's Introduction

Eight-Point Essential Matrix Estimation with PyTorch

This Python script implements the eight-point algorithm for estimating the essential matrix from corresponding points in two images, using the power of PyTorch for efficient numerical computations both in CPU and GPU. The essential matrix is a fundamental component in computer vision, used for tasks such as stereo vision, structure from motion, and camera calibration.

Table of Contents

Introduction

The eight-point algorithm is a widely used method for estimating the essential matrix, which encodes the geometric relationship between two camera views of a scene. Given corresponding points in two images and camera matrices, the algorithm computes the essential matrix that describes the relative pose between the two camera views.

This algorithm is implemented in Python using the PyTorch library for efficient numerical computations, enabling seamless execution on both GPUs and CPUs.

This figure provides an illustration of epipolar lines being computed across two images for a given collection of matching points:

Image

Image

This graph depicts the relationship between time and the quantity of points, showcasing the PyTorch implementation on both CPU and GPU, alongside the OpenCV cv.findEssentialMat using the method=cv.LMEDS. The exclusion of OpenCV cv.findEssentialMat with method=cv.RANSAC is due to its partial utilization of points.

Image

Evidently, the PyTorch implementations on both CPU and GPU exhibit swifter performance compared to the OpenCV cv.findEssentialMat when employing the method=cv.LMEDS. Notably, as the number of points escalates, the execution time on CPU experiences a significant surge, whereas the GPU execution time remains relatively stable. It is noteworthy that the GPU implementation aligns with the CPU counterpart after approximately 1000 sets of corresponding points.

Requirements

To run this script, you need:

  • Python 3.x
  • PyTorch
  • Numpy

Usage

To use the eight_point_essential_matrix function, follow these steps:

  1. Copy the eight_point_essential_matrix function from the provided script.

  2. Call the function with appropriate inputs:

    img1_points = ...  # Corresponding points in image 1 (N x 2)
    img2_points = ...  # Corresponding points in image 2 (N x 2)
    camera_1_matrix = ...  # Camera matrix for image 1 (3 x 3)
    camera_2_matrix = ...  # Camera matrix for image 2 (3 x 3)
    
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    result = eight_point_essential_matrix(img1_points, img2_points, camera_1_matrix, camera_2_matrix, device=device)
  3. The result will be a dictionary containing the estimated essential matrix and normalized epipoles for both images.

  4. For a practical demonstration of invoking this function and subsequently computing as well as visualizing epipolar lines, please refer to the run.py script.

pytorch-eight-point-algorithm-essential-matrix's People

Contributors

farhad-dalirani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.