Git Product home page Git Product logo

3dreconstruction's Introduction

3D reconstruction

3D reconstruction from 2D images pipeline

Steps:

  1. Detect 2D points
  2. Match 2D points across 2 images
  3. Epipolar geometry
    3a. If both intrinsic and extrinsic camera parameters are known, reconstruct with projection matrices.
    3b. If only the intrinsic parameters are known, normalize coordinates and calculate the essential matrix.
    3c. If neither intrinsic nor extrinsic parameters are known, calculate the fundamental matrix.
  4. With fundamental or essential matrix, assume P1 = [I 0] and calulate parameters of camera 2.
  5. Triangulate knowing that x1 = P1 * X and x2 = P2 * X.
  6. Bundle adjustment to minimize reprojection errors and refine the 3D coordinates.

Note: Steps and code in this repo is my hobby / learning exercise. Ie, its probably not very efficient. If you wish to use a more production-ready library, check out OpenCV's SFM module. I have a docker environment for it at: https://github.com/alyssaq/reconstruction

Prerequisites

Example 3D cube reconstruction

$ python3 cube_reconstruction.py

Example Dino 3D reconstruction from 2D images

Download images from https://www.robots.ox.ac.uk/~vgg/data/mview/ and place into imgs/dinos

$ python3 example.py

Detected points and matched across 2 images.

3D reconstructed dino with essential matrix

3D to 2D Projection

$ python3 camera.py

3D points of model house from Oxford University VGG datasets.

Projected points

Datasets

References

License

MIT

3dreconstruction's People

Contributors

alyssaq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

3dreconstruction's Issues

Current OpenCV version do not support SIFT

Current OpenCV versions do not support SIFT.

python3 example.py

returns

Traceback (most recent call last): File "example.py", line 90, in <module> points1, points2, intrinsic = dino() File "example.py", line 68, in dino pts1, pts2 = features.find_correspondence_points(img1, img2) File "/content/3Dreconstruction/features.py", line 6, in find_correspondence_points sift = cv2.xfeatures2d.SIFT_create() cv2.error: OpenCV(3.4.3) /io/opencv_contrib/modules/xfeatures2d/src/sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'

Is it possible to get the real coordinates of the dino?

Since the result of the 3D reconstructed points of dino with essential matrix seems unlikely the real world coordinates, and the steps include assuming P1 = [I 0], I wonder is it possible to get the real coordinates by the code provided here? If not, what else do I require to reconstruct the accurate world coordinates by two images or even more(through sfm)?

NO it(a difference in data points normalization)

in structure.py
def scale_and_translate_points(points): …… x = points[0] y = points[1] center = points.mean(axis=1) # mean of each row cx = x - center[0] # center the points cy = y - center[1] dist = np.sqrt(np.power(cx, 2) + np.power(cy, 2)) scale = np.sqrt(2) / dist.mean()
Here, computation of scale is different from reference http://ece631web.groups.et.byu.net/Lectures/ECEn631%2013%20-%208%20Point%20Algorithm.pdf

I am sorry that I make a mistake

sample image

The image download site in the sample is closed, where else can I download it?

FileMissing

when i ran the example.py,an error ocurred

Traceback (most recent call last):
File "/home/ben/PyProjects/3Dreconstruction/example.py", line 9, in
import features
ImportError: No module named 'features'

it seems like the features.py is missing

more images

Is it possible to use three or more images reconstruct an object?

[BUG] A path bug concerning the image folder

Hello @alyssaq , there is a small bug concerning the image folder. In the README.md, readers are told to put images under imgs/dino, but a better one is imgs/dinos. Otherwise, the path bug would cause the interruption.

The repository is awesome and I have stared it. Thanks a lot!

How to perform triangulation without intrinsic matrix?

As far as procedure is concerned, if the intrinsic is not available, the fundamental matrix will be calculated. However, recording the examples, all intrinsic matrices are required. May I ask how to use those examples without intrinsic matrices?

alueError: shapes (3,3) and (1,1) not aligned: 3 (dim 1) != 1 (dim 0)

Hi, just tried out python3 cube_reconstruction.py and got:

True essential matrix: [[matrix([[0.]]) matrix([[-1.]]) matrix([[0.]])]
 [matrix([[-0.361547]]) matrix([[0.]]) matrix([[-3.14154162]])]
 [matrix([[0.]]) matrix([[3.]]) matrix([[0.]])]]
Computed essential matrix: [[-4.85388477e-05 -1.00000000e+00 -4.21762070e-04]
 [-3.62391216e-01 -3.38325541e-02 -3.14887717e+00]
 [ 1.45616543e-04  3.00000000e+00  1.26528621e-03]]
True fundamental matrix: [[matrix([[0.]]) matrix([[-1.11111111e-05]]) matrix([[0.00166667]])]
 [matrix([[-4.01718887e-06]]) matrix([[0.]]) matrix([[-0.00986923]])]
 [matrix([[0.00060258]]) matrix([[0.01166667]]) matrix([[-0.26961594]])]]
Traceback (most recent call last):
  File "cube_reconstruction.py", line 119, in <module>
    print('Computed fundamental matrix:', (F * true_F[2][2]))
  File "/home/zangetsu/proj/prometheus-core/demo/demo-20-3dreconstruction-flame/3Dreconstruction/venv3/lib/python3.6/site-packages/numpy/matrixlib/defmatrix.py", line 226, in __rmul__
    return N.dot(other, self)
ValueError: shapes (3,3) and (1,1) not aligned: 3 (dim 1) != 1 (dim 0)

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.