diff --git a/src/common/detail/clvacontext.cpp b/src/common/detail/clvacontext.cpp index 9ec38ab3b..63f19f04d 100644 --- a/src/common/detail/clvacontext.cpp +++ b/src/common/detail/clvacontext.cpp @@ -24,9 +24,14 @@ cv::Size CLVAContext::getVideoFrameSize() { bool CLVAContext::capture(std::function fn) { { - CLExecScope_t scope(context_); - fn(videoFrame_); - videoFrameSize_ = videoFrame_.size(); + if(!context_ .empty()) { + CLExecScope_t scope(context_); + fn(videoFrame_); + videoFrameSize_ = videoFrame_.size(); + } else { + fn(videoFrame_); + videoFrameSize_ = videoFrame_.size(); + } } { CLExecScope_t scope(clglContext_.getCLExecContext()); diff --git a/src/common/viz2d.cpp b/src/common/viz2d.cpp index 44cf4bad4..8a2c8ae8b 100644 --- a/src/common/viz2d.cpp +++ b/src/common/viz2d.cpp @@ -369,12 +369,20 @@ bool Viz2D::capture() { }); } +bool Viz2D::capture(std::function fn) { + return clva().capture(fn); +} + void Viz2D::write() { clva().write([=, this](const cv::UMat &videoFrame) { *(this->writer_) << videoFrame; }); } +void Viz2D::write(std::function fn) { + clva().write(fn); +} + void Viz2D::makeCurrent() { glfwMakeContextCurrent(getGLFWWindow()); } diff --git a/src/common/viz2d.hpp b/src/common/viz2d.hpp index e462b3de8..792d0b39e 100644 --- a/src/common/viz2d.hpp +++ b/src/common/viz2d.hpp @@ -96,7 +96,9 @@ public: void clear(const cv::Scalar& rgba = cv::Scalar(0,0,0,255)); bool capture(); + bool capture(std::function fn); void write(); + void write(std::function fn); cv::VideoWriter& makeVAWriter(const string& outputFilename, const int fourcc, const float fps, const cv::Size& frameSize, const int vaDeviceIndex); cv::VideoCapture& makeVACapture(const string& intputFilename, const int vaDeviceIndex); cv::VideoWriter& makeWriter(const string& outputFilename, const int fourcc, const float fps, const cv::Size& frameSize); diff --git a/src/optflow/optflow-demo.cpp b/src/optflow/optflow-demo.cpp index d2ccf0e06..f2df656e2 100644 --- a/src/optflow/optflow-demo.cpp +++ b/src/optflow/optflow-demo.cpp @@ -21,17 +21,6 @@ using std::vector; using std::string; using namespace std::literals::chrono_literals; -/** Application parameters **/ - -constexpr unsigned int WIDTH = 1920; -constexpr unsigned int HEIGHT = 1080; -constexpr unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT)); -constexpr const char* OUTPUT_FILENAME = "optflow-demo.mkv"; -constexpr bool OFFSCREEN = false; -constexpr int VA_HW_DEVICE_INDEX = 0; - -/** Visualization parameters **/ - enum BackgroundModes { GREY, COLOR, @@ -45,6 +34,17 @@ enum PostProcModes { NONE }; +/** Application parameters **/ + +constexpr unsigned int WIDTH = 1920; +constexpr unsigned int HEIGHT = 1080; +constexpr unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT)); +constexpr const char* OUTPUT_FILENAME = "optflow-demo.mkv"; +constexpr bool OFFSCREEN = false; +constexpr int VA_HW_DEVICE_INDEX = 0; + +/** Visualization parameters **/ + // Generate the foreground at this scale. float fg_scale = 0.5f; // On every frame the foreground loses on brightness. specifies the loss in percent. @@ -291,7 +291,7 @@ void setup_gui(cv::Ptr v2d, cv::Ptr v2dMenu) }); v2d->makeFormVariable("Alpha", alpha, 0.0f, 1.0f, true, "", "The opacity of the effect"); v2d->makeGroup("Post Processing"); - auto* enableBloom = v2d->makeComboBox("Mode",post_proc_mode, {"Glow", "Bloom", "None"}); + auto* postPocMode = v2d->makeComboBox("Mode",post_proc_mode, {"Glow", "Bloom", "None"}); auto* kernelSize = v2d->makeFormVariable("Kernel Size", kernel_size, 1, 63, true, "", "Intensity of glow defined by kernel size"); kernelSize->set_callback([=](const int& k) { static int lastKernelSize = kernel_size; @@ -310,7 +310,7 @@ void setup_gui(cv::Ptr v2d, cv::Ptr v2dMenu) auto* thresh = v2d->makeFormVariable("Threshold", bloom_thresh, 1, 255, true, "", "The lightness selection threshold", true, false); auto* gain = v2d->makeFormVariable("Gain", bloom_gain, 0.1f, 20.0f, true, "", "Intensity of the effect defined by gain", true, false); - enableBloom->set_callback([&,kernelSize, thresh, gain](const int& m) { + postPocMode->set_callback([&,kernelSize, thresh, gain](const int& m) { if(m == BLOOM) { thresh->set_enabled(true); gain->set_enabled(true); @@ -383,6 +383,8 @@ int main(int argc, char **argv) { //BGRA cv::UMat background, down; cv::UMat foreground(v2d->getFrameBufferSize(), CV_8UC4, cv::Scalar::all(0)); + //RGB + cv::UMat menuFrame; //GREY cv::UMat downPrevGrey, downNextGrey, downMotionMaskGrey; vector detectedPoints; @@ -422,12 +424,17 @@ int main(int argc, char **argv) { v2d->opencl([&](cv::UMat& frameBuffer){ //Put it all together (OpenCL) composite_layers(background, foreground, frameBuffer, frameBuffer, kernel_size, fg_loss, background_mode, post_proc_mode); + cvtColor(frameBuffer, menuFrame, cv::COLOR_BGRA2RGB); }); update_fps(v2d, show_fps); v2d->write(); + v2dMenu->capture([=](cv::UMat& videoFrame) { + menuFrame.copyTo(videoFrame); + }); + //If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed. if(!v2d->display()) break;