enable onscreen fps display

pull/3471/head
kallaballa 2 years ago
parent a5f2b227ce
commit 18f8de80ff
  1. 9
      src/beauty/beauty-demo.cpp
  2. 24
      src/common/subsystems.hpp
  3. 12
      src/font/font-demo.cpp
  4. 11
      src/nanovg/nanovg-demo.cpp
  5. 19
      src/optflow/optflow-demo.cpp
  6. 10
      src/pedestrian/pedestrian-demo.cpp
  7. 10
      src/tetra/tetra-demo.cpp
  8. 10
      src/video/video-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();

@ -357,6 +357,14 @@ using namespace nanogui;
ref<nanogui::Screen> screen;
FormHelper* form;
nanogui::detail::FormWidget<bool> * 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 <typename T> nanogui::detail::FormWidget<T> * 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;
}

@ -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<size_t>().max() / 2.0)
cnt = 0;
app::print_fps();
}
app::terminate();

@ -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();

@ -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();

@ -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();

@ -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;
}
});

@ -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();

Loading…
Cancel
Save