sketch_3D_reconstruction.pde 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*The dataset is from
  2. *Computer Vision Group
  3. *TUM Department of Informatics Technical
  4. *University of Munich
  5. *https://vision.in.tum.de/data/datasets/rgbd-dataset/download#freiburg1_xyz
  6. */
  7. Scene scene;
  8. void setup() {
  9. size(640, 480, P3D);
  10. // default settings
  11. int frame_no = 0; // frame number
  12. float fov = PI / 3; // field of view
  13. int block_size = 8; // block size
  14. float normalizer = 5000.0f; // normalizer
  15. // initialize
  16. PointCloud point_cloud = new PointCloud();
  17. // synchronized rgb, depth and ground truth
  18. String head = "../data/";
  19. String[] rgb_depth_gt = loadStrings(head + "rgb_depth_groundtruth.txt");
  20. // read in rgb and depth image file paths as well as corresponding camera
  21. // posiiton and quaternion
  22. String[] info = split(rgb_depth_gt[frame_no], ' ');
  23. String rgb_path = head + info[1];
  24. String depth_path = head + info[3];
  25. float tx = float(info[7]), ty = float(info[8]),
  26. tz = float(info[9]); // real camera position
  27. float qx = float(info[10]), qy = float(info[11]), qz = float(info[12]),
  28. qw = float(info[13]); // quaternion
  29. // build transformer
  30. Transform trans =
  31. new Transform(tx, ty, tz, qx, qy, qz, qw, fov, width, height, normalizer);
  32. PImage rgb = loadImage(rgb_path);
  33. PImage depth = loadImage(depth_path);
  34. // generate point cloud
  35. point_cloud.generate(rgb, depth, trans);
  36. // initialize camera
  37. Camera camera = new Camera(fov, new PVector(0, 0, 0), new PVector(0, 0, 1),
  38. new PVector(0, 1, 0));
  39. // initialize motion field
  40. MotionField motion_field = new MotionField(block_size);
  41. // initialize scene
  42. scene = new Scene(camera, point_cloud, motion_field);
  43. }
  44. boolean inter = false;
  45. void draw() {
  46. background(0);
  47. // run camera dragged mouse to rotate camera
  48. // w: go forward
  49. // s: go backward
  50. // a: go left
  51. // d: go right
  52. // up arrow: go up
  53. // down arrow: go down
  54. //+ increase move speed
  55. //- decrease move speed
  56. // r: rotate the camera
  57. // b: reset to initial position
  58. scene.run(); // true: make interpolation; false: do not make
  59. // interpolation
  60. if (keyPressed && key == 'o') {
  61. inter = true;
  62. }
  63. scene.render(
  64. false); // true: turn on motion field; false: turn off motion field
  65. // save frame with no motion field
  66. scene.save("../data/frame/raw");
  67. background(0);
  68. scene.render(true);
  69. showGrids(scene.motion_field.block_size);
  70. // save frame with motion field
  71. scene.save("../data/frame/raw_mv");
  72. scene.saveMotionField("../data/frame/mv");
  73. }