latest changes

pull/3471/head
kallaballa 2 years ago
parent 526def2f33
commit 0580c2ca58
  1. 11
      src/common/detail/clvacontext.cpp
  2. 8
      src/common/viz2d.cpp
  3. 2
      src/common/viz2d.hpp
  4. 33
      src/optflow/optflow-demo.cpp

@ -24,9 +24,14 @@ cv::Size CLVAContext::getVideoFrameSize() {
bool CLVAContext::capture(std::function<void(cv::UMat&)> 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());

@ -369,12 +369,20 @@ bool Viz2D::capture() {
});
}
bool Viz2D::capture(std::function<void(cv::UMat&)> fn) {
return clva().capture(fn);
}
void Viz2D::write() {
clva().write([=, this](const cv::UMat &videoFrame) {
*(this->writer_) << videoFrame;
});
}
void Viz2D::write(std::function<void(const cv::UMat&)> fn) {
clva().write(fn);
}
void Viz2D::makeCurrent() {
glfwMakeContextCurrent(getGLFWWindow());
}

@ -96,7 +96,9 @@ public:
void clear(const cv::Scalar& rgba = cv::Scalar(0,0,0,255));
bool capture();
bool capture(std::function<void(cv::UMat&)> fn);
void write();
void write(std::function<void(const cv::UMat&)> 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);

@ -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<kb::viz2d::Viz2D> v2d, cv::Ptr<kb::viz2d::Viz2D> 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<kb::viz2d::Viz2D> v2d, cv::Ptr<kb::viz2d::Viz2D> 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<cv::Point2f> 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;

Loading…
Cancel
Save