Giter Club home page Giter Club logo

cuda-sfm's Introduction

Project 4 SfM on CUDA

University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 0

  • Name: Vaibhav Arcot
  • Tested on: Windows 10, i7-7700HQ @ 2.8GHz (3.8 Boost) 32GB, External GTX 1080Ti, 11G (My personal laptop)
  • Worked on this project with Dewang Sultania(@Iron-Stark)

Overview

Structure from motion is the process of extracting a rotation and translation from an pair of images. Using this relative rotation and translation, we can then reproject the pixels into 3d points (without scale) to generate crude 3d meshes. The main contribution of this repo is to have the entire pipeline done on the GPU, making it faster if doing a large number of images. This repo is a learning exercise. Use at your own risk

Features Implemented (besides vanilla SfM)

  • RANSAC for the Essential matrix estimation
  • 3D Visualization

Dependencies

  • Cuda 10+
  • cubasl (matrix multiplication)
  • cusolve (most Linear algebra)
  • opengl (visualization)
  • CudaSift (SIFT)
  • Thrust (max_element)
  • Opencv (to load images)

Pipeline

  • Sift and matches between the images were handled by CudaSift, which we had to integrate.
  • Transform points to camera used the camera intrinsic matrix to reproject the points
  • Estimate essential matrix used RANSAC to filter the candidate essential matrices (using the 8 point algorithm) to find the matrix that resulted in the maximum number of inliers. This process randomly shuffles the data, so it will result in different candidate matrices each time.
  • Next, 4 candidate projection matrices are calculated (because we do not have enough information to get the exact one).
  • To choose the correct projection matrix, we can transform a single point and check if it lies in front of both cameras. If it does, we found our projection matrix.
  • Finally, we use linear reprojection to convert the points from 2d images into 3d points. This results in the 3d point cloud.
  • To perform the visualization, we modified the boid code (link) to plot a point cloud and have the ability to color them (if we choose to do so in the future).

Results

To test our algorithm, we decided to run our code on the 3d dinosaur model. The raw images are shown below. Below that are some reconstructions that were created. There is a tradeoff when picking 2 images, we found that if the images are taken from a similar angle, more points were matched but it was harder to see the final 3d model. The flip side is that we don't match as many points so our model ends up looking not as dense as it should. Bundle adjustment would solve this but is way outside the scope of this assignment. The image looks mostly 2d except for the legs which have some depth to them.

dino1

The stray points in the image are from the fact that we did not filter the points using a homograph to find outlier matches. This would result in a cleaner appearance.

For time metrics, below is shown the various stages and the time they take on this GPU version. It is clear from below that the majority of the time is spend in the estimate essential matrix, which is performing RANSAC. This can be improved by writing a more efficient SVD computation (or converting the code to a column major standard).

Thoughts

  • We took on way way way too much work. This project turned into a fight against the CUDA API because of its limitations to do linear algebra functions on kernel functions as well as convention issues (row major vs column major).
  • The other issue we faced was getting
  • If we had more time, there are a bunch of things that would be easy to do, such as coloring points using the pixel colors, but due to time limitations once we actually got the code up add running, these weren't explored.

Future work

  • Limit on RANSAC iterations (currently a fixed value)
  • Visualization of color
  • Bundle adjustment
  • Improve SVD performance

Bloopers

  • This project had a ton of issues to complete. No screenshots though because we get the visualization stage done in the last few hours. Many many hours were lost to get a working SVD (semi working but good enough for our use case because we care only about a subset of the components).

Work division (high level)

Work Vaibhav Dewang
CudaSift
3x3 linear algebra (SVD, inverse, matmul)
Batched linear algebra (SVD, inverse, matmul)
Estimating E Matrix
RANSAC
Compute pose candidates
Choose correct pose
Linear Triangulation
Visualization

References

Some important references were

cuda-sfm's People

Contributors

black-phoenix 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

Watchers

 avatar  avatar

cuda-sfm's Issues

Error in building with makefile

I installed all the dependencies but when I try to compile and run the program I get this error below are the error logs

cd build && /usr/bin/cmake -DCMAKE_BUILD_TYPE=Release .. && make)
-- Found CUDA: /usr/local/cuda (found suitable version "11.6", minimum required is "10")
CMake Warning (dev) at /usr/share/cmake-3.16/Modules/FindOpenGL.cmake:275 (message):
Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when
available. Run "cmake --help-policy CMP0072" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.

FindOpenGL found both a legacy GL library:

OPENGL_gl_LIBRARY: /usr/lib/x86_64-linux-gnu/libGL.so

and GLVND libraries for OpenGL and GLX:

OPENGL_opengl_LIBRARY: /usr/lib/x86_64-linux-gnu/libOpenGL.so
OPENGL_glx_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLX.so

OpenGL_GL_PREFERENCE has not been set to "GLVND" or "LEGACY", so for
compatibility with CMake 3.10 and below the legacy GL library will be used.
Call Stack (most recent call first):
CMakeLists.txt:17 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.

-- Found CUDA: /usr/local/cuda (found version "11.6")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cloudlabgpu1/Downloads/CUDA-SfM-master
make[1]: Entering directory '/home/cloudlabgpu1/Downloads/CUDA-SfM-master/build'
make[2]: Entering directory '/home/cloudlabgpu1/Downloads/CUDA-SfM-master/build'
make[3]: Entering directory '/home/cloudlabgpu1/Downloads/CUDA-SfM-master/build'
make[3]: Leaving directory '/home/cloudlabgpu1/Downloads/CUDA-SfM-master/build'
[ 38%] Built target cudaSift
make[3]: Entering directory '/home/cloudlabgpu1/Downloads/CUDA-SfM-master/build'
[ 46%] Building NVCC (Device) object SfM/CMakeFiles/SfM.dir/SfM_generated_sfm.cu.o
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:4:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/kernels.h:19: warning: "enable_debug" redefined
19 | #define enable_debug false
|
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:3:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/common.h:41: note: this is the location of the previous definition
41 | #define enable_debug true
|
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:30:42: error: macro "checkCUDAError" passed 2 arguments, but takes just 1
30 | checkCUDAErrorWithLine("Malloc failed!");
| ^
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:3:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/common.h:18: note: macro "checkCUDAError" defined here
18 | #define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, LINE)
|
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:32:42: error: macro "checkCUDAError" passed 2 arguments, but takes just 1
32 | checkCUDAErrorWithLine("Malloc failed!");
| ^
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:3:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/common.h:18: note: macro "checkCUDAError" defined here
18 | #define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, LINE)
|
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:110:44: error: macro "checkCUDAError" passed 2 arguments, but takes just 1
110 | checkCUDAErrorWithLine("A malloc failed!");
| ^
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:3:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/common.h:18: note: macro "checkCUDAError" defined here
18 | #define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, LINE)
|
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:113:40: error: macro "checkCUDAError" passed 2 arguments, but takes just 1
113 | checkCUDAErrorWithLine("Kron failed!");
| ^
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:3:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/common.h:18: note: macro "checkCUDAError" defined here
18 | #define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, LINE)
|
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:275:38: error: macro "checkCUDAError" passed 2 arguments, but takes just 1
275 | checkCUDAErrorWithLine("Before SVD");
| ^
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:3:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/common.h:18: note: macro "checkCUDAError" defined here
18 | #define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, LINE)
|
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:279:31: error: macro "checkCUDAError" passed 2 arguments, but takes just 1
279 | checkCUDAErrorWithLine("SVD");
| ^
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:3:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/common.h:18: note: macro "checkCUDAError" defined here
18 | #define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, LINE)
|
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:376:54: error: macro "checkCUDAError" passed 2 arguments, but takes just 1
376 | checkCUDAErrorWithLine("Not copyBoidsToVBO failed!");
| ^
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:3:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/common.h:18: note: macro "checkCUDAError" defined here
18 | #define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, LINE)
|
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:380:50: error: macro "checkCUDAError" passed 2 arguments, but takes just 1
380 | checkCUDAErrorWithLine("copyBoidsToVBO failed!");
| ^
In file included from /home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/sfm.cu:3:
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/SfM/common.h:18: note: macro "checkCUDAError" defined here
18 | #define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, LINE)
|
CMake Error at SfM_generated_sfm.cu.o.cmake:206 (message):
Error generating
/home/cloudlabgpu1/Downloads/CUDA-SfM-master/build/SfM/CMakeFiles/SfM.dir//./SfM_generated_sfm.cu.o

make[3]: *** [SfM/CMakeFiles/SfM.dir/build.make:72: SfM/CMakeFiles/SfM.dir/SfM_generated_sfm.cu.o] Error 1
make[3]: Leaving directory '/home/cloudlabgpu1/Downloads/CUDA-SfM-master/build'
make[2]: *** [CMakeFiles/Makefile2:144: SfM/CMakeFiles/SfM.dir/all] Error 2
make[2]: Leaving directory '/home/cloudlabgpu1/Downloads/CUDA-SfM-master/build'
make[1]: *** [Makefile:106: all] Error 2
make[1]: Leaving directory '/home/cloudlabgpu1/Downloads/CUDA-SfM-master/build'
make: *** [GNUmakefile:19: Release] Error 2

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.