launching_viz.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @file launching_viz.cpp
  3. * @brief Launching visualization window
  4. * @author Ozan Cagri Tonkal
  5. */
  6. #include <opencv2/viz.hpp>
  7. #include <iostream>
  8. using namespace cv;
  9. using namespace std;
  10. /**
  11. * @function help
  12. * @brief Display instructions to use this tutorial program
  13. */
  14. static void help()
  15. {
  16. cout
  17. << "--------------------------------------------------------------------------" << endl
  18. << "This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. "
  19. << "You can access the same window via its name. You can run event loop for a given period of time. " << endl
  20. << "Usage:" << endl
  21. << "./launching_viz" << endl
  22. << endl;
  23. }
  24. /**
  25. * @function main
  26. */
  27. int main()
  28. {
  29. help();
  30. /// Create a window
  31. viz::Viz3d myWindow("Viz Demo");
  32. /// Start event loop
  33. myWindow.spin();
  34. /// Event loop is over when pressed q, Q, e, E
  35. cout << "First event loop is over" << endl;
  36. /// Access window via its name
  37. viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");
  38. /// Start event loop
  39. sameWindow.spin();
  40. /// Event loop is over when pressed q, Q, e, E
  41. cout << "Second event loop is over" << endl;
  42. /// Event loop is over when pressed q, Q, e, E
  43. /// Start event loop once for 1 millisecond
  44. sameWindow.spinOnce(1, true);
  45. while(!sameWindow.wasStopped())
  46. {
  47. /// Interact with window
  48. /// Event loop for 1 millisecond
  49. sameWindow.spinOnce(1, true);
  50. }
  51. /// Once more event loop is stopped
  52. cout << "Last event loop is over" << endl;
  53. return 0;
  54. }