3d-scanner.cpp 908 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <librealsense2/rs.hpp>
  2. #include <iostream>
  3. int main(int argc, char *argv[])
  4. try
  5. {
  6. rs2::pointcloud pc;
  7. rs2::points points;
  8. rs2::pipeline pipe;
  9. pipe.start();
  10. auto frames = pipe.wait_for_frames();
  11. auto color = frames.get_color_frame();
  12. // For cameras that don't have RGB sensor, we'll map the pointcloud to infrared instead of color
  13. if (!color)
  14. color = frames.get_infrared_frame();
  15. pc.map_to(color);
  16. auto depth = frames.get_depth_frame();
  17. points = pc.calculate(depth);
  18. points.export_to_ply("test.ply", color);
  19. return EXIT_SUCCESS;
  20. }
  21. catch (const rs2::error &e)
  22. {
  23. std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
  24. return EXIT_FAILURE;
  25. }
  26. catch (const std::exception &e)
  27. {
  28. std::cerr << e.what() << std::endl;
  29. return EXIT_FAILURE;
  30. }