resize framebuffer behind the scenes

pull/3471/head
kallaballa 2 years ago
parent ba046405ea
commit 94fc18e87c
  1. 13
      src/beauty/beauty-demo.cpp
  2. 1
      src/common/subsystems.hpp
  3. 4
      src/nanovg/nanovg-demo.cpp
  4. 12
      src/optflow/optflow-demo.cpp
  5. 5
      src/pedestrian/pedestrian-demo.cpp
  6. 4
      src/tetra/tetra-demo.cpp
  7. 7
      src/video/video-demo.cpp

@ -212,7 +212,7 @@ int main(int argc, char **argv) {
}); });
//BGR //BGR
cv::UMat rgb, resized, down, faceBgMask, diff, blurred, reduced, sharpened, masked; cv::UMat rgb, down, faceBgMask, diff, blurred, reduced, sharpened, masked;
cv::UMat frameOut(HEIGHT, WIDTH, CV_8UC3); cv::UMat frameOut(HEIGHT, WIDTH, CV_8UC3);
cv::UMat lhalf(HEIGHT * SCALE, WIDTH * SCALE, CV_8UC3); cv::UMat lhalf(HEIGHT * SCALE, WIDTH * SCALE, CV_8UC3);
cv::UMat rhalf(lhalf.size(), lhalf.type()); cv::UMat rhalf(lhalf.size(), lhalf.type());
@ -237,7 +237,6 @@ int main(int argc, char **argv) {
cl::compute([&](CLExecContext_t& clclx, cv::UMat& frameBuffer){ cl::compute([&](CLExecContext_t& clclx, cv::UMat& frameBuffer){
cvtColor(frameBuffer,rgb,cv::COLOR_BGRA2RGB); cvtColor(frameBuffer,rgb,cv::COLOR_BGRA2RGB);
cv::resize(rgb, resized, cv::Size(WIDTH, HEIGHT));
cv::resize(rgb, down, cv::Size(0, 0), SCALE, SCALE); cv::resize(rgb, down, cv::Size(0, 0), SCALE, SCALE);
cvtColor(down, downGrey, cv::COLOR_BGRA2GRAY); cvtColor(down, downGrey, cv::COLOR_BGRA2GRAY);
detector->detect(down, faces); detector->detect(down, faces);
@ -286,8 +285,8 @@ int main(int argc, char **argv) {
cv::subtract(faceBgMaskGrey, faceFgMaskGrey, faceBgMaskGrey); cv::subtract(faceBgMaskGrey, faceFgMaskGrey, faceBgMaskGrey);
cv::bitwise_not(faceBgMaskGrey, faceBgMaskInvGrey); cv::bitwise_not(faceBgMaskGrey, faceBgMaskInvGrey);
unsharp_mask(resized, sharpened, UNSHARP_STRENGTH); unsharp_mask(rgb, sharpened, UNSHARP_STRENGTH);
reduce_shadows(resized, reduced, REDUCE_SHADOW); reduce_shadows(rgb, reduced, REDUCE_SHADOW);
blender.prepare(cv::Rect(0, 0, WIDTH, HEIGHT)); blender.prepare(cv::Rect(0, 0, WIDTH, HEIGHT));
blender.feed(reduced, faceBgMaskGrey, cv::Point(0, 0)); blender.feed(reduced, faceBgMaskGrey, cv::Point(0, 0));
blender.feed(sharpened, faceBgMaskInvGrey, cv::Point(0, 0)); blender.feed(sharpened, faceBgMaskInvGrey, cv::Point(0, 0));
@ -295,11 +294,11 @@ int main(int argc, char **argv) {
frameOutFloat.convertTo(frameOut, CV_8U, 1.0); frameOutFloat.convertTo(frameOut, CV_8U, 1.0);
cv::boxFilter(frameOut, blurred, -1, cv::Size(BLUR_KERNEL_SIZE, BLUR_KERNEL_SIZE), cv::Point(-1, -1), true, cv::BORDER_REPLICATE); cv::boxFilter(frameOut, blurred, -1, cv::Size(BLUR_KERNEL_SIZE, BLUR_KERNEL_SIZE), cv::Point(-1, -1), true, cv::BORDER_REPLICATE);
cv::subtract(blurred, resized, diff); cv::subtract(blurred, rgb, diff);
bitwise_and(diff, faceBgMask, masked); bitwise_and(diff, faceBgMask, masked);
cv::add(frameOut, masked, reduced); cv::add(frameOut, masked, reduced);
cv::resize(resized, lhalf, cv::Size(0, 0), 0.5, 0.5); cv::resize(rgb, lhalf, cv::Size(0, 0), 0.5, 0.5);
cv::resize(reduced, rhalf, cv::Size(0, 0), 0.5, 0.5); cv::resize(reduced, rhalf, cv::Size(0, 0), 0.5, 0.5);
frameOut = cv::Scalar::all(0); frameOut = cv::Scalar::all(0);
@ -310,7 +309,7 @@ int main(int argc, char **argv) {
} else { } else {
cl::compute([&](CLExecContext_t& clclx, cv::UMat &frameBuffer) { cl::compute([&](CLExecContext_t& clclx, cv::UMat &frameBuffer) {
frameOut = cv::Scalar::all(0); frameOut = cv::Scalar::all(0);
cv::resize(resized, lhalf, cv::Size(0, 0), 0.5, 0.5); cv::resize(rgb, lhalf, cv::Size(0, 0), 0.5, 0.5);
lhalf.copyTo(frameOut(cv::Rect(0, 0, lhalf.size().width, lhalf.size().height))); lhalf.copyTo(frameOut(cv::Rect(0, 0, lhalf.size().width, lhalf.size().height)));
lhalf.copyTo(frameOut(cv::Rect(lhalf.size().width, 0, lhalf.size().width, lhalf.size().height))); lhalf.copyTo(frameOut(cv::Rect(lhalf.size().width, 0, lhalf.size().width, lhalf.size().height)));
cvtColor(frameOut, frameBuffer, cv::COLOR_BGR2RGBA); cvtColor(frameOut, frameBuffer, cv::COLOR_BGR2RGBA);

@ -297,6 +297,7 @@ bool read(std::function<void(CLExecContext_t&, cv::UMat&)> fn) {
return false; return false;
//Color-conversion from RGB to BGRA (OpenCL) //Color-conversion from RGB to BGRA (OpenCL)
cv::cvtColor(va::videoFrame, cl::frameBuffer, cv::COLOR_RGB2BGRA); cv::cvtColor(va::videoFrame, cl::frameBuffer, cv::COLOR_RGB2BGRA);
cv::resize(cl::frameBuffer, cl::frameBuffer, cv::Size(app::window_width, app::window_height));
cl::release_to_gl(cl::frameBuffer); cl::release_to_gl(cl::frameBuffer);
return true; return true;
} }

@ -186,9 +186,7 @@ int main(int argc, char **argv) {
//Color-conversion from HSV to RGB. (OpenCL) //Color-conversion from HSV to RGB. (OpenCL)
cv::cvtColor(hsv, rgb, cv::COLOR_HSV2RGB_FULL); cv::cvtColor(hsv, rgb, cv::COLOR_HSV2RGB_FULL);
//Color-conversion from RGB to BGRA. (OpenCL) //Color-conversion from RGB to BGRA. (OpenCL)
cv::cvtColor(rgb, bgra, cv::COLOR_RGB2BGRA); cv::cvtColor(rgb, frameBuffer, cv::COLOR_RGB2BGRA);
//Resize the frame if necessary. (OpenCL)
cv::resize(bgra, frameBuffer, cv::Size(WIDTH, HEIGHT));
}); });
//Render using nanovg //Render using nanovg

@ -181,13 +181,13 @@ void composite_layers(const cv::UMat background, const cv::UMat foreground, cons
cv::add(background, glow, dst); cv::add(background, glow, dst);
} }
nanogui::Window* win;
void setup_gui() { void setup_gui() {
using namespace kb::gui; using namespace kb::gui;
using namespace kb::display; using namespace kb::display;
win = form->add_window(nanogui::Vector2i(6, 45), "Settings"); static nanogui::Window* win = form->add_window(nanogui::Vector2i(6, 45), "Settings");
auto useOpenCL = make_gui_variable("Use OpenCL", use_opencl, "Enable or disable OpenCL acceleration"); auto useOpenCL = make_gui_variable("Use OpenCL", use_opencl, "Enable or disable OpenCL acceleration");
useOpenCL->set_callback([](bool b){ useOpenCL->set_callback([](bool b){
cv::ocl::setUseOpenCL(b); cv::ocl::setUseOpenCL(b);
@ -264,7 +264,7 @@ int main(int argc, char **argv) {
//BGRA //BGRA
cv::UMat background, foreground(frameBufferSize, CV_8UC4, cv::Scalar::all(0)); cv::UMat background, foreground(frameBufferSize, CV_8UC4, cv::Scalar::all(0));
//RGB //RGB
cv::UMat rgb, resized, down; cv::UMat rgb, down;
//GREY //GREY
cv::UMat backgroundGrey, downPrevGrey, downNextGrey, downMotionMaskGrey; cv::UMat backgroundGrey, downPrevGrey, downNextGrey, downMotionMaskGrey;
vector<cv::Point2f> detectedPoints; vector<cv::Point2f> detectedPoints;
@ -279,10 +279,8 @@ int main(int argc, char **argv) {
break; break;
cl::compute([&](CLExecContext_t& clctx, cv::UMat& frameBuffer){ cl::compute([&](CLExecContext_t& clctx, cv::UMat& frameBuffer){
cvtColor(frameBuffer,rgb,cv::COLOR_BGRA2RGB); cv::resize(frameBuffer, down, cv::Size(WIDTH * fg_scale, HEIGHT * fg_scale));
cv::resize(rgb, resized, frameBufferSize); cv::cvtColor(frameBuffer, background, cv::COLOR_RGB2BGRA);
cv::resize(rgb, down, cv::Size(WIDTH * fg_scale, HEIGHT * fg_scale));
cv::cvtColor(resized, background, cv::COLOR_RGB2BGRA);
cv::cvtColor(down, downNextGrey, cv::COLOR_RGB2GRAY); cv::cvtColor(down, downNextGrey, cv::COLOR_RGB2GRAY);
//Subtract the background to create a motion mask //Subtract the background to create a motion mask
prepare_motion_mask(downNextGrey, downMotionMaskGrey); prepare_motion_mask(downNextGrey, downMotionMaskGrey);

@ -163,9 +163,8 @@ int main(int argc, char **argv) {
break; break;
cl::compute([&](CLExecContext_t& clclx, cv::UMat& frameBuffer){ cl::compute([&](CLExecContext_t& clclx, cv::UMat& frameBuffer){
cvtColor(frameBuffer,rgb,cv::COLOR_BGRA2RGB); cvtColor(frameBuffer,videoFrameUp,cv::COLOR_BGRA2RGB);
cv::resize(rgb, videoFrameUp, cv::Size(WIDTH, HEIGHT)); cv::resize(frameBuffer, videoFrameDown, cv::Size(DOWNSIZE_WIDTH, DOWNSIZE_HEIGHT));
cv::resize(rgb, videoFrameDown, cv::Size(DOWNSIZE_WIDTH, DOWNSIZE_HEIGHT));
cv::cvtColor(videoFrameDown, videoFrameDownGrey, cv::COLOR_RGB2GRAY); cv::cvtColor(videoFrameDown, videoFrameDownGrey, cv::COLOR_RGB2GRAY);
cv::cvtColor(videoFrameUp, background, cv::COLOR_RGB2BGRA); cv::cvtColor(videoFrameUp, background, cv::COLOR_RGB2BGRA);
hog.detectMultiScale(videoFrameDownGrey, locations, 0, cv::Size(), cv::Size(), 1.025, 2.0, false); hog.detectMultiScale(videoFrameDownGrey, locations, 0, cv::Size(), cv::Size(), 1.025, 2.0, false);

@ -2,8 +2,8 @@
#include "../common/subsystems.hpp" #include "../common/subsystems.hpp"
constexpr long unsigned int WIDTH = 1920; constexpr long unsigned int WIDTH = 3840;
constexpr long unsigned int HEIGHT = 1080; constexpr long unsigned int HEIGHT = 2160;
constexpr double FPS = 60; constexpr double FPS = 60;
constexpr bool OFFSCREEN = false; constexpr bool OFFSCREEN = false;
constexpr const char* OUTPUT_FILENAME = "tetra-demo.mkv"; constexpr const char* OUTPUT_FILENAME = "tetra-demo.mkv";

@ -6,7 +6,7 @@
constexpr long unsigned int WIDTH = 1920; constexpr long unsigned int WIDTH = 1920;
constexpr long unsigned int HEIGHT = 1080; constexpr long unsigned int HEIGHT = 1080;
constexpr const int VA_HW_DEVICE_INDEX = 0; constexpr const int VA_HW_DEVICE_INDEX = 0;
constexpr bool OFFSCREEN = true; constexpr bool OFFSCREEN = false;
constexpr const char* OUTPUT_FILENAME = "video-demo.mkv"; constexpr const char* OUTPUT_FILENAME = "video-demo.mkv";
constexpr unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT)); constexpr unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT));
@ -129,11 +129,6 @@ int main(int argc, char **argv) {
if(!success) if(!success)
break; break;
cl::compute([](CLExecContext_t& clctx, cv::UMat& frameBuffer){
//Resize the frame if necessary. (OpenCL)
cv::resize(frameBuffer, frameBuffer, cv::Size(WIDTH, HEIGHT));
});
gl::render([](int w, int h) { gl::render([](int w, int h) {
//Render using OpenGL //Render using OpenGL
render_scene(w, h); render_scene(w, h);

Loading…
Cancel
Save