diff --git a/src/common/viz2d.hpp b/src/common/viz2d.hpp index 7bce9808d..f6d755377 100644 --- a/src/common/viz2d.hpp +++ b/src/common/viz2d.hpp @@ -133,7 +133,6 @@ public: void close(); bool display(); - nanogui::FormHelper* form(); Viz2DWindow* makeWindow(int x, int y, const string& title); nanogui::Label* makeGroup(const string& label); nanogui::detail::FormWidget* makeFormVariable(const string &name, bool &v, const string &tooltip = "", bool visible = true, bool enabled = true); @@ -162,6 +161,7 @@ public: private: virtual bool keyboard_event(int key, int scancode, int action, int modifiers) override; void setMousePosition(int x, int y); + nanogui::FormHelper* form(); CLGLContext& clgl(); CLVAContext& clva(); NanoVGContext& nvg(); diff --git a/src/optflow/optflow-demo.cpp b/src/optflow/optflow-demo.cpp index 7b8ee4eb8..d228253ff 100644 --- a/src/optflow/optflow-demo.cpp +++ b/src/optflow/optflow-demo.cpp @@ -274,17 +274,29 @@ void setup_gui(cv::Ptr v2d, cv::Ptr v2dMenu) v2d->makeGroup("Optical flow"); v2d->makeFormVariable("Max. Stroke Size", max_stroke, 1, 100, true, "px", "The theoretical maximum size of the drawing stroke which is scaled by the area of the convex hull of tracked points and therefor is usually much smaller"); - v2d->makeColorPicker("Color", effect_color, "The primary effect color",[](const nanogui::Color &c) { + v2d->makeColorPicker("Color", effect_color, "The primary effect color",[&](const nanogui::Color &c) { effect_color[0] = c[0]; effect_color[1] = c[1]; effect_color[2] = c[2]; + effect_color[3] = alpha; }); v2d->makeFormVariable("Alpha", alpha, 0.0f, 1.0f, true, "", "The opacity of the effect"); v2d->makeGroup("Post Processing"); auto* enableBloom = v2d->makeFormVariable("Enable Bloom", use_bloom, "Enable or disable the bloom effect"); auto* kernelSize = v2d->makeFormVariable("Kernel Size", kernel_size, 1, 63, true, "", "Intensity of glow defined by kernel size"); - kernelSize->set_callback([](const int& k) { - kernel_size = std::max(int(k % 2 == 0 ? k + 1 : k), 1); + kernelSize->set_callback([=](const int& k) { + static int lastKernelSize = kernel_size; + + if(k == lastKernelSize) + return; + + if(k <= lastKernelSize) { + kernel_size = std::max(int(k % 2 == 0 ? k - 1 : k), 1); + } else if(k > lastKernelSize) + kernel_size = std::max(int(k % 2 == 0 ? k + 1 : k), 1); + + lastKernelSize = k; + kernelSize->set_value(kernel_size); }); auto* thresh = v2d->makeFormVariable("Threshold", bloom_thresh, 1, 255, true, "", "The lightness selection threshold", true, false); @@ -390,7 +402,7 @@ int main(int argc, char **argv) { //We don't want the algorithm to get out of hand when there is a scene change, so we suppress it when we detect one. if (!detect_scene_change(downMotionMaskGrey, scene_change_thresh, scene_change_thresh_diff)) { //Visualize the sparse optical flow using nanovg - cv::Scalar color = cv::Scalar(effect_color.b() * 255.0f, effect_color.g() * 255.0f, effect_color.r() * 255.0f, alpha * 255.0f); + cv::Scalar color = cv::Scalar(effect_color.b() * 255.0f, effect_color.g() * 255.0f, effect_color.r() * 255.0f, effect_color.a() * 255.0f); visualize_sparse_optical_flow(downPrevGrey, downNextGrey, detectedPoints, fg_scale, max_stroke, color, max_points, point_loss); } }