diff --git a/modules/v4d/include/opencv2/v4d/nvg.hpp b/modules/v4d/include/opencv2/v4d/nvg.hpp index 547515091..af65c65f3 100644 --- a/modules/v4d/include/opencv2/v4d/nvg.hpp +++ b/modules/v4d/include/opencv2/v4d/nvg.hpp @@ -6,8 +6,6 @@ #ifndef SRC_OPENCV_V4D_NVG_HPP_ #define SRC_OPENCV_V4D_NVG_HPP_ -//#include "v4d.hpp" - #include #include #include "nanovg.h" @@ -17,7 +15,7 @@ struct NVGcontext; namespace cv { namespace v4d { /*! - * In general please refere to https://github.com/memononen/nanovg/blob/master/src/nanovg.h for reference. + * In general please refer to https://github.com/memononen/nanovg/blob/master/src/nanovg.h for reference. */ namespace nvg { /*! diff --git a/modules/v4d/include/opencv2/v4d/v4d.hpp b/modules/v4d/include/opencv2/v4d/v4d.hpp index 107096952..6ab468194 100644 --- a/modules/v4d/include/opencv2/v4d/v4d.hpp +++ b/modules/v4d/include/opencv2/v4d/v4d.hpp @@ -25,14 +25,18 @@ #include "source.hpp" #include "sink.hpp" #include "util.hpp" +#include "formhelper.hpp" +#include "nvg.hpp" +#include "detail/threadpool.hpp" + #include #include #include #include + #include #include -#include "formhelper.hpp" -#include "detail/threadpool.hpp" + using std::cout; using std::cerr; @@ -49,7 +53,7 @@ namespace nanogui { */ namespace cv { /*! - * Visualization namespace + * V4D namespace */ namespace v4d { class FormHelper; @@ -63,12 +67,6 @@ class GLContext; class NanoVGContext; class NanoguiContext; -/*! - * The GFLW error callback. - * @param error Error number - * @param description Error description - */ -void glfw_error_callback(int error, const char* description); /*! * Find widgets that are of type T. * @tparam T The type of widget to find @@ -96,10 +94,7 @@ CV_EXPORTS cv::Scalar colorConvert(const cv::Scalar& src, cv::ColorConversionCod using namespace cv::v4d::detail; -class NVG; - class CV_EXPORTS V4D { - friend class detail::NanoVGContext; friend class detail::FrameBufferContext; friend class HTML5Capture; cv::Size initialSize_; @@ -347,12 +342,12 @@ public: * Enable/Disable scaling the framebuffer during blitting. * @param s if true enable scaling */ - CV_EXPORTS void setFrameBufferScaling(bool s); + CV_EXPORTS void setScaling(bool s); /*! * Determine if framebuffer is scaled during blitting. * @return true if framebuffer is scaled during blitting. */ - CV_EXPORTS bool isFrameBufferScaling(); + CV_EXPORTS bool isScaling(); /*! * Everytime a frame is displayed this count is incremented * @return the current frame count @@ -378,15 +373,16 @@ public: CV_EXPORTS void printSystemInfo(); CV_EXPORTS void makeCurrent(); - NanoguiContext& nguiCtx(); + + void setDefaultKeyboardEventCallback(); + void setKeyboardEventCallback( + std::function fn); private: V4D(const cv::Size& size, const cv::Size& fbsize, const string& title, bool offscreen, bool debug, bool compat, int samples); void init(); - void setDefaultKeyboardEventCallback(); - void setKeyboardEventCallback( - std::function fn); + void setMouseDrag(bool d); bool isMouseDrag(); cv::Vec2f getMousePosition(); @@ -397,6 +393,7 @@ private: CLVAContext& clvaCtx(); NanoVGContext& nvgCtx(); GLContext& glCtx(); + NanoguiContext& nguiCtx(); bool hasFbCtx(); bool hasClvaCtx(); @@ -410,6 +407,5 @@ private: } } /* namespace kb */ -#include #endif /* SRC_OPENCV_V4D_V4D_HPP_ */ diff --git a/modules/v4d/samples/beauty-demo.cpp b/modules/v4d/samples/beauty-demo.cpp index ceda162fb..5cfae4bea 100644 --- a/modules/v4d/samples/beauty-demo.cpp +++ b/modules/v4d/samples/beauty-demo.cpp @@ -26,8 +26,8 @@ constexpr long unsigned int HEIGHT = 720; constexpr long unsigned int WIDTH = 960; constexpr long unsigned int HEIGHT = 540; #endif -constexpr unsigned int DOWNSIZE_WIDTH = 320; -constexpr unsigned int DOWNSIZE_HEIGHT = 180; +constexpr unsigned int DOWNSIZE_WIDTH = 960; +constexpr unsigned int DOWNSIZE_HEIGHT = 540; constexpr bool OFFSCREEN = false; #ifndef __EMSCRIPTEN__ constexpr const char *OUTPUT_FILENAME = "beauty-demo.mkv"; @@ -35,10 +35,10 @@ constexpr const char *OUTPUT_FILENAME = "beauty-demo.mkv"; const unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT)); /* Visualization parameters */ -constexpr int BLUR_DIV = 1000; +constexpr int BLUR_DIV = 500; int blur_skin_kernel_size = std::max(int(DIAG / BLUR_DIV % 2 == 0 ? DIAG / BLUR_DIV + 1 : DIAG / BLUR_DIV), 1); //Saturation boost factor for eyes and lips -float eyes_and_lips_saturation = 1.6f; +float eyes_and_lips_saturation = 2.0f; //Saturation boost factor for skin float skin_saturation = 1.7f; //Contrast factor skin @@ -46,11 +46,11 @@ float skin_contrast = 0.7f; #ifndef __EMSCRIPTEN__ //Show input and output side by side bool side_by_side = true; -//Stretch the video to the window size -bool stretch = true; +//Scale the video to the window size +bool scale = true; #else bool side_by_side = false; -bool stretch = false; +bool scale = false; #endif cv::Ptr window; @@ -126,7 +126,7 @@ struct FaceFeatures { return allPoints; } - //Returns all face features points in fixed order + //Returns all feature points in fixed order vector> features() const { return {chin_, top_nose_, @@ -206,10 +206,10 @@ static void setup_gui(cv::Ptr v) { form.makeGroup("Display"); form.makeFormVariable("Side by side", side_by_side, "Enable or disable side by side view"); - auto* stretchVar = form.makeFormVariable("Stretch", stretch, "Enable or disable stetching to the window size"); - stretchVar->set_callback([=](const bool& b) { - v->setFrameBufferScaling(b); - stretch = b; + auto* scaleVar = form.makeFormVariable("Stretch", scale, "Enable or disable stetching to the window size"); + scaleVar->set_callback([=](const bool& b) { + v->setScaling(b); + scale = b; }); #ifndef __EMSCRIPTEN__ @@ -398,7 +398,7 @@ int main() { window = V4D::make(cv::Size(WIDTH, HEIGHT), cv::Size(), "Beauty Demo", OFFSCREEN); facemark->loadModel("assets/lbfmodel.yaml"); - window->setFrameBufferScaling(stretch); + window->setScaling(scale); if (!OFFSCREEN) { setup_gui(window); diff --git a/modules/v4d/samples/optflow-demo.cpp b/modules/v4d/samples/optflow-demo.cpp index 9c6cc202a..55d9b5473 100644 --- a/modules/v4d/samples/optflow-demo.cpp +++ b/modules/v4d/samples/optflow-demo.cpp @@ -100,7 +100,7 @@ nanogui::Color effect_color(1.0f, 0.75f, 0.4f, 1.0f); //display on-screen FPS bool show_fps = true; //Stretch frame buffer to window size -bool stretch = false; +bool scale = false; //Use OpenCL or not bool use_acceleration = true; //The post processing mode @@ -379,8 +379,8 @@ static void setup_gui(cv::Ptr main, cv::Ptr menu) { form.makeGroup("Display"); form.makeFormVariable("Show FPS", show_fps, "Enable or disable the On-screen FPS display"); - form.makeFormVariable("Stetch", stretch, "Stretch the frame buffer to the window size")->set_callback([=](const bool &s) { - main->setFrameBufferScaling(s); + form.makeFormVariable("Stetch", scale, "Stretch the frame buffer to the window size")->set_callback([=](const bool &s) { + main->setScaling(s); }); #ifndef __EMSCRIPTEN__ diff --git a/modules/v4d/src/detail/framebuffercontext.cpp b/modules/v4d/src/detail/framebuffercontext.cpp index 2ea6f7970..eecabf149 100644 --- a/modules/v4d/src/detail/framebuffercontext.cpp +++ b/modules/v4d/src/detail/framebuffercontext.cpp @@ -22,6 +22,10 @@ namespace cv { namespace v4d { namespace detail { +void glfw_error_callback(int error, const char* description) { + fprintf(stderr, "GLFW Error: (%d) %s\n", error, description); +} + static bool contains_absolute(nanogui::Widget* w, const nanogui::Vector2i& p) { nanogui::Vector2i d = p - w->absolute_position(); return d.x() >= 0 && d.y() >= 0 && d.x() < w->size().x() && d.y() < w->size().y(); @@ -211,7 +215,7 @@ void FrameBufferContext::init() { #endif if (glfwInit() != GLFW_TRUE) assert(false); - glfwSetErrorCallback(cv::v4d::glfw_error_callback); + glfwSetErrorCallback(cv::v4d::detail::glfw_error_callback); if (debug_) glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); diff --git a/modules/v4d/src/detail/nanoguicontext.hpp b/modules/v4d/src/detail/nanoguicontext.hpp index 697dc6bd8..66db418dc 100644 --- a/modules/v4d/src/detail/nanoguicontext.hpp +++ b/modules/v4d/src/detail/nanoguicontext.hpp @@ -6,6 +6,7 @@ #ifndef SRC_OPENCV_NANOGUICONTEXT_HPP_ #define SRC_OPENCV_NANOGUICONTEXT_HPP_ +#include "opencv2/v4d/nvg.hpp" #include "framebuffercontext.hpp" diff --git a/modules/v4d/src/v4d.cpp b/modules/v4d/src/v4d.cpp index b956ee390..f4472e76b 100644 --- a/modules/v4d/src/v4d.cpp +++ b/modules/v4d/src/v4d.cpp @@ -15,11 +15,6 @@ namespace cv { namespace v4d { -namespace detail { -void glfw_error_callback(int error, const char* description) { - fprintf(stderr, "GLFW Error: (%d) %s\n", error, description); -} -} cv::Scalar colorConvert(const cv::Scalar& src, cv::ColorConversionCodes code) { cv::Mat tmpIn(1, 1, CV_8UC3); @@ -464,11 +459,11 @@ void V4D::setVisible(bool v) { nguiCtx().screen().perform_layout(); } -void V4D::setFrameBufferScaling(bool s) { +void V4D::setScaling(bool s) { stretch_ = s; } -bool V4D::isFrameBufferScaling() { +bool V4D::isScaling() { return stretch_; } @@ -494,7 +489,7 @@ void V4D::setDefaultKeyboardEventCallback() { void V4D::swapContextBuffers() { run_sync_on_main<10>([this]() { FrameBufferContext::GLScope glScope(glCtx().fbCtx(), GL_READ_FRAMEBUFFER); - glCtx().fbCtx().blitFrameBufferToScreen(viewport(), glCtx().fbCtx().getWindowSize(), isFrameBufferScaling()); + glCtx().fbCtx().blitFrameBufferToScreen(viewport(), glCtx().fbCtx().getWindowSize(), isScaling()); #ifndef __EMSCRIPTEN__ glfwSwapBuffers(glCtx().fbCtx().getGLFWWindow()); #else @@ -504,7 +499,7 @@ void V4D::swapContextBuffers() { run_sync_on_main<11>([this]() { FrameBufferContext::GLScope glScope(nvgCtx().fbCtx(), GL_READ_FRAMEBUFFER); - nvgCtx().fbCtx().blitFrameBufferToScreen(viewport(), nvgCtx().fbCtx().getWindowSize(), isFrameBufferScaling()); + nvgCtx().fbCtx().blitFrameBufferToScreen(viewport(), nvgCtx().fbCtx().getWindowSize(), isScaling()); #ifndef __EMSCRIPTEN__ glfwSwapBuffers(nvgCtx().fbCtx().getGLFWWindow()); #else @@ -514,7 +509,7 @@ void V4D::swapContextBuffers() { run_sync_on_main<12>([this]() { FrameBufferContext::GLScope glScope(nguiCtx().fbCtx(), GL_READ_FRAMEBUFFER); - nguiCtx().fbCtx().blitFrameBufferToScreen(viewport(), nguiCtx().fbCtx().getWindowSize(), isFrameBufferScaling()); + nguiCtx().fbCtx().blitFrameBufferToScreen(viewport(), nguiCtx().fbCtx().getWindowSize(), isScaling()); #ifndef __EMSCRIPTEN__ glfwSwapBuffers(nguiCtx().fbCtx().getGLFWWindow()); #else @@ -539,7 +534,7 @@ bool V4D::display() { run_sync_on_main<6>([&, this](){ { FrameBufferContext::GLScope glScope(fbCtx(), GL_READ_FRAMEBUFFER); - fbCtx().blitFrameBufferToScreen(viewport(), fbCtx().getWindowSize(), isFrameBufferScaling()); + fbCtx().blitFrameBufferToScreen(viewport(), fbCtx().getWindowSize(), isScaling()); } #ifndef __EMSCRIPTEN__ nguiCtx().render(printFPS_, showFPS_); diff --git a/modules/v4d/tutorials/00-intro.markdown b/modules/v4d/tutorials/00-intro.markdown index 3ebaa4689..e2c78818d 100644 --- a/modules/v4d/tutorials/00-intro.markdown +++ b/modules/v4d/tutorials/00-intro.markdown @@ -114,6 +114,15 @@ make -j8 sudo make install ``` +## Download models +```bash +mkdir assets +cd assets +wget https://github.com/kurnianggoro/GSOC2017/raw/master/data/lbfmodel.yaml +wget https://github.com/opencv/opencv_zoo/raw/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx +cd .. +``` + ## Download the example videos ```bash # big buck bunny video