项目作者: max-krichenbauer

项目描述 :
Stereo Depth Reconstruction from a pair of stereo color images.
高级语言: C
项目地址: git://github.com/max-krichenbauer/SteDeR.git
创建时间: 2019-07-20T01:01:45Z
项目社区:https://github.com/max-krichenbauer/SteDeR

开源协议:GNU General Public License v3.0

下载


SteDeR

Stereo Depth Reconstruction from a pair of stereo color images, implemented as a single C++ header file, both CPU and GPU implementation.

The library is intended for live video stream Augmented Reality, and therefore optimized for highest processing speed, not for an optimal result.

Illustration

Contents:

  • steder.h CPU-based implementation using SIMD / SSE instructions for maximum performance.
  • steder_gl.h GPU-based implementations using OpenGL (implemented as a shader for maximum compatibility).
  • steder_cl.h GPU-based implementation using OpenCL.

steder.h

Stereo color image depth reconstruction on the CPU, using Intel SSE SIMD instruction and an optimized memory layout for high performance.

The whole code is included in the single header file.

Just create a SteDeR object, initialize it with init(image_width, image_height, disparity_limit) where disparity_limit is the maximum pixel disparity (relative to image width) that you wish to allow, and use the () operator on the SteDeR object to receive floating point depth buffers.

Usage example:

  1. // Load color stereo images
  2. unsigned char *left_image, *right_image;
  3. left_image = load_image("C:/path/to/image/left.png");
  4. right_image = load_image("C:/path/to/image/right.png");
  5. // Create and initialize SteDeR
  6. SteDeR s;
  7. int error = s.init(left_width,left_height, 0.2f);
  8. if(error) {
  9. printf("Failed to initialize SteDeR (%i).\n",error);
  10. return -1;
  11. }
  12. // Allocate depth buffers
  13. float* zL = (float*) malloc(left_width * left_height * sizeof(float));
  14. float* zR = (float*) malloc(left_width * left_height * sizeof(float));
  15. // Perform depth reconstruction
  16. s(left_image, right_image, zL, zR);

steder_gl.h

Stereo color image depth reconstruction on the GPU by using OpenGL shaders.

The whole code is included in the single header file. steder.h is not required.

SteDeR_GL uses OpenGL shaders (GLSL) to calculate the depth from the stereo image pair on the GPU by rendering it to a OpenGL floating point render target.

This is very handy if you wish to use the depth buffer for later rendering. For example to insert virtual 3DCG objects into a stereo video stream such as a video see-through AR HMD.

Note that you need have an intialized OpenGL rendering contect for running SteDeR_GL.

Usage example:

  1. // Load color stereo images
  2. unsigned char *left_image, *right_image;
  3. left_image = load_image("C:/path/to/image/left.png");
  4. right_image = load_image("C:/path/to/image/right.png");
  5. // Initialize OpenGL context:
  6. int argc = 0;
  7. glutInit(&argc, 0);
  8. glutInitWindowPosition(0, 0);
  9. glutInitWindowSize(left_width,left_height);
  10. glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
  11. int window = glutCreateWindow("StDeR - Test");
  12. glewInit();
  13. // Prepare textures and render targets:
  14. GLuint framebuffer_left, framebuffer_right;
  15. GLuint framebuffer_left_tex, framebuffer_right_tex;
  16. GLuint depthbuffer_left, depthbuffer_right;
  17. GLuint depthbuffer_left_tex, depthbuffer_right_tex;
  18. glActiveTexture(GL_TEXTURE0);
  19. genFramebuffer(framebuffer_left, framebuffer_left_tex, depthbuffer_left, depthbuffer_left_tex, left_width, left_height);
  20. genFramebuffer(framebuffer_right, framebuffer_right_tex, depthbuffer_right, depthbuffer_right_tex, left_width, left_height);
  21. glBindTexture(GL_TEXTURE_2D, framebuffer_left_tex);
  22. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, left_width, left_height, 0, GL_RGB, GL_UNSIGNED_BYTE, left_img);
  23. glBindTexture(GL_TEXTURE_2D, framebuffer_right_tex);
  24. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, left_width, left_height, 0, GL_RGB, GL_UNSIGNED_BYTE, right_img);
  25. // Create SteDeR_GL object and set the textures and render targets:
  26. SteDeRGL s;
  27. s.imgL.fb = framebuffer_left;
  28. s.imgR.fb = framebuffer_right;
  29. s.imgL.tx = framebuffer_left_tex;
  30. s.imgR.tx = framebuffer_right_tex;
  31. s.imgL.vp.x = s.imgR.vp.x = 0;
  32. s.imgL.vp.y = s.imgR.vp.y = 0;
  33. s.imgL.vp.w = s.imgR.vp.w = left_width;
  34. s.imgL.vp.h = s.imgR.vp.h = left_height;
  35. int error = s.init(image_width, image_height, 0.2f);
  36. if (error) {
  37. printf("Failed to initialize SteDeRGL (%i).\n",error);
  38. return -1;
  39. }
  40. // Execute stereo depth reconstruction:
  41. error = s();
  42. // Optional: download the depth buffers from the GPU:
  43. glBindTexture(GL_TEXTURE_2D, depthbuffer_left_tex);
  44. glGetTexImage(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, GL_FLOAT, zL);
  45. glBindTexture(GL_TEXTURE_2D, depthbuffer_right_tex);
  46. glGetTexImage(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, GL_FLOAT, zR);

steder_cl.h

Stereo color image depth reconstruction on the GPU by using OpenGL shaders.

The whole code is included in the single header file. steder.h is not required.

SteDeR_CL requires OpenCL.

Usage example:

  1. // Load images and allocate depth buffers:
  2. unsigned char *left_img, *right_img;
  3. left_img = load_image("C:/path/to/images/left.png");
  4. right_img = load_image("C:/path/to/images/right.png");
  5. float* zL = (float*) malloc(image_width * image_height * sizeof(float));
  6. float* zR = (float*) malloc(image_width * image_height * sizeof(float));
  7. // Create and initialize SteDeR CL object:
  8. SteDeRCL s;
  9. int error = s.init(image_width, image_height, 0.2f);
  10. if (error) {
  11. printf("Failed to initialize SteDeRCL (%i).\n",error);
  12. return -1;
  13. }
  14. // Perform depth reconstruction:
  15. error = s(left_img, right_img, zL,zR);