diff --git a/src/beauty/beauty-demo.cpp b/src/beauty/beauty-demo.cpp index 968bb2ead..2c17c543b 100644 --- a/src/beauty/beauty-demo.cpp +++ b/src/beauty/beauty-demo.cpp @@ -321,15 +321,16 @@ int main(int argc, char **argv) { }); } - if (!app::display()) - break; - va::write([&writer](const cv::UMat& videoFrame){ //videoFrame is the frameBuffer converted to BGR. Ready to be written. writer << videoFrame; }); - app::print_fps(); + app::update_fps(); + + //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. + if(!app::display()) + break; } app::terminate(); diff --git a/src/common/subsystems.hpp b/src/common/subsystems.hpp index 9559a145d..af6e58699 100644 --- a/src/common/subsystems.hpp +++ b/src/common/subsystems.hpp @@ -357,6 +357,14 @@ using namespace nanogui; ref screen; FormHelper* form; +nanogui::detail::FormWidget * make_gui_variable(const string& name, bool& v, const string& tooltip = "") { + using kb::gui::form; + auto var = form->add_variable(name, v); + if(!tooltip.empty()) + var->set_tooltip(tooltip); + return var; +} + template nanogui::detail::FormWidget * make_gui_variable(const string& name, T& v, const T& min, const T& max, bool spinnable = true, const string& unit = "", const string tooltip = "") { using kb::gui::form; auto var = form->add_variable(name, v); @@ -464,7 +472,7 @@ bool display() { return true; } -void print_fps() { +void update_fps(bool graphical = false) { static uint64_t cnt = 0; static double fps = 1; static cv::TickMeter meter; @@ -479,6 +487,20 @@ void print_fps() { } } + if (graphical) { + nvg::render([&](int w, int h) { + nvgBeginPath(nvg::vg); + nvgRoundedRect(nvg::vg, 10, 10, 60 * 6, 60, 10); + nvgFillColor(nvg::vg, nvgRGBA(255, 255, 255, 180)); + nvgFill (nvg::vg); + nvgFontSize(nvg::vg, 60.0f); + nvgFontFace(nvg::vg, "sans-bold"); + nvgFillColor(nvg::vg, nvgRGBA(90, 90, 90, 200)); + nvgTextAlign(nvg::vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); + nvgText(nvg::vg, 22, 37, ("FPS: " + std::to_string(fps)).c_str(), nullptr); + }); + } + meter.start(); ++cnt; } diff --git a/src/font/font-demo.cpp b/src/font/font-demo.cpp index 772baaed2..60e995d51 100644 --- a/src/font/font-demo.cpp +++ b/src/font/font-demo.cpp @@ -138,21 +138,23 @@ int main(int argc, char **argv) { cv::add(stars, warped, frameBuffer); }); - //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. - if(!app::display()) - break; + va::write([&writer](const cv::UMat& videoFrame){ //videoFrame is the frameBuffer converted to BGR. Ready to be written. writer << videoFrame; }); + app::update_fps(); + + //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. + if(!app::display()) + break; + ++cnt; //Wrap the cnt around if it becomes to big. if(cnt > std::numeric_limits().max() / 2.0) cnt = 0; - - app::print_fps(); } app::terminate(); diff --git a/src/nanovg/nanovg-demo.cpp b/src/nanovg/nanovg-demo.cpp index 1fa9a3bc4..6c307d67b 100644 --- a/src/nanovg/nanovg-demo.cpp +++ b/src/nanovg/nanovg-demo.cpp @@ -126,6 +126,7 @@ int main(int argc, char **argv) { app::init("Nanovg Demo", WIDTH, HEIGHT, OFFSCREEN); //Print system information app::print_system_info(); + app::run([&]() { //Initialize MJPEG HW decoding using VAAPI cv::VideoCapture capture(argv[1], cv::CAP_FFMPEG, { @@ -195,16 +196,16 @@ int main(int argc, char **argv) { drawColorwheel(nvg::vg, w - 300, h - 300, 250.0f, 250.0f, nvgHue); }); - //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. - if(!app::display()) - break; - va::write([&writer](const cv::UMat& videoFrame){ //videoFrame is the frameBuffer converted to BGR. Ready to be written. writer << videoFrame; }); - app::print_fps(); + app::update_fps(); + + //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. + if(!app::display()) + break; } app::terminate(); diff --git a/src/optflow/optflow-demo.cpp b/src/optflow/optflow-demo.cpp index a4631e771..38c8ba458 100644 --- a/src/optflow/optflow-demo.cpp +++ b/src/optflow/optflow-demo.cpp @@ -42,6 +42,8 @@ int GLOW_KERNEL_SIZE = std::max(int(DIAG / 138 % 2 == 0 ? DIAG / 138 + 1 : DIAG float ALPHA = 0.1f; // Red, green, blue and alpha. All from 0.0f to 1.0f nanogui::Color EFFECT_COLOR(1.0f, 0.75f, 0.4f, 1.0f); +//show graphical FPS +bool SHOW_FPS = false; using std::cerr; using std::endl; @@ -184,7 +186,7 @@ void setup_gui() { using namespace kb::gui; using namespace kb::display; - win = form->add_window(nanogui::Vector2i(0, 0), "Settings"); + win = form->add_window(nanogui::Vector2i(6, 45), "Settings"); form->add_group("Foreground"); make_gui_variable("Scale", FG_SCALE, 0.1f, 4.0f, true, "", "Generate the foreground at this scale"); make_gui_variable("Loss", FG_LOSS, 0.1f, 99.9f, true, "%", "On every frame the foreground loses on brightness"); @@ -212,7 +214,10 @@ void setup_gui() { EFFECT_COLOR[2] = c[2]; }); - auto alpha = make_gui_variable("Alpha", ALPHA, 0.0f, 1.0f, true, "", "The opacity of the effect"); + make_gui_variable("Alpha", ALPHA, 0.0f, 1.0f, true, "", "The opacity of the effect"); + + form->add_group("Display"); + make_gui_variable("Show FPS", SHOW_FPS, "Display the FPS on screen"); form->add_button("Fullscreen", []() { set_fullscreen(!is_fullscreen()); @@ -302,16 +307,16 @@ int main(int argc, char **argv) { composite_layers(background, foreground, frameBuffer, frameBuffer, GLOW_KERNEL_SIZE, FG_LOSS); }); - //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. - if(!app::display()) - break; - va::write([&writer](const cv::UMat& videoFrame){ //videoFrame is the frameBuffer converted to BGR. Ready to be written. writer << videoFrame; }); - app::print_fps(); + app::update_fps(SHOW_FPS); + + //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. + if(!app::display()) + break; } app::terminate(); diff --git a/src/pedestrian/pedestrian-demo.cpp b/src/pedestrian/pedestrian-demo.cpp index 5d48e5c8f..ee1cc7557 100644 --- a/src/pedestrian/pedestrian-demo.cpp +++ b/src/pedestrian/pedestrian-demo.cpp @@ -205,16 +205,16 @@ int main(int argc, char **argv) { composite_layers(background, foreground, frameBuffer, frameBuffer, BLUR_KERNEL_SIZE, FG_LOSS); }); - //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. - if (!app::display()) - break; - va::write([&writer](const cv::UMat& videoFrame){ //videoFrame is the frameBuffer converted to BGR. Ready to be written. writer << videoFrame; }); - app::print_fps(); + app::update_fps(); + + //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. + if (!app::display()) + break; } app::terminate(); diff --git a/src/tetra/tetra-demo.cpp b/src/tetra/tetra-demo.cpp index bfb2fbf61..a283e09be 100644 --- a/src/tetra/tetra-demo.cpp +++ b/src/tetra/tetra-demo.cpp @@ -115,16 +115,16 @@ int main(int argc, char **argv) { glow_effect(frameBuffer, frameBuffer, GLOW_KERNEL_SIZE); }); - //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. - if(!app::display()) - break; - va::write([&writer](const cv::UMat& videoFrame){ //videoFrame is the frameBuffer converted to BGR. Ready to be written. writer << videoFrame; }); - app::print_fps(); + app::update_fps(); + + //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. + if(!app::display()) + break; } }); diff --git a/src/video/video-demo.cpp b/src/video/video-demo.cpp index 13b8c2651..ccf29010f 100644 --- a/src/video/video-demo.cpp +++ b/src/video/video-demo.cpp @@ -144,16 +144,16 @@ int main(int argc, char **argv) { glow_effect(frameBuffer, frameBuffer, GLOW_KERNEL_SIZE); }); - //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. - if(!app::display()) - break; - va::write([&](const cv::UMat& videoFrame){ //videoFrame is the frameBuffer converted to BGR. Ready to be written. writer << videoFrame; }); - app::print_fps(); + app::update_fps(); + + //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. + if(!app::display()) + break; } app::terminate();