Coder Social home page Coder Social logo

sakshikakde / depth-using-stereo Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 1.0 203.11 MB

Python code to estimate depth using stereo vision.

Python 4.01% Jupyter Notebook 95.99%
stereo-vision depth-estimation vectorization feature-matching fundamental-matrix essential-matrix camera-pose-estimation image-rectification disparity-map computer-vision

depth-using-stereo's Introduction

Depth estimation using Stereo Cameras

Overview

CALIBRATION

1. Feature Detection and Matching

The result is obtained using the Brute-Force matcher in OpenCV. It can be seen that there are a few wrong matches obtained. These can affect the results. To filter these wrong feature pairs, we will use RANSAC in the next step.
alt text

2. Estimation of Fundamental Matrix and RANSAC

The fundamental matrix is calculated using the 8-point algorithm. If the F matrix estimation is good, then terms x T 2 .F.x 1 should be close to 0, where x 1 and x 2 are features from image1 and image2. Using this criterion, RANSAC can be used to filter the outliers.
alt text

3. Estimation of Essential Matrix

Since we know the camera calibration matrix, we can use it to obtain the essential matrix.

4. Estimation of Camera Pose

camera pose(R and C) can be estimated using the essential matrix E. We will be estimating the pose for camera 2 with respect to camera 1 which is assumed to be of world origin. We will get four solutions for which we will use the Chirality condition to choose the correct set.

RECTIFICATION

Using the fundamental matrix and the feature points, we can obtain the epipolar lines for both images. The epipolar lines need to be parallel for further computations to obtain depth. This can be done by reprojecting image planes onto a common plane parallel to the line between camera centers.
alt text

CORRESPONDENCE

For every pixel in image 1, we try to find a corresponding match along the epipolar line in image 2. We will consider a a window of a predefined size for this purpose, so this method is called block matching. Essentially, we will be taking a small region of pixels in the left image, and searching for the closest matching region of pixels in the right. Following methods can be used for block comparison:

  1. Sum of Absolute Differences (SAD)
  2. Sum of Squared Differences (SSD)
  3. Normalized Cross-Correlation (NCC)

Depth computation

1. Disparity Map

After we get the matching pixel location, the disparity can be found by take the absolute of the difference between the source and matched pixel location

alt-text-1 alt-text-1 alt-text-1

2. Depth Map

If we know the focal length(f) and basline(b), the depth can be calculated. alt-text-1 alt-text-1 alt-text-1

How to run the code

  • Change the location to the root directory
  • Run the following command:
python3 Code/stereo.py --DataPath ./Data/Project\ 3/Dataset\ 3 --DataNumber 3 

Parameters:

  1. DataPath: Absolute path where the images are located. Be careful about the spaces.
  2. DataNumber: The dataset number. used to choose the intrinsic parameters.

depth-using-stereo's People

Contributors

sakshikakde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  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.