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