import_reconstruction.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <opencv2/sfm.hpp>
  2. #include <opencv2/viz.hpp>
  3. #include <iostream>
  4. using namespace std;
  5. using namespace cv;
  6. using namespace cv::sfm;
  7. static void help() {
  8. cout
  9. << "\n---------------------------------------------------------------------------\n"
  10. << " This program shows how to import a reconstructed scene in the \n"
  11. << " OpenCV Structure From Motion (SFM) module.\n"
  12. << " Usage:\n"
  13. << " example_sfm_import_reconstruction <path_to_file>\n"
  14. << " where: file_path is the absolute path file into your system which contains\n"
  15. << " the reconstructed scene. \n"
  16. << "---------------------------------------------------------------------------\n\n"
  17. << endl;
  18. }
  19. int main(int argc, char* argv[])
  20. {
  21. /// Read input parameters
  22. if ( argc != 2 ) {
  23. help();
  24. exit(0);
  25. }
  26. /// Immport a reconstructed scene
  27. vector<Mat> Rs, Ts, Ks, points3d;
  28. importReconstruction(argv[1], Rs, Ts, Ks, points3d, SFM_IO_BUNDLER);
  29. /// Create 3D windows
  30. viz::Viz3d window("Coordinate Frame");
  31. window.setWindowSize(Size(500,500));
  32. window.setWindowPosition(Point(150,150));
  33. window.setBackgroundColor(); // black by default
  34. /// Create the pointcloud
  35. vector<Vec3d> point_cloud;
  36. for (int i = 0; i < points3d.size(); ++i){
  37. point_cloud.push_back(Vec3f(points3d[i]));
  38. }
  39. /// Recovering cameras
  40. vector<Affine3d> path;
  41. for (size_t i = 0; i < Rs.size(); ++i)
  42. path.push_back(Affine3d(Rs[i], Ts[i]));
  43. /// Create and show widgets
  44. viz::WCloud cloud_widget(point_cloud, viz::Color::green());
  45. viz::WTrajectory trajectory(path, viz::WTrajectory::FRAMES, 0.5);
  46. viz::WTrajectoryFrustums frustums(path, Vec2f(0.889484, 0.523599), 0.5,
  47. viz::Color::yellow());
  48. window.showWidget("point_cloud", cloud_widget);
  49. window.showWidget("cameras", trajectory);
  50. window.showWidget("frustums", frustums);
  51. /// Wait for key 'q' to close the window
  52. cout << endl << "Press 'q' to close each windows ... " << endl;
  53. window.spin();
  54. return 0;
  55. }