From f7b2903cc1040ac4dea2fdce9af558c76832b2ce Mon Sep 17 00:00:00 2001 From: kallaballa Date: Sat, 19 Nov 2022 22:31:29 +0100 Subject: [PATCH] adjust to new opencv draft --- Makefile | 2 +- src/optflow/optflow-demo.cpp | 2 ++ src/tetra/tetra-demo.cpp | 21 ++++++++++++--------- src/video/video-demo.cpp | 20 +++++++++++--------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 34ec3a860..7687b8037 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CXX := g++ -CXXFLAGS := -std=c++20 -pthread -fno-strict-aliasing -pedantic -Wall -march=native -flto +CXXFLAGS := -std=c++20 -pthread -fno-strict-aliasing -pedantic -Wall -march=native -flto -I/usr/include/opencv4/ LDFLAGS := -L/opt/local/lib -flto LIBS := -lnanovg .PHONY: all release debian-release info debug asan clean debian-clean distclean diff --git a/src/optflow/optflow-demo.cpp b/src/optflow/optflow-demo.cpp index 28c01cc8f..14e8ef391 100644 --- a/src/optflow/optflow-demo.cpp +++ b/src/optflow/optflow-demo.cpp @@ -1,5 +1,6 @@ #define CL_TARGET_OPENCL_VERSION 120 +//WIDTH and HEIGHT have to be specified before including subsystems.hpp constexpr unsigned long WIDTH = 1920; constexpr unsigned long HEIGHT = 1080; constexpr bool OFFSCREEN = false; @@ -67,6 +68,7 @@ bool detect_scene_change(const cv::UMat& srcMotionMaskGrey, float thresh, float float relation = movement > 0 && last_movement > 0 ? std::max(movement, last_movement) / std::min(movement, last_movement) : 0; float relM = relation * log10(1.0f + (movement * 9.0)); float relLM = relation * log10(1.0f + (last_movement * 9.0)); + bool result = !((movement > 0 && last_movement > 0 && relation > 0) && (relM < thresh && relLM < thresh && fabs(relM - relLM) < theshDiff)); last_movement = (last_movement + movement) / 2.0f; diff --git a/src/tetra/tetra-demo.cpp b/src/tetra/tetra-demo.cpp index b799c65a8..5df56b888 100644 --- a/src/tetra/tetra-demo.cpp +++ b/src/tetra/tetra-demo.cpp @@ -1,5 +1,6 @@ #define CL_TARGET_OPENCL_VERSION 120 +//WIDTH and HEIGHT have to be specified before including subsystems.hpp constexpr long unsigned int WIDTH = 1920; constexpr long unsigned int HEIGHT = 1080; constexpr double FPS = 60; @@ -7,6 +8,8 @@ constexpr bool OFFSCREEN = false; constexpr const char* OUTPUT_FILENAME = "tetra-demo.mkv"; constexpr const int VA_HW_DEVICE_INDEX = 0; +constexpr int GLOW_KERNEL_SIZE = WIDTH / 120 % 2 == 0 ? WIDTH / 120 + 1 : WIDTH / 120; + #include "../common/subsystems.hpp" using std::cerr; @@ -52,26 +55,26 @@ void render_scene() { glEnd(); } -void glow_effect(cv::UMat &src, int ksize = WIDTH / 85 % 2 == 0 ? WIDTH / 85 + 1 : WIDTH / 85) { +void glow_effect(const cv::UMat &src, cv::UMat &dst, const int ksize) { static cv::UMat resize; static cv::UMat blur; - static cv::UMat src16; + static cv::UMat dst16; - cv::bitwise_not(src, src); + cv::bitwise_not(src, dst); //Resize for some extra performance - cv::resize(src, resize, cv::Size(), 0.5, 0.5); + cv::resize(dst, resize, cv::Size(), 0.5, 0.5); //Cheap blur cv::boxFilter(resize, resize, -1, cv::Size(ksize, ksize), cv::Point(-1,-1), true, cv::BORDER_REPLICATE); //Back to original size - cv::resize(resize, blur, cv::Size(WIDTH, HEIGHT)); + cv::resize(resize, blur, src.size()); //Multiply the src image with a blurred version of itself - cv::multiply(src, blur, src16, 1, CV_16U); + cv::multiply(dst, blur, dst16, 1, CV_16U); //Normalize and convert back to CV_8U - cv::divide(src16, cv::Scalar::all(255.0), src, 1, CV_8U); + cv::divide(dst16, cv::Scalar::all(255.0), dst, 1, CV_8U); - cv::bitwise_not(src, src); + cv::bitwise_not(dst, dst); } int main(int argc, char **argv) { @@ -116,7 +119,7 @@ int main(int argc, char **argv) { //Aquire the frame buffer for use by OpenCL gl::acquire_from_gl(frameBuffer); //Glow effect (OpenCL) - glow_effect(frameBuffer); + glow_effect(frameBuffer, frameBuffer, GLOW_KERNEL_SIZE); //Color-conversion from BGRA to RGB. OpenCV/OpenCL. cv::cvtColor(frameBuffer, videoFrame, cv::COLOR_BGRA2RGB); //Release the frame buffer for use by OpenGL diff --git a/src/video/video-demo.cpp b/src/video/video-demo.cpp index daefce4b8..46bf381d0 100644 --- a/src/video/video-demo.cpp +++ b/src/video/video-demo.cpp @@ -7,6 +7,8 @@ constexpr const int VA_HW_DEVICE_INDEX = 0; constexpr bool OFFSCREEN = false; constexpr const char *OUTPUT_FILENAME = "video-demo.mkv"; +constexpr int GLOW_KERNEL_SIZE = WIDTH / 120 % 2 == 0 ? WIDTH / 120 + 1 : WIDTH / 120; + #include "../common/subsystems.hpp" #include @@ -54,26 +56,26 @@ void render_scene() { glEnd(); } -void glow_effect(cv::UMat &src, int ksize = WIDTH / 85 % 2 == 0 ? WIDTH / 85 + 1 : WIDTH / 85) { +void glow_effect(const cv::UMat &src, cv::UMat &dst, const int ksize) { static cv::UMat resize; static cv::UMat blur; - static cv::UMat src16; + static cv::UMat dst16; - cv::bitwise_not(src, src); + cv::bitwise_not(src, dst); //Resize for some extra performance - cv::resize(src, resize, cv::Size(), 0.5, 0.5); + cv::resize(dst, resize, cv::Size(), 0.5, 0.5); //Cheap blur cv::boxFilter(resize, resize, -1, cv::Size(ksize, ksize), cv::Point(-1,-1), true, cv::BORDER_REPLICATE); //Back to original size - cv::resize(resize, blur, cv::Size(WIDTH, HEIGHT)); + cv::resize(resize, blur, src.size()); //Multiply the src image with a blurred version of itself - cv::multiply(src, blur, src16, 1, CV_16U); + cv::multiply(dst, blur, dst16, 1, CV_16U); //Normalize and convert back to CV_8U - cv::divide(src16, cv::Scalar::all(255.0), src, 1, CV_8U); + cv::divide(dst16, cv::Scalar::all(255.0), dst, 1, CV_8U); - cv::bitwise_not(src, src); + cv::bitwise_not(dst, dst); } int main(int argc, char **argv) { @@ -158,7 +160,7 @@ int main(int argc, char **argv) { //Aquire the frame buffer for use by OpenCL gl::acquire_from_gl(frameBuffer); //Glow effect (OpenCL) - glow_effect(frameBuffer); + glow_effect(frameBuffer, frameBuffer, GLOW_KERNEL_SIZE); //Color-conversion from BGRA to RGB. (OpenCL) cv::cvtColor(frameBuffer, videoFrame, cv::COLOR_BGRA2RGB); //Release the frame buffer for use by OpenGL