From 854452c30dae9ec8f73d25b81d2e1ede7db2094d Mon Sep 17 00:00:00 2001 From: kallaballa Date: Wed, 18 Oct 2023 09:13:34 +0200 Subject: [PATCH] fixed all warnings --- modules/v4d/CMakeLists.txt | 1 + modules/v4d/include/opencv2/v4d/util.hpp | 18 +- modules/v4d/include/opencv2/v4d/v4d.hpp | 250 ++++++++++------------- modules/v4d/samples/beauty-demo.cpp | 10 +- modules/v4d/samples/display_image_fb.cpp | 2 +- modules/v4d/samples/font-demo.cpp | 69 ++++--- modules/v4d/samples/font_with_gui.cpp | 1 + modules/v4d/samples/many_cubes-demo.cpp | 14 +- modules/v4d/samples/shader-demo.cpp | 25 +-- modules/v4d/src/detail/imguicontext.cpp | 1 - modules/v4d/src/util.cpp | 21 ++ 11 files changed, 189 insertions(+), 223 deletions(-) diff --git a/modules/v4d/CMakeLists.txt b/modules/v4d/CMakeLists.txt index 39f234b8a..3c93f9ab3 100755 --- a/modules/v4d/CMakeLists.txt +++ b/modules/v4d/CMakeLists.txt @@ -261,6 +261,7 @@ if(NOT (TARGET ${the_module})) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV_V4D_USE_ES3=1") endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-sign-promo") target_compile_features(${the_module} PRIVATE cxx_std_20) ocv_warnings_disable(CMAKE_CXX_FLAGS -Wdeprecated-enum-enum-conversion) diff --git a/modules/v4d/include/opencv2/v4d/util.hpp b/modules/v4d/include/opencv2/v4d/util.hpp index 17171bf85..3cb82597b 100644 --- a/modules/v4d/include/opencv2/v4d/util.hpp +++ b/modules/v4d/include/opencv2/v4d/util.hpp @@ -138,23 +138,7 @@ struct function_traits { //https://stackoverflow.com/questions/281818/unmangling-the-result-of-stdtype-infoname -#ifdef __GNUG__ -static std::string demangle(const char* name) { - int status = -4; // some arbitrary value to eliminate the compiler warning - std::unique_ptr res { - abi::__cxa_demangle(name, NULL, NULL, &status), - std::free - }; - - return (status==0) ? res.get() : name ; -} - -#else -// does nothing if not g++ -static std::string demangle(const char* name) { - return name; -} -#endif +CV_EXPORTS std::string demangle(const char* name); template struct fun_ptr_helper diff --git a/modules/v4d/include/opencv2/v4d/v4d.hpp b/modules/v4d/include/opencv2/v4d/v4d.hpp index b04f8aa45..2b4c6ab53 100644 --- a/modules/v4d/include/opencv2/v4d/v4d.hpp +++ b/modules/v4d/include/opencv2/v4d/v4d.hpp @@ -35,8 +35,6 @@ #include #include #include -#define UNW_LOCAL_ONLY -#include #include #include @@ -70,10 +68,10 @@ enum AllocateFlags { class Plan { public: virtual ~Plan() {}; - virtual void gui(cv::Ptr window) {}; - virtual void setup(cv::Ptr window) {}; + virtual void gui(cv::Ptr window) { CV_UNUSED(window); }; + virtual void setup(cv::Ptr window) { CV_UNUSED(window); }; virtual void infer(cv::Ptr window) = 0; - virtual void teardown(cv::Ptr window) {}; + virtual void teardown(cv::Ptr window) { CV_UNUSED(window); }; }; /*! * Private namespace @@ -105,6 +103,49 @@ template std::string lambda_ptr_hex(Tlamba&& l) { return int_to_hex((size_t)Lambda::ptr(l)); } +static std::size_t index(const std::thread::id id) +{ + static std::size_t nextindex = 0; + static std::mutex my_mutex; + static std::unordered_map ids; + std::lock_guard lock(my_mutex); + auto iter = ids.find(id); + if(iter == ids.end()) + return ids[id] = nextindex++; + return iter->second; +} + +template +const string make_id(const string& name, Tfn&& fn, const Textra& extra) { + stringstream ss; + stringstream ssExtra; + ssExtra << extra; + if(ssExtra.str().empty()) { + ss << name << "(" << index(std::this_thread::get_id()) << "-" << detail::lambda_ptr_hex(std::forward(fn)) << ")"; + } + else { + ss << name << "(" << index(std::this_thread::get_id()) << "-" << detail::lambda_ptr_hex(std::forward(fn)) << ")/" << ssExtra.str(); + } + + return ss.str(); +} + +template +const string make_id(const string& name, Tfn&& fn, const string& extra = "") { + return make_id(name, fn, extra); +} + + +template +void print_id(const string& name, Tfn&& fn, const Textra& extra) { + cerr << make_id(name, fn, extra) << endl; +} + +template +void print_id(const string& name, Tfn&& fn, const string& extra = "") { + cerr << make_id(name, fn, extra) << endl; +} + } using namespace cv::v4d::detail; @@ -271,78 +312,16 @@ public: } } -// template -// void add_transaction(const string& context, Tfn&& fn, cv::UMat&& fb, Args&& ...args) { -// auto it = transactions_.find(context); -// if(it == transactions_.end()) { -// transactions_.insert({context, make_transaction(std::forward(fn), std::forward(fb), std::forward(args)...)}); -// } -// } -// -// template -// void add_transaction(const string& context, Tfn&& fn, const cv::UMat&& fb, Args&& ...args) { -// auto it = transactions_.find(context); -// if(it == transactions_.end()) { -// transactions_.insert({context, make_transaction(std::forward(fn), std::forward(fb), std::forward(args)...)}); -// } -// } - - std::size_t index(const std::thread::id id) - { - static std::size_t nextindex = 0; - static std::mutex my_mutex; - static std::unordered_map ids; - std::lock_guard lock(my_mutex); - auto iter = ids.find(id); - if(iter == ids.end()) - return ids[id] = nextindex++; - return iter->second; - } - - - template - const string make_id(const string& name, Tfn&& fn, const Textra& extra) { - stringstream ss; - stringstream ssExtra; - ssExtra << extra; - if(ssExtra.str().empty()) { - ss << name << "(" << index(std::this_thread::get_id()) << "-" << detail::lambda_ptr_hex(std::forward(fn)) << ")"; - } - else { - ss << name << "(" << index(std::this_thread::get_id()) << "-" << detail::lambda_ptr_hex(std::forward(fn)) << ")/" << ssExtra.str(); - } - - return ss.str(); - } - - template - const string make_id(const string& name, Tfn&& fn, const string& extra = "") { - return make_id(name, fn, extra); - } - - - template - void print_id(const string& name, Tfn&& fn, const Textra& extra) { - cerr << make_id(name, fn, extra) << endl; - } - - template - void print_id(const string& name, Tfn&& fn, const string& extra = "") { - cerr << make_id(name, fn, extra) << endl; - } - template typename std::enable_if, void>::type gl(Tfn fn, Args&& ... args) { CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("gl", fn, -1); - TimeTracker::getInstance()->execute(id, [this, fn, id, &args...](){ - emit_access(id, true, &fbCtx()->fb()); - (emit_access, Args...>(id, std::is_const_v>, &args),...); - emit_access(id, false, &fbCtx()->fb()); - std::function functor(fn); - add_transaction(glCtx(-1), id, std::forward(fn), std::forward(args)...); - }); + emit_access(id, true, &fbCtx()->fb()); + (emit_access, Args...>(id, std::is_const_v>, &args),...); + emit_access(id, false, &fbCtx()->fb()); + std::function functor(fn); + add_transaction(glCtx(-1), id, std::forward(fn), std::forward(args)...); } template @@ -350,13 +329,11 @@ public: CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("gl", fn, idx); - TimeTracker::getInstance()->execute(id, [this, fn, idx, id, &args...](){ - emit_access(id, true, &fbCtx()->fb()); - (emit_access, Args...>(id, std::is_const_v>, &args),...); - emit_access(id, false, &fbCtx()->fb()); - std::function functor(fn); - add_transaction(fbCtx(),id, std::forward(functor), glCtx(idx)->getIndex(), std::forward(args)...); - }); + emit_access(id, true, &fbCtx()->fb()); + (emit_access, Args...>(id, std::is_const_v>, &args),...); + emit_access(id, false, &fbCtx()->fb()); + std::function functor(fn); + add_transaction(fbCtx(),id, std::forward(functor), glCtx(idx)->getIndex(), std::forward(args)...); } template @@ -364,11 +341,9 @@ public: CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("branch", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id](){ - std::function functor = fn; - emit_access(id, true, &fn); - add_transaction(singleCtx(), id, functor); - }); + std::function functor = fn; + emit_access(id, true, &fn); + add_transaction(singleCtx(), id, functor); } template @@ -376,11 +351,9 @@ public: CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("branch", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id, &args...](){ - (emit_access, Args...>(id, std::is_const_v>, &args),...); - std::function functor = fn; - add_transaction(singleCtx(), id, functor, std::forward(args)...); - }); + (emit_access, Args...>(id, std::is_const_v>, &args),...); + std::function functor = fn; + add_transaction(singleCtx(), id, functor, std::forward(args)...); } template @@ -388,11 +361,9 @@ public: CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("endbranch", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id] { - std::function functor = fn; - emit_access(id, true, &fn); - add_transaction(singleCtx(), id, functor); - }); + std::function functor = fn; + emit_access(id, true, &fn); + add_transaction(singleCtx(), id, functor); } template @@ -400,29 +371,24 @@ public: CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("endbranch", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id, &args...](){ - (emit_access, Args...>(id, std::is_const_v>, &args),...); - std::function functor = fn; - add_transaction(singleCtx(), id, functor, std::forward(args)...); - }); + (emit_access, Args...>(id, std::is_const_v>, &args),...); + std::function functor = fn; + add_transaction(singleCtx(), id, functor, std::forward(args)...); } template void fb(Tfn fn, Args&& ... args) { CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("fb", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id, &args...]{ - using Tfb = std::add_lvalue_reference_t::argument_types>::type>; - using Tfbbase = typename std::remove_cv::type; - using Tfbconst = std::add_const_t; - - static_assert((std::is_same::value || std::is_same::value) || !"The first argument must be eiter of type 'cv::UMat&' or 'const cv::UMat&'"); - emit_access(id, true, &fbCtx()->fb()); - (emit_access, Tfb, Args...>(id, std::is_const_v>, &args),...); - emit_access::type>, cv::UMat, Tfb, Args...>(id, false, &fbCtx()->fb()); - std::function functor(fn); - add_transaction(fbCtx(),id, std::forward(functor), fbCtx()->fb(), std::forward(args)...); - }); + using Tfb = std::add_lvalue_reference_t::argument_types>::type>; + using Tfbbase = typename std::remove_cv::type; + + static_assert((std::is_same::value || std::is_same::value) || !"The first argument must be eiter of type 'cv::UMat&' or 'const cv::UMat&'"); + emit_access(id, true, &fbCtx()->fb()); + (emit_access, Tfb, Args...>(id, std::is_const_v>, &args),...); + emit_access::type>, cv::UMat, Tfb, Args...>(id, false, &fbCtx()->fb()); + std::function functor(fn); + add_transaction(fbCtx(),id, std::forward(functor), fbCtx()->fb(), std::forward(args)...); } void capture(cv::UMat& frame) { @@ -449,15 +415,13 @@ public: void capture(Tfn fn, Args&& ... args) { CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("capture", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id, &args...]{ - using Tfb = std::add_lvalue_reference_t::argument_types>::type>; - - static_assert((std::is_same::value) || !"The first argument must be of type 'const cv::UMat&'"); - emit_access(id, true, &sourceCtx()->sourceBuffer()); - (emit_access, Tfb, Args...>(id, std::is_const_v>, &args),...); - std::function functor(fn); - add_transaction(std::dynamic_pointer_cast(sourceCtx()),id, std::forward(functor), sourceCtx()->sourceBuffer(), std::forward(args)...); - }); + using Tfb = std::add_lvalue_reference_t::argument_types>::type>; + + static_assert((std::is_same::value) || !"The first argument must be of type 'const cv::UMat&'"); + emit_access(id, true, &sourceCtx()->sourceBuffer()); + (emit_access, Tfb, Args...>(id, std::is_const_v>, &args),...); + std::function functor(fn); + add_transaction(std::dynamic_pointer_cast(sourceCtx()),id, std::forward(functor), sourceCtx()->sourceBuffer(), std::forward(args)...); } void write() { @@ -482,51 +446,43 @@ public: void write(Tfn fn, Args&& ... args) { CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("write", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id, &args...]{ - using Tfb = std::add_lvalue_reference_t::argument_types>::type>; - - static_assert((std::is_same::value) || !"The first argument must be of type 'cv::UMat&'"); - emit_access(id, true, &sinkCtx()->sinkBuffer()); - (emit_access, Tfb, Args...>(id, std::is_const_v>, &args),...); - emit_access(id, false, &sinkCtx()->sinkBuffer()); - std::function functor(fn); - add_transaction(std::dynamic_pointer_cast(sinkCtx()),id, std::forward(functor), sinkCtx()->sinkBuffer(), std::forward(args)...); - }); + using Tfb = std::add_lvalue_reference_t::argument_types>::type>; + + static_assert((std::is_same::value) || !"The first argument must be of type 'cv::UMat&'"); + emit_access(id, true, &sinkCtx()->sinkBuffer()); + (emit_access, Tfb, Args...>(id, std::is_const_v>, &args),...); + emit_access(id, false, &sinkCtx()->sinkBuffer()); + std::function functor(fn); + add_transaction(std::dynamic_pointer_cast(sinkCtx()),id, std::forward(functor), sinkCtx()->sinkBuffer(), std::forward(args)...); } template void nvg(Tfn fn, Args&&... args) { CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("nvg", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id, &args...](){ - emit_access(id, true, &fbCtx()->fb()); - (emit_access, Args...>(id, std::is_const_v>, &args),...); - emit_access(id, false, &fbCtx()->fb()); - std::function functor(fn); - add_transaction(nvgCtx(), id, std::forward(fn), std::forward(args)...); - }); + emit_access(id, true, &fbCtx()->fb()); + (emit_access, Args...>(id, std::is_const_v>, &args),...); + emit_access(id, false, &fbCtx()->fb()); + std::function functor(fn); + add_transaction(nvgCtx(), id, std::forward(fn), std::forward(args)...); } template void single(Tfn fn, Args&&... args) { CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("single", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id, &args...](){ - (emit_access, Args...>(id, std::is_const_v>, &args),...); - std::function functor(fn); - add_transaction(singleCtx(), id, std::forward(fn), std::forward(args)...); - }); + (emit_access, Args...>(id, std::is_const_v>, &args),...); + std::function functor(fn); + add_transaction(singleCtx(), id, std::forward(fn), std::forward(args)...); } template void parallel(Tfn fn, Args&&... args) { CV_Assert(detail::is_stateless_lambda>>::value); const string id = make_id("parallel", fn); - TimeTracker::getInstance()->execute(id, [this, fn, id, &args...](){ - (emit_access, Args...>(id, std::is_const_v>, &args),...); - std::function functor(fn); - add_transaction(parallelCtx(), id, std::forward(fn), std::forward(args)...); - }); + (emit_access, Args...>(id, std::is_const_v>, &args),...); + std::function functor(fn); + add_transaction(parallelCtx(), id, std::forward(fn), std::forward(args)...); } template diff --git a/modules/v4d/samples/beauty-demo.cpp b/modules/v4d/samples/beauty-demo.cpp index ddb6d83d6..a4920ccc0 100644 --- a/modules/v4d/samples/beauty-demo.cpp +++ b/modules/v4d/samples/beauty-demo.cpp @@ -220,25 +220,25 @@ public: } void gui(cv::Ptr window) override { - window->imgui([](cv::Ptr window, ImGuiContext* ctx, Params& params){ + window->imgui([](cv::Ptr win, ImGuiContext* ctx, Params& params){ using namespace ImGui; SetCurrentContext(ctx); Begin("Effect"); Text("Display"); Checkbox("Side by side", ¶ms.sideBySide_); if(Checkbox("Stetch", ¶ms.stretch_)) { - window->setStretching(true); + win->setStretching(true); } else - window->setStretching(false); + win->setStretching(false); #ifndef __EMSCRIPTEN__ if(Button("Fullscreen")) { - window->setFullscreen(!window->isFullscreen()); + win->setFullscreen(!win->isFullscreen()); }; #endif if(Button("Offscreen")) { - window->setVisible(!window->isVisible()); + win->setVisible(!win->isVisible()); }; Text("Face Skin"); diff --git a/modules/v4d/samples/display_image_fb.cpp b/modules/v4d/samples/display_image_fb.cpp index 80733d307..4ea00cffc 100644 --- a/modules/v4d/samples/display_image_fb.cpp +++ b/modules/v4d/samples/display_image_fb.cpp @@ -8,7 +8,7 @@ class DisplayImageFB : public Plan { UMat image_; UMat converted_; public: - void setup(cv::Ptr win) { + void setup(cv::Ptr win) override { win->parallel([](cv::UMat& image, cv::UMat& converted, const cv::Size& sz){ //Loads an image as a UMat (just in case we have hardware acceleration available) #ifdef __EMSCRIPTEN__ diff --git a/modules/v4d/samples/font-demo.cpp b/modules/v4d/samples/font-demo.cpp index 562c1ee68..d1633c017 100644 --- a/modules/v4d/samples/font-demo.cpp +++ b/modules/v4d/samples/font-demo.cpp @@ -49,11 +49,12 @@ class FontDemoPlan : public Plan { float fontSize_ = 40.0f; cv::Scalar_ textColor_ = INITIAL_COLOR / 255.0; float warpRatio_ = 1.0f/3.0f; + bool updateStars_ = true; + bool updatePerspective_ = true; } params_; + //the text to display vector lines_; - bool updateStars_ = true; - bool updatePerspective_ = true; //BGRA cv::UMat stars_, warped_, frame_; @@ -72,32 +73,34 @@ class FontDemoPlan : public Plan { int32_t translateY_; public: void gui(cv::Ptr window) override { - window->imgui([this](cv::Ptr window, ImGuiContext* ctx){ - using namespace ImGui; + window->imgui([](cv::Ptr win, ImGuiContext* ctx, Params& params){ + CV_UNUSED(win); + using namespace ImGui; SetCurrentContext(ctx); Begin("Effect"); Text("Text Crawl"); - SliderFloat("Font Size", ¶ms_.fontSize_, 1.0f, 100.0f); - if(SliderFloat("Warp Ratio", ¶ms_.warpRatio_, 0.1f, 1.0f)) - updatePerspective_ = true; - ColorPicker4("Text Color", params_.textColor_.val); + SliderFloat("Font Size", ¶ms.fontSize_, 1.0f, 100.0f); + if(SliderFloat("Warp Ratio", ¶ms.warpRatio_, 0.1f, 1.0f)) + params.updatePerspective_ = true; + ColorPicker4("Text Color", params.textColor_.val); Text("Stars"); - if(SliderFloat("Min Star Size", ¶ms_.minStarSize_, 0.5f, 1.0f)) - updateStars_ = true; - if(SliderFloat("Max Star Size", ¶ms_.maxStarSize_, 1.0f, 10.0f)) - updateStars_ = true; - if(SliderInt("Min Star Count", ¶ms_.minStarCount_, 1, 1000)) - updateStars_ = true; - if(SliderInt("Max Star Count", ¶ms_.maxStarCount_, 1000, 5000)) - updateStars_ = true; - if(SliderFloat("Min Star Alpha", ¶ms_.starAlpha_, 0.2f, 1.0f)) - updateStars_ = true; + if(SliderFloat("Min Star Size", ¶ms.minStarSize_, 0.5f, 1.0f)) + params.updateStars_ = true; + if(SliderFloat("Max Star Size", ¶ms.maxStarSize_, 1.0f, 10.0f)) + params.updateStars_ = true; + if(SliderInt("Min Star Count", ¶ms.minStarCount_, 1, 1000)) + params.updateStars_ = true; + if(SliderInt("Max Star Count", ¶ms.maxStarCount_, 1000, 5000)) + params.updateStars_ = true; + if(SliderFloat("Min Star Alpha", ¶ms.starAlpha_, 0.2f, 1.0f)) + params.updateStars_ = true; End(); - }); + }, params_); } void setup(cv::Ptr window) override { + CV_UNUSED(window); //The text to display string txt = cv::getBuildInformation(); //Save the text to a vector @@ -114,7 +117,7 @@ public: auto always = []() { return true; }; auto isTrue = [](const bool& b) { return b; }; - window->branch(isTrue, updateStars_); + window->branch(isTrue, params_.updateStars_); { window->nvg([](const cv::Size& sz, cv::RNG& rng, const Params& params) { using namespace cv::v4d::nvg; @@ -136,9 +139,9 @@ public: frameBuffer.copyTo(f); }, stars_); } - window->endbranch(isTrue, updateStars_); + window->endbranch(isTrue, params_.updateStars_); - window->branch(isTrue, updatePerspective_); + window->branch(isTrue, params_.updatePerspective_); { window->parallel([](cv::Mat& tm, const Params& params){ //Derive the transformation matrix tm for the pseudo 3D effect from quad1 and quad2. @@ -150,7 +153,7 @@ public: tm = cv::getPerspectiveTransform(quad1, quad2); }, tm_, params_); } - window->endbranch(isTrue, updatePerspective_); + window->endbranch(isTrue, params_.updatePerspective_); window->branch(always); { @@ -175,15 +178,19 @@ public: } }, window->fbSize(), translateY_, cnt_, y_, textHeight_, lines_, params_); - window->fb([](cv::UMat& framebuffer, cv::UMat& w, cv::UMat& s, cv::Mat& t, cv::UMat& f) { + window->fb([](cv::UMat& framebuffer, cv::UMat& w, cv::UMat& s, cv::Mat& t) { //Pseudo 3D text effect. cv::warpPerspective(framebuffer, w, t, framebuffer.size(), cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar()); //Combine layers cv::add(s, w, framebuffer); - framebuffer.copyTo(f); - }, warped_, stars_, tm_, frame_); + }, warped_, stars_, tm_); + + window->write(); + + window->parallel([](const int32_t& translateY, const int32_t& textHeight, uint32_t& cnt, Params& params) { + params.updatePerspective_ = false; + params.updateStars_ = false; - window->parallel([](const int32_t& translateY, const int32_t& textHeight, uint32_t& cnt) { if(-translateY > textHeight) { //reset the scroll once the text is out of the picture cnt = 0; @@ -192,13 +199,7 @@ public: //Wrap the cnt around if it becomes to big. if(cnt > std::numeric_limits().max() / 2.0) cnt = 0; - }, translateY_, textHeight_, cnt_); - - window->write([](cv::UMat& outputFrame, const cv::UMat& f, bool& updatePerspective, bool& updateStars){ - f.copyTo(outputFrame); - updatePerspective = false; - updateStars = false; - }, frame_, updatePerspective_, updateStars_); + }, translateY_, textHeight_, cnt_, params_); } window->endbranch(always); } diff --git a/modules/v4d/samples/font_with_gui.cpp b/modules/v4d/samples/font_with_gui.cpp index fe2a08004..b3164720a 100644 --- a/modules/v4d/samples/font_with_gui.cpp +++ b/modules/v4d/samples/font_with_gui.cpp @@ -15,6 +15,7 @@ class FontWithGuiPlan: public Plan { public: void gui(Ptr window) override { window->imgui([](Ptr win, ImGuiContext* ctx, Params& params) { + CV_UNUSED(win); using namespace ImGui; SetCurrentContext(ctx); Begin("Settings"); diff --git a/modules/v4d/samples/many_cubes-demo.cpp b/modules/v4d/samples/many_cubes-demo.cpp index adf7ce3e3..b0dec0f6c 100644 --- a/modules/v4d/samples/many_cubes-demo.cpp +++ b/modules/v4d/samples/many_cubes-demo.cpp @@ -229,7 +229,7 @@ class ManyCubesDemoPlan : public Plan { } #endif public: - void setup(cv::Ptr window) { + void setup(cv::Ptr window) override { sz_ = window->fbSize(); for(size_t i = 0; i < NUMBER_OF_CUBES; ++i) { window->gl(i, [](const size_t& ctxIdx, cv::Size& sz, GLuint& v, GLuint& sp, GLuint& ut){ @@ -238,7 +238,7 @@ public: }, sz_, vao[i], shaderProgram[i], uniformTransform[i]); } } - void infer(cv::Ptr window) { + void infer(cv::Ptr window) override { window->gl([](){ //Clear the background glClearColor(0.2, 0.24, 0.4, 1); @@ -248,9 +248,10 @@ public: //Render using multiple OpenGL contexts for(size_t i = 0; i < NUMBER_OF_CUBES; ++i) { window->gl(i, [](const int32_t& ctxIdx, GLuint& v, GLuint& sp, GLuint& ut){ - double pos = (((double(ctxIdx) / NUMBER_OF_CUBES) * 2.0) - 1) + (1.0 / NUMBER_OF_CUBES); + double x = sin((double(ctxIdx) / NUMBER_OF_CUBES) * 2 * M_PI) / 1.5; + double y = cos((double(ctxIdx) / NUMBER_OF_CUBES) * 2 * M_PI) / 1.5; double angle = sin((double(ctxIdx) / NUMBER_OF_CUBES) * 2 * M_PI); - render_scene(pos, pos, angle, v, sp, ut); + render_scene(x, y, angle, v, sp, ut); }, vao[i], shaderProgram[i], uniformTransform[i]); } @@ -268,7 +269,8 @@ public: } }; -int main() { +int main(int argc, char** argv) { + CV_UNUSED(argc); cv::Ptr window = V4D::make(WIDTH, HEIGHT, "Many Cubes Demo", IMGUI, OFFSCREEN); #ifndef __EMSCRIPTEN__ @@ -276,7 +278,7 @@ int main() { auto sink = makeWriterSink(window, OUTPUT_FILENAME, FPS, cv::Size(WIDTH, HEIGHT)); window->setSink(sink); #endif - window->run(0); + window->run(atoi(argv[1])); return 0; } diff --git a/modules/v4d/samples/shader-demo.cpp b/modules/v4d/samples/shader-demo.cpp index 5fec13e04..2b0258ff8 100644 --- a/modules/v4d/samples/shader-demo.cpp +++ b/modules/v4d/samples/shader-demo.cpp @@ -258,29 +258,30 @@ class ShaderDemoPlan : public Plan { } public: void gui(cv::Ptr window) override { - window->imgui([this](cv::Ptr window, ImGuiContext* ctx) { + window->imgui([](cv::Ptr win, ImGuiContext* ctx, Params& params) { + CV_UNUSED(win); using namespace ImGui; SetCurrentContext(ctx); Begin("Fractal"); Text("Navigation"); - SliderInt("Iterations", ¶ms_.maxIterations_, 3, 50000); - if(SliderFloat("X", ¶ms_.centerX_, -1.0f, 1.0f)) - params_.manualNavigation_ = true; + SliderInt("Iterations", ¶ms.maxIterations_, 3, 50000); + if(SliderFloat("X", ¶ms.centerX_, -1.0f, 1.0f)) + params.manualNavigation_ = true; - if(SliderFloat("Y", ¶ms_.centerY_, -1.0f, 1.0f)) - params_.manualNavigation_ = true; + if(SliderFloat("Y", ¶ms.centerY_, -1.0f, 1.0f)) + params.manualNavigation_ = true; - if(SliderFloat("Zoom", ¶ms_.zoomFactor_, 1.0f, 100.0f)) - params_.manualNavigation_ = true; + if(SliderFloat("Zoom", ¶ms.zoomFactor_, 1.0f, 100.0f)) + params.manualNavigation_ = true; #ifndef __EMSCRIPTEN__ Text("Glow"); - SliderInt("Kernel Size", ¶ms_.glowKernelSize_, 1, 127); + SliderInt("Kernel Size", ¶ms.glowKernelSize_, 1, 127); #endif Text("Color"); - ColorPicker4("Color", params_.baseColorVal_); - SliderInt("Contrast boost", ¶ms_.contrastBoost_, 1, 255); + ColorPicker4("Color", params.baseColorVal_); + SliderInt("Contrast boost", ¶ms.contrastBoost_, 1, 255); End(); - }); + }, params_); } void setup(cv::Ptr window) override { diff --git a/modules/v4d/src/detail/imguicontext.cpp b/modules/v4d/src/detail/imguicontext.cpp index 914ab070e..44852e320 100644 --- a/modules/v4d/src/detail/imguicontext.cpp +++ b/modules/v4d/src/detail/imguicontext.cpp @@ -73,7 +73,6 @@ void ImGuiContextImpl::render(bool showFPS) { ImGui::SetNextWindowPos(pos, ImGuiCond_Once); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0f, 0.0f, 0.0f, 0.5f)); ImGui::Begin("Display", open_ptr, window_flags); - ImGuiIO& io = ImGui::GetIO(); ImGui::Text("%.3f ms/frame (%.1f FPS)", (1000.0f / Global::fps()) , Global::fps()); ImGui::End(); ImGui::PopStyleColor(1); diff --git a/modules/v4d/src/util.cpp b/modules/v4d/src/util.cpp index 8649793f4..bd16f24cc 100644 --- a/modules/v4d/src/util.cpp +++ b/modules/v4d/src/util.cpp @@ -39,6 +39,24 @@ namespace cv { namespace v4d { namespace detail { +#ifdef __GNUG__ +std::string demangle(const char* name) { + int status = -4; // some arbitrary value to eliminate the compiler warning + std::unique_ptr res { + abi::__cxa_demangle(name, NULL, NULL, &status), + std::free + }; + + return (status==0) ? res.get() : name ; +} + +#else +// does nothing if not g++ +std::string demangle(const char* name) { + return name; +} +#endif + size_t cnz(const cv::UMat& m) { cv::UMat grey; if(m.channels() == 1) { @@ -311,6 +329,7 @@ cv::Ptr makeVaSink(cv::Ptr window, const string& outputFilename, cons cerr << "Using a VA sink" << endl; if(writer->isOpened()) { return new Sink([=](const uint64_t& seq, const cv::UMat& frame) { + CV_UNUSED(seq); CLExecScope_t scope(window->sourceCtx()->getCLExecContext()); //FIXME cache it cv::UMat converted; @@ -347,6 +366,7 @@ static cv::Ptr makeAnyHWSink(const string& outputFilename, const int fourc if(writer->isOpened()) { return new Sink([=](const uint64_t& seq, const cv::UMat& frame) { + CV_UNUSED(seq); cv::UMat converted; cv::resize(frame, converted, frameSize); cvtColor(converted, converted, cv::COLOR_BGRA2RGB); @@ -399,6 +419,7 @@ cv::Ptr makeWriterSink(cv::Ptr window, const string& outputFilename, if(writer->isOpened()) { return new Sink([=](const uint64_t& seq, const cv::UMat& frame) { + CV_UNUSED(seq); cv::UMat converted; cv::resize(frame, converted, frameSize); cvtColor(converted, converted, cv::COLOR_BGRA2RGB);