From 8f8a89644eb4ca7f50854defbab923a764079f27 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Thu, 13 Apr 2023 03:04:19 +0200 Subject: [PATCH] documentation touch-ups --- modules/viz2d/samples/cpp/display_image.cpp | 9 ++++++--- modules/viz2d/samples/cpp/display_image_fb.cpp | 1 - modules/viz2d/samples/cpp/font_with_gui.cpp | 1 + modules/viz2d/samples/cpp/render_opengl.cpp | 4 +--- modules/viz2d/samples/cpp/vector_graphics.cpp | 2 ++ modules/viz2d/samples/cpp/vector_graphics_and_fb.cpp | 2 ++ modules/viz2d/samples/cpp/video_editing.cpp | 5 +++-- modules/viz2d/tutorials/00-intro.markdown | 9 +++++---- modules/viz2d/tutorials/01-dislay_image.markdown | 4 ++-- modules/viz2d/tutorials/02-vector_graphics.markdown | 2 +- modules/viz2d/tutorials/03-render_opengl.markdown | 2 +- modules/viz2d/tutorials/04-font_rendering.markdown | 2 +- modules/viz2d/tutorials/05-video_editing.markdown | 4 ++-- modules/viz2d/tutorials/06-font_with_gui.markdown | 2 +- 14 files changed, 28 insertions(+), 21 deletions(-) diff --git a/modules/viz2d/samples/cpp/display_image.cpp b/modules/viz2d/samples/cpp/display_image.cpp index 22f9d3e9b..da6ee3a6a 100644 --- a/modules/viz2d/samples/cpp/display_image.cpp +++ b/modules/viz2d/samples/cpp/display_image.cpp @@ -9,12 +9,15 @@ constexpr int HEIGHT = 720; int main() { //Creates a Viz2D object for on screen rendering Ptr v2d = Viz2D::make(Size(WIDTH, HEIGHT), "Show image"); - //An image Mat image = imread(samples::findFile("lena.jpg")); //Feeds the image to the video pipeline v2d->feed(image); - //Display the framebuffer in the native window in an endless loop - v2d->run(v2d->display); + + //Display the framebuffer in the native window in an endless loop. + //Viz2D::run() though it takes a functor is not a context. It is simply an abstraction + //of a run loop for portability reasons and executes the functor until the application + //terminates or the functor returns false. + v2d->run(v2d->display); } diff --git a/modules/viz2d/samples/cpp/display_image_fb.cpp b/modules/viz2d/samples/cpp/display_image_fb.cpp index 36417b39a..0d576c477 100644 --- a/modules/viz2d/samples/cpp/display_image_fb.cpp +++ b/modules/viz2d/samples/cpp/display_image_fb.cpp @@ -9,7 +9,6 @@ constexpr int HEIGHT = 720; int main() { //Creates a Viz2D object for on screen rendering Ptr v2d = Viz2D::make(Size(WIDTH, HEIGHT), "Show image"); - //Read an image as UMat UMat image = imread(samples::findFile("lena.jpg")).getUMat(ACCESS_READ); UMat resized; diff --git a/modules/viz2d/samples/cpp/font_with_gui.cpp b/modules/viz2d/samples/cpp/font_with_gui.cpp index 78fa68343..dcaa87fb3 100644 --- a/modules/viz2d/samples/cpp/font_with_gui.cpp +++ b/modules/viz2d/samples/cpp/font_with_gui.cpp @@ -38,6 +38,7 @@ int main(int argc, char** argv) { textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP); text(sz.width / 2.0, sz.height / 2.0, hw.c_str(), hw.c_str() + hw.size()); }); + //Display the framebuffer in the native window return v2d->display(); }); } diff --git a/modules/viz2d/samples/cpp/render_opengl.cpp b/modules/viz2d/samples/cpp/render_opengl.cpp index 1f71dbc68..26e9e36eb 100644 --- a/modules/viz2d/samples/cpp/render_opengl.cpp +++ b/modules/viz2d/samples/cpp/render_opengl.cpp @@ -27,9 +27,7 @@ int main(int argc, char** argv) { glRotatef(50, 1, 0, 0); glRotatef(70, 0, 1, 0); }); - //Viz2D::run() though it takes a functor is not a context. It is simply an abstraction - //of a run loop for portability reasons and executes the functor until the application - //terminates or the functor returns false. + v2d->run([=]() { v2d->gl([](const Size& sz) { //Render a tetrahedron using immediate mode because the code is more concise diff --git a/modules/viz2d/samples/cpp/vector_graphics.cpp b/modules/viz2d/samples/cpp/vector_graphics.cpp index ce425903d..668c5ac46 100644 --- a/modules/viz2d/samples/cpp/vector_graphics.cpp +++ b/modules/viz2d/samples/cpp/vector_graphics.cpp @@ -13,6 +13,8 @@ int main(int argc, char** argv) { v2d->nvg([](const Size& sz) { //Calls from this namespace may only be used inside a nvg context using namespace cv::viz::nvg; + + //Draws a cross hair beginPath(); strokeWidth(3.0); strokeColor(Scalar(0,0,255,255)); //BGRA diff --git a/modules/viz2d/samples/cpp/vector_graphics_and_fb.cpp b/modules/viz2d/samples/cpp/vector_graphics_and_fb.cpp index c65639783..e1a3b15e2 100644 --- a/modules/viz2d/samples/cpp/vector_graphics_and_fb.cpp +++ b/modules/viz2d/samples/cpp/vector_graphics_and_fb.cpp @@ -13,6 +13,8 @@ int main(int argc, char** argv) { v2d->nvg([](const Size& sz) { //Calls from this namespace may only be used inside a nvg context using namespace cv::viz::nvg; + + //Draws a cross-hair beginPath(); strokeWidth(3.0); strokeColor(Scalar(0,0,255,255)); //BGRA diff --git a/modules/viz2d/samples/cpp/video_editing.cpp b/modules/viz2d/samples/cpp/video_editing.cpp index 5f07a6f71..9a9ed02b2 100644 --- a/modules/viz2d/samples/cpp/video_editing.cpp +++ b/modules/viz2d/samples/cpp/video_editing.cpp @@ -20,6 +20,7 @@ int main(int argc, char** argv) { v2d->setSink(sink); v2d->run([=]() { + //Capture video from the Source if(!v2d->capture()) return false; //end of input video @@ -32,8 +33,8 @@ int main(int argc, char** argv) { textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP); text(sz.width / 2.0, sz.height / 2.0, hv.c_str(), hv.c_str() + hv.size()); }); - v2d->write(); //write the output video - return v2d->display(); //display the framebuffer in the native window + v2d->write(); //Write video to the Sink + return v2d->display(); //Display the framebuffer in the native window }); } diff --git a/modules/viz2d/tutorials/00-intro.markdown b/modules/viz2d/tutorials/00-intro.markdown index 38ee65587..433266c75 100644 --- a/modules/viz2d/tutorials/00-intro.markdown +++ b/modules/viz2d/tutorials/00-intro.markdown @@ -21,9 +21,9 @@ Please refer to the online demos in the following section to see at a glance wha * **OpenGL**: Easy access to OpenGL. * **GUI**: Simple yet powerful user interfaces through NanoGUI. * **Vector graphics**: Elegant and fast vector graphics through NanoVG. -* **Font rendering**: Loading of TTF-fonts and sophisticated rendering options. -* **Video pipeline**: Through a simple Source/Sink system videos can be displayed, edited and saved. -* **Hardware acceleration**: Automatic hardware acceleration usage where possible. (e.g. CL-GL sharing and VAAPI). Actually it is possible to write programs that run almost entirely on the GPU, given driver-features are available. +* **Font rendering**: Loading of fonts and sophisticated rendering options. +* **Video pipeline**: Through a simple Source/Sink system videos can be efficently displayed, edited and saved. +* **Hardware acceleration**: Transparent hardware acceleration usage where possible. (e.g. CL-GL sharing and VAAPI). Actually it is possible to write programs that run almost entirely on the GPU, given driver-features are available. * **No more highgui** with it's heavy dependencies, licenses and limitations. * **WebAssembly support**. @@ -39,6 +39,7 @@ Please note that the following online demos are slower and/or have less features * Viz2D is not thread safe. Though it is possible to have several Viz2D objects in one or more threads and synchronize them using ```Viz2D::makeNonCurrent()``` and ```Viz2D::makeCurrent()```. This is a limitation of GLFW3. That said, OpenCV algorithms are multi-threaded as usual. * Viz2D uses InputArray/OutputArray/InputOutputArray which gives you the option to work with Mat, std::vector and UMat. Anyway, you should prefer to use UMat whenever possible to automatically use hardware capabilities where available. * Access to different subsystems (opengl, framebuffer, nanovg and nanogui) is provided through "contexts". A context is simply a function that takes a functor, sets up the subsystem, executes the functor and tears-down the subsystem. +* ```Viz2D::run``` is not a context. It is an abstraction of a run loop that takes a functor and runs until the application terminates or the functor returns false. This is necessary for portability reasons. * Contexts ***may not*** be nested. For example, to create an OpenGL context and set the GL viewport: @@ -79,7 +80,7 @@ The tutorials are designed to be read one after the other to give you a good ove * \ref viz2d_font_with_gui # Samples -The goal of the samples is to show how to use Viz2D to the fullest. Also they show how to use Viz2D in conjunction with interop options to create programs that run mostly (the part the matters) on the GPU. They are also a good starting point for your own applications because they touch many key aspects and algorithms of OpenCV. +The goal of the samples is to show how to use Viz2D to the fullest. Also they show how to use Viz2D to create programs that run mostly (the part the matters) on the GPU (when driver capabilities allow). They are also a good starting point for your own applications because they touch many key aspects and algorithms of OpenCV. * \ref viz2d_tetra * \ref viz2d_video diff --git a/modules/viz2d/tutorials/01-dislay_image.markdown b/modules/viz2d/tutorials/01-dislay_image.markdown index 25cfd4432..e1e79a6f7 100644 --- a/modules/viz2d/tutorials/01-dislay_image.markdown +++ b/modules/viz2d/tutorials/01-dislay_image.markdown @@ -1,4 +1,4 @@ -# Display an image using Viz2D {#viz2d_display_image} +# Display an Image {#viz2d_display_image} @prev_tutorial{viz2d} @next_tutorial{viz2d_vector_graphics} @@ -9,7 +9,7 @@ | Compatibility | OpenCV >= 4.7 | ## Using the video pipeline -Actually there are two ways to display an image using Viz2D. The most convenient way is to use the video pipeline system to feed an image into Viz2D. That has the advantage that the image is automatically resized (keeping aspect ratio) to framebuffer size and color converted (The framebuffer is BGRA). +Actually there are two ways to display an image using Viz2D. The most convenient way is to use the video pipeline to feed an image to Viz2D. That has the advantage that the image is automatically resized (preserving aspect ratio) to framebuffer size and color converted (the framebuffer is BGRA). @include samples/cpp/display_image.cpp diff --git a/modules/viz2d/tutorials/02-vector_graphics.markdown b/modules/viz2d/tutorials/02-vector_graphics.markdown index 6b24da6a8..f8e043df3 100644 --- a/modules/viz2d/tutorials/02-vector_graphics.markdown +++ b/modules/viz2d/tutorials/02-vector_graphics.markdown @@ -1,4 +1,4 @@ -# Render vector graphics using Viz2D {#viz2d_vector_graphics} +# Render vector graphics {#viz2d_vector_graphics} @prev_tutorial{viz2d_display_image} @next_tutorial{viz2d_render_opengl} diff --git a/modules/viz2d/tutorials/03-render_opengl.markdown b/modules/viz2d/tutorials/03-render_opengl.markdown index 3bd91fd94..d4640112c 100644 --- a/modules/viz2d/tutorials/03-render_opengl.markdown +++ b/modules/viz2d/tutorials/03-render_opengl.markdown @@ -1,4 +1,4 @@ -# Render OpenGL using Viz2D {#viz2d_render_opengl} +# OpenGL Rendering {#viz2d_render_opengl} @prev_tutorial{viz2d_vector_graphics} @next_tutorial{viz2d_font_rendering} diff --git a/modules/viz2d/tutorials/04-font_rendering.markdown b/modules/viz2d/tutorials/04-font_rendering.markdown index 031a671f9..503f901cc 100644 --- a/modules/viz2d/tutorials/04-font_rendering.markdown +++ b/modules/viz2d/tutorials/04-font_rendering.markdown @@ -1,4 +1,4 @@ -# Font rendering using Viz2D {#viz2d_font_rendering} +# Font rendering {#viz2d_font_rendering} @prev_tutorial{viz2d_render_opengl} @next_tutorial{viz2d_video_editing} diff --git a/modules/viz2d/tutorials/05-video_editing.markdown b/modules/viz2d/tutorials/05-video_editing.markdown index 954d99172..8ffb003d0 100644 --- a/modules/viz2d/tutorials/05-video_editing.markdown +++ b/modules/viz2d/tutorials/05-video_editing.markdown @@ -1,4 +1,4 @@ -# Video editing using Viz2D {#viz2d_video_editing} +# Video editing {#viz2d_video_editing} @prev_tutorial{viz2d_font_rendering} @next_tutorial{viz2d_font_with_gui} @@ -9,7 +9,7 @@ | Compatibility | OpenCV >= 4.7 | ## Render text on top of a video -Through adding a Source and a Sink v2d becomes capable of video editing. Reads a video, renders text on top and writes the result. +Through adding a Source and a Sink v2d becomes capable of video editing. Reads a video, renders text on top and writes the result. Note: Reading and writing of video-data is multi-threaded in the background for performance reasons. @include samples/cpp/video_editing.cpp diff --git a/modules/viz2d/tutorials/06-font_with_gui.markdown b/modules/viz2d/tutorials/06-font_with_gui.markdown index 46f344d54..b82a94f7a 100644 --- a/modules/viz2d/tutorials/06-font_with_gui.markdown +++ b/modules/viz2d/tutorials/06-font_with_gui.markdown @@ -1,4 +1,4 @@ -# Form based GUI using Viz2D {#viz2d_font_with_gui} +# Form based GUI {#viz2d_font_with_gui} @prev_tutorial{viz2d_video_editing}