Home | History | Annotate | Download | only in launching_viz
      1 Launching Viz {#tutorial_launching_viz}
      2 =============
      3 
      4 Goal
      5 ----
      6 
      7 In this tutorial you will learn how to
      8 
      9 -   Open a visualization window.
     10 -   Access a window by its name.
     11 -   Start event loop.
     12 -   Start event loop for a given amount of time.
     13 
     14 Code
     15 ----
     16 
     17 You can download the code from [here ](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/viz/launching_viz.cpp).
     18 @include samples/cpp/tutorial_code/viz/launching_viz.cpp
     19 
     20 Explanation
     21 -----------
     22 
     23 Here is the general structure of the program:
     24 
     25 -   Create a window.
     26     @code{.cpp}
     27     /// Create a window
     28     viz::Viz3d myWindow("Viz Demo");
     29     @endcode
     30 -   Start event loop. This event loop will run until user terminates it by pressing **e**, **E**,
     31     **q**, **Q**.
     32     @code{.cpp}
     33     /// Start event loop
     34     myWindow.spin();
     35     @endcode
     36 -   Access same window via its name. Since windows are implicitly shared, **sameWindow** is exactly
     37     the same with **myWindow**. If the name does not exist, a new window is created.
     38     @code{.cpp}
     39     /// Access window via its name
     40     viz::Viz3d sameWindow = viz::get("Viz Demo");
     41     @endcode
     42 -   Start a controlled event loop. Once it starts, **wasStopped** is set to false. Inside the while
     43     loop, in each iteration, **spinOnce** is called to prevent event loop from completely stopping.
     44     Inside the while loop, user can execute other statements including those which interact with the
     45     window.
     46     @code{.cpp}
     47     /// Event loop is over when pressed q, Q, e, E
     48     /// Start event loop once for 1 millisecond
     49     sameWindow.spinOnce(1, true);
     50     while(!sameWindow.wasStopped())
     51     {
     52         /// Interact with window
     53 
     54         /// Event loop for 1 millisecond
     55         sameWindow.spinOnce(1, true);
     56     }
     57     @endcode
     58 
     59 Results
     60 -------
     61 
     62 Here is the result of the program.
     63 
     64 ![](images/window_demo.png)
     65