refactoring, renaming and commenting

pull/3471/head
kallaballa 3 years ago
parent a12f1cb582
commit 745e41dee5
  1. 17
      src/beauty/beauty-demo.cpp
  2. 30
      src/common/subsystems.hpp
  3. 18
      src/font/font-demo.cpp
  4. 6
      src/nanovg/nanovg-demo.cpp
  5. 19
      src/optflow/optflow-demo.cpp
  6. 22
      src/pedestrian/pedestrian-demo.cpp
  7. 21
      src/tetra/tetra-demo.cpp
  8. 22
      src/video/video-demo.cpp

@ -1,13 +1,5 @@
#define CL_TARGET_OPENCL_VERSION 120 #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 double SCALE = 0.125;
constexpr bool OFFSCREEN = true;
constexpr int VA_HW_DEVICE_INDEX = 0;
constexpr int BLUR_KERNEL_SIZE = WIDTH / 360 % 2 == 0 ? WIDTH / 360 + 1 : WIDTH / 360;
#include "../common/subsystems.hpp" #include "../common/subsystems.hpp"
#include <vector> #include <vector>
@ -18,6 +10,13 @@ constexpr int BLUR_KERNEL_SIZE = WIDTH / 360 % 2 == 0 ? WIDTH / 360 + 1 : WIDTH
#include <opencv2/face.hpp> #include <opencv2/face.hpp>
#include <opencv2/stitching/detail/blenders.hpp> #include <opencv2/stitching/detail/blenders.hpp>
constexpr unsigned long WIDTH = 1920;
constexpr unsigned long HEIGHT = 1080;
constexpr double SCALE = 0.125;
constexpr bool OFFSCREEN = true;
constexpr int VA_HW_DEVICE_INDEX = 0;
constexpr int BLUR_KERNEL_SIZE = WIDTH / 360 % 2 == 0 ? WIDTH / 360 + 1 : WIDTH / 360;
using std::cerr; using std::cerr;
using std::endl; using std::endl;
using std::vector; using std::vector;
@ -178,6 +177,8 @@ int main(int argc, char **argv) {
exit(1); exit(1);
} }
kb::init(WIDTH, HEIGHT);
cv::Ptr<cv::FaceDetectorYN> detector = cv::FaceDetectorYN::create("assets/face_detection_yunet_2022mar.onnx", "", cv::Size(320, 320), 0.9, 0.3, 5000, cv::dnn::DNN_BACKEND_OPENCV, cv::dnn::DNN_TARGET_OPENCL); cv::Ptr<cv::FaceDetectorYN> detector = cv::FaceDetectorYN::create("assets/face_detection_yunet_2022mar.onnx", "", cv::Size(320, 320), 0.9, 0.3, 5000, cv::dnn::DNN_BACKEND_OPENCV, cv::dnn::DNN_TARGET_OPENCL);
cv::Ptr<cv::face::Facemark> facemark = cv::face::createFacemarkLBF(); cv::Ptr<cv::face::Facemark> facemark = cv::face::createFacemarkLBF();
cv::detail::MultiBandBlender blender(true); cv::detail::MultiBandBlender blender(true);

@ -31,6 +31,14 @@ using std::cerr;
using std::endl; using std::endl;
namespace kb { namespace kb {
unsigned long WINDOW_WIDTH;
unsigned long WINDOW_HEIGHT;
void init(unsigned long width, unsigned long height) {
WINDOW_WIDTH = width;
WINDOW_HEIGHT = height;
}
void gl_check_error(const std::filesystem::path &file, unsigned int line, const char *expression) { void gl_check_error(const std::filesystem::path &file, unsigned int line, const char *expression) {
GLint errorCode = glGetError(); GLint errorCode = glGetError();
@ -124,7 +132,7 @@ void init() {
xroot = DefaultRootWindow(xdisplay); xroot = DefaultRootWindow(xdisplay);
XSetWindowAttributes swa; XSetWindowAttributes swa;
swa.event_mask = ClientMessage; swa.event_mask = ClientMessage;
xwin = XCreateWindow(xdisplay, xroot, 0, 0, WIDTH, HEIGHT, 0, xwin = XCreateWindow(xdisplay, xroot, 0, 0, kb::WINDOW_WIDTH, kb::WINDOW_HEIGHT, 0,
CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &swa); CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &swa);
XSetWindowAttributes xattr; XSetWindowAttributes xattr;
@ -295,8 +303,8 @@ void init(bool debug = false) {
EGL_CHECK(surface = eglCreateWindowSurface(display, configs[0], x11::get_x11_window(), nullptr)); EGL_CHECK(surface = eglCreateWindowSurface(display, configs[0], x11::get_x11_window(), nullptr));
} else { } else {
EGLint pbuffer_attrib_list[] = { EGLint pbuffer_attrib_list[] = {
EGL_WIDTH, WIDTH, EGL_WIDTH, kb::WINDOW_WIDTH,
EGL_HEIGHT, HEIGHT, EGL_HEIGHT, kb::WINDOW_HEIGHT,
EGL_NONE }; EGL_NONE };
EGL_CHECK(surface = eglCreatePbufferSurface(display, configs[0], pbuffer_attrib_list)); EGL_CHECK(surface = eglCreatePbufferSurface(display, configs[0], pbuffer_attrib_list));
} }
@ -365,11 +373,11 @@ void init() {
GL_CHECK(glGenRenderbuffers(1, &render_buf)); GL_CHECK(glGenRenderbuffers(1, &render_buf));
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, render_buf)); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, render_buf));
GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, WIDTH, HEIGHT)); GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kb::WINDOW_WIDTH, kb::WINDOW_HEIGHT));
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, render_buf)); GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, render_buf));
frame_buf_tex = new cv::ogl::Texture2D(cv::Size(WIDTH, HEIGHT), cv::ogl::Texture2D::RGBA, false); frame_buf_tex = new cv::ogl::Texture2D(cv::Size(kb::WINDOW_WIDTH, kb::WINDOW_HEIGHT), cv::ogl::Texture2D::RGBA, false);
frame_buf_tex->bind(); frame_buf_tex->bind();
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, frame_buf_tex->texId(), 0)); GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, frame_buf_tex->texId(), 0));
@ -400,7 +408,7 @@ void blit_frame_buffer_to_screen() {
glBindFramebuffer(GL_READ_FRAMEBUFFER, kb::gl::frame_buf); glBindFramebuffer(GL_READ_FRAMEBUFFER, kb::gl::frame_buf);
glReadBuffer(GL_COLOR_ATTACHMENT0); glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, 0, kb::WINDOW_WIDTH, kb::WINDOW_HEIGHT, 0, 0, kb::WINDOW_WIDTH, kb::WINDOW_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
bool display() { bool display() {
@ -447,8 +455,8 @@ void clear(const float& r = 0.0f, const float& g = 0.0f, const float& b = 0.0f)
void begin() { void begin() {
gl::begin(); gl::begin();
float w = WIDTH; float w = kb::WINDOW_WIDTH;
float h = HEIGHT; float h = kb::WINDOW_HEIGHT;
if(x11::is_initialized()) { if(x11::is_initialized()) {
auto ws = x11::get_window_size(); auto ws = x11::get_window_size();
w = ws.first; w = ws.first;
@ -457,8 +465,8 @@ void begin() {
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, kb::gl::frame_buf)); GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, kb::gl::frame_buf));
nvgSave(vg); nvgSave(vg);
GL_CHECK(glViewport(0, HEIGHT - h, w, h)); GL_CHECK(glViewport(0, WINDOW_HEIGHT - h, w, h));
nvgBeginFrame(vg, w, h, std::fmax(WIDTH/w, HEIGHT/h)); nvgBeginFrame(vg, w, h, std::fmax(kb::WINDOW_WIDTH/w, kb::WINDOW_HEIGHT/h));
} }
void end() { void end() {
@ -468,7 +476,7 @@ void end() {
} }
void init(bool debug = false) { void init(bool debug = false) {
GL_CHECK(glViewport(0, 0, WIDTH, HEIGHT)); GL_CHECK(glViewport(0, 0, kb::WINDOW_WIDTH, kb::WINDOW_HEIGHT));
GL_CHECK(glEnable(GL_STENCIL_TEST)); GL_CHECK(glEnable(GL_STENCIL_TEST));
GL_CHECK(glStencilMask(~0)); GL_CHECK(glStencilMask(~0));
GL_CHECK(glClearColor(0.0f, 0.0f, 0.0f, 1.0f)); GL_CHECK(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));

@ -1,13 +1,5 @@
#define CL_TARGET_OPENCL_VERSION 120 #define CL_TARGET_OPENCL_VERSION 120
constexpr unsigned long WIDTH = 1920;
constexpr unsigned long HEIGHT = 1080;
constexpr bool OFFSCREEN = false;
constexpr const char *OUTPUT_FILENAME = "font-demo.mkv";
constexpr const int VA_HW_DEVICE_INDEX = 0;
constexpr double FPS = 60;
constexpr float FONT_SIZE = 40.0f;
#include "../common/subsystems.hpp" #include "../common/subsystems.hpp"
#include <string> #include <string>
@ -16,6 +8,14 @@ constexpr float FONT_SIZE = 40.0f;
#include <sstream> #include <sstream>
#include <limits> #include <limits>
constexpr unsigned long WIDTH = 1920;
constexpr unsigned long HEIGHT = 1080;
constexpr bool OFFSCREEN = false;
constexpr const char *OUTPUT_FILENAME = "font-demo.mkv";
constexpr const int VA_HW_DEVICE_INDEX = 0;
constexpr double FPS = 60;
constexpr float FONT_SIZE = 40.0f;
using std::cerr; using std::cerr;
using std::endl; using std::endl;
using std::string; using std::string;
@ -25,6 +25,8 @@ using std::stringstream;
int main(int argc, char **argv) { int main(int argc, char **argv) {
using namespace kb; using namespace kb;
kb::init(WIDTH, HEIGHT);
//Initialize VP9 HW encoding using VAAPI //Initialize VP9 HW encoding using VAAPI
cv::VideoWriter writer(OUTPUT_FILENAME, cv::CAP_FFMPEG, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT), { cv::VideoWriter writer(OUTPUT_FILENAME, cv::CAP_FFMPEG, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT), {
cv::VIDEOWRITER_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI, cv::VIDEOWRITER_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI,

@ -1,13 +1,13 @@
#define CL_TARGET_OPENCL_VERSION 120 #define CL_TARGET_OPENCL_VERSION 120
#include "../common/subsystems.hpp"
constexpr unsigned long WIDTH = 1920; constexpr unsigned long WIDTH = 1920;
constexpr unsigned long HEIGHT = 1080; constexpr unsigned long HEIGHT = 1080;
constexpr bool OFFSCREEN = false; constexpr bool OFFSCREEN = false;
constexpr const char *OUTPUT_FILENAME = "nanovg-demo.mkv"; constexpr const char *OUTPUT_FILENAME = "nanovg-demo.mkv";
constexpr const int VA_HW_DEVICE_INDEX = 0; constexpr const int VA_HW_DEVICE_INDEX = 0;
#include "../common/subsystems.hpp"
using std::cerr; using std::cerr;
using std::endl; using std::endl;
@ -122,6 +122,8 @@ int main(int argc, char **argv) {
exit(1); exit(1);
} }
kb::init(WIDTH, HEIGHT);
//Initialize MJPEG HW decoding using VAAPI //Initialize MJPEG HW decoding using VAAPI
cv::VideoCapture capture(argv[1], cv::CAP_FFMPEG, { cv::VideoCapture capture(argv[1], cv::CAP_FFMPEG, {
cv::CAP_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX, cv::CAP_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX,

@ -2,13 +2,6 @@
#include <cmath> #include <cmath>
//WIDTH and HEIGHT have to be specified before including subsystems.hpp
constexpr unsigned long WIDTH = 1920;
constexpr unsigned long HEIGHT = 1080;
constexpr unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT));
constexpr bool OFFSCREEN = false;
constexpr int VA_HW_DEVICE_INDEX = 0;
#include "../common/subsystems.hpp" #include "../common/subsystems.hpp"
#include <vector> #include <vector>
#include <string> #include <string>
@ -17,13 +10,21 @@ constexpr int VA_HW_DEVICE_INDEX = 0;
#include <opencv2/imgproc.hpp> #include <opencv2/imgproc.hpp>
#include <opencv2/optflow.hpp> #include <opencv2/optflow.hpp>
/** Application parameters **/
constexpr unsigned long WIDTH = 1920;
constexpr unsigned long HEIGHT = 1080;
constexpr unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT));
constexpr bool OFFSCREEN = false;
constexpr int VA_HW_DEVICE_INDEX = 0;
/** Visualization parameters **/ /** Visualization parameters **/
// Generate the foreground at this scale. // Generate the foreground at this scale.
constexpr float FG_SCALE = 0.5f; constexpr float FG_SCALE = 0.5f;
// On every frame the foreground loses on brightness. specifies the loss in percent. // On every frame the foreground loses on brightness. specifies the loss in percent.
constexpr float FG_LOSS = 4.7; constexpr float FG_LOSS = 4.7;
// Peak thresholds for the scene change detection. Raising them makes the detection less sensitive but // Peak thresholds for the scene change detection. Lowering them makes the detection more sensitive but
// the default should be fine. // the default should be fine.
constexpr float SCENE_CHANGE_THRESH = 0.29f; constexpr float SCENE_CHANGE_THRESH = 0.29f;
constexpr float SCENE_CHANGE_THRESH_DIFF = 0.1f; constexpr float SCENE_CHANGE_THRESH_DIFF = 0.1f;
@ -182,6 +183,8 @@ int main(int argc, char **argv) {
exit(1); exit(1);
} }
kb::init(WIDTH, HEIGHT);
cv::VideoCapture capture(argv[1], cv::CAP_FFMPEG, { cv::VideoCapture capture(argv[1], cv::CAP_FFMPEG, {
cv::CAP_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX, cv::CAP_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX,
cv::CAP_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI, cv::CAP_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI,

@ -1,15 +1,5 @@
#define CL_TARGET_OPENCL_VERSION 120 #define CL_TARGET_OPENCL_VERSION 120
constexpr unsigned long WIDTH = 1280;
constexpr unsigned long HEIGHT = 720;
constexpr unsigned long DOWNSIZE_WIDTH = 640;
constexpr unsigned long DOWNSIZE_HEIGHT = 360;
constexpr double WIDTH_FACTOR = double(WIDTH) / DOWNSIZE_WIDTH;
constexpr double HEIGHT_FACTOR = double(HEIGHT) / DOWNSIZE_HEIGHT;
constexpr bool OFFSCREEN = false;
constexpr const int VA_HW_DEVICE_INDEX = 0;
constexpr const char *OUTPUT_FILENAME = "pedestrian-demo.mkv";
#include "../common/tsafe_queue.hpp" #include "../common/tsafe_queue.hpp"
#include "../common/subsystems.hpp" #include "../common/subsystems.hpp"
#include <csignal> #include <csignal>
@ -20,6 +10,16 @@ constexpr const char *OUTPUT_FILENAME = "pedestrian-demo.mkv";
#include <opencv2/objdetect/objdetect.hpp> #include <opencv2/objdetect/objdetect.hpp>
constexpr unsigned long WIDTH = 1280;
constexpr unsigned long HEIGHT = 720;
constexpr unsigned long DOWNSIZE_WIDTH = 640;
constexpr unsigned long DOWNSIZE_HEIGHT = 360;
constexpr double WIDTH_FACTOR = double(WIDTH) / DOWNSIZE_WIDTH;
constexpr double HEIGHT_FACTOR = double(HEIGHT) / DOWNSIZE_HEIGHT;
constexpr bool OFFSCREEN = false;
constexpr const int VA_HW_DEVICE_INDEX = 0;
constexpr const char *OUTPUT_FILENAME = "pedestrian-demo.mkv";
using std::cerr; using std::cerr;
using std::endl; using std::endl;
using std::vector; using std::vector;
@ -42,6 +42,8 @@ int main(int argc, char **argv) {
exit(1); exit(1);
} }
kb::init(WIDTH, HEIGHT);
cv::VideoCapture cap(argv[1], cv::CAP_FFMPEG, { cv::VideoCapture cap(argv[1], cv::CAP_FFMPEG, {
cv::CAP_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX, cv::CAP_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX,
cv::CAP_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI, cv::CAP_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI,

@ -1,6 +1,7 @@
#define CL_TARGET_OPENCL_VERSION 120 #define CL_TARGET_OPENCL_VERSION 120
//WIDTH and HEIGHT have to be specified before including subsystems.hpp #include "../common/subsystems.hpp"
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 double FPS = 60; constexpr double FPS = 60;
@ -10,13 +11,11 @@ constexpr const int VA_HW_DEVICE_INDEX = 0;
constexpr int GLOW_KERNEL_SIZE = WIDTH / 120 % 2 == 0 ? WIDTH / 120 + 1 : WIDTH / 120; constexpr int GLOW_KERNEL_SIZE = WIDTH / 120 % 2 == 0 ? WIDTH / 120 + 1 : WIDTH / 120;
#include "../common/subsystems.hpp"
using std::cerr; using std::cerr;
using std::endl; using std::endl;
void init_scene() { void init_scene(unsigned long w, unsigned long h) {
glViewport(0, 0, WIDTH, HEIGHT); glViewport(0, 0, w, h);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
@ -33,8 +32,9 @@ void init_scene() {
glRotatef(70, 0, 1, 0); glRotatef(70, 0, 1, 0);
} }
void render_scene() { void render_scene(unsigned long w, unsigned long h) {
glViewport(0, 0, WIDTH , HEIGHT ); //Render a tetrahedron using immediate mode because the code is more concise for a demo
glViewport(0, 0, w, h);
glRotatef(1, 0, 1, 0); glRotatef(1, 0, 1, 0);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f); glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -79,6 +79,9 @@ void glow_effect(const cv::UMat &src, cv::UMat &dst, const int ksize) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
using namespace kb; using namespace kb;
kb::init(WIDTH, HEIGHT);
//Initialize VP9 HW encoding using VAAPI //Initialize VP9 HW encoding using VAAPI
cv::VideoWriter writer(OUTPUT_FILENAME, cv::CAP_FFMPEG, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT), { cv::VideoWriter writer(OUTPUT_FILENAME, cv::CAP_FFMPEG, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT), {
cv::VIDEOWRITER_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX, cv::VIDEOWRITER_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX,
@ -98,7 +101,7 @@ int main(int argc, char **argv) {
//Initialize OpenCL Context for OpenGL //Initialize OpenCL Context for OpenGL
gl::init(); gl::init();
init_scene(); init_scene(WIDTH, HEIGHT);
cerr << "EGL Version: " << egl::get_info() << endl; cerr << "EGL Version: " << egl::get_info() << endl;
cerr << "OpenGL Version: " << gl::get_info() << endl; cerr << "OpenGL Version: " << gl::get_info() << endl;
@ -112,7 +115,7 @@ int main(int argc, char **argv) {
gl::bind(); gl::bind();
//Render using OpenGL //Render using OpenGL
gl::begin(); gl::begin();
render_scene(); render_scene(WIDTH, HEIGHT);
gl::end(); gl::end();
//Aquire the frame buffer for use by OpenCL //Aquire the frame buffer for use by OpenCL

@ -1,6 +1,8 @@
#define CL_TARGET_OPENCL_VERSION 120 #define CL_TARGET_OPENCL_VERSION 120
//WIDTH and HEIGHT have to be specified before including subsystems.hpp #include "../common/subsystems.hpp"
#include <string>
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;
@ -9,15 +11,12 @@ constexpr const char *OUTPUT_FILENAME = "video-demo.mkv";
constexpr int GLOW_KERNEL_SIZE = WIDTH / 120 % 2 == 0 ? WIDTH / 120 + 1 : WIDTH / 120; constexpr int GLOW_KERNEL_SIZE = WIDTH / 120 % 2 == 0 ? WIDTH / 120 + 1 : WIDTH / 120;
#include "../common/subsystems.hpp"
#include <string>
using std::cerr; using std::cerr;
using std::endl; using std::endl;
using std::string; using std::string;
void init_scene() { void init_scene(unsigned long w, unsigned long h) {
glViewport(0, 0, WIDTH, HEIGHT); glViewport(0, 0, w, h);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
@ -34,9 +33,9 @@ void init_scene() {
glRotatef(70, 0, 1, 0); glRotatef(70, 0, 1, 0);
} }
void render_scene() { void render_scene(unsigned long w, unsigned long h) {
//Render a tetrahedron using immediate mode because the code is more concise for a demo //Render a tetrahedron using immediate mode because the code is more concise for a demo
glViewport(0, 0, WIDTH, HEIGHT); glViewport(0, 0, w, h);
glRotatef(1, 0, 1, 0); glRotatef(1, 0, 1, 0);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f); glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
@ -86,6 +85,8 @@ int main(int argc, char **argv) {
exit(1); exit(1);
} }
kb::init(WIDTH, HEIGHT);
//Initialize MJPEG HW decoding using VAAPI //Initialize MJPEG HW decoding using VAAPI
cv::VideoCapture capture(argv[1], cv::CAP_FFMPEG, { cv::VideoCapture capture(argv[1], cv::CAP_FFMPEG, {
cv::CAP_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX, cv::CAP_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX,
@ -122,7 +123,7 @@ int main(int argc, char **argv) {
cerr << "OpenGL Version: " << gl::get_info() << endl; cerr << "OpenGL Version: " << gl::get_info() << endl;
cerr << "OpenCL Platforms: " << endl << cl::get_info() << endl; cerr << "OpenCL Platforms: " << endl << cl::get_info() << endl;
init_scene(); init_scene(WIDTH, HEIGHT);
cv::UMat frameBuffer; cv::UMat frameBuffer;
cv::UMat videoFrame; cv::UMat videoFrame;
@ -139,7 +140,6 @@ int main(int argc, char **argv) {
break; break;
} }
//Color-conversion from RGB to BGRA. (OpenCL) //Color-conversion from RGB to BGRA. (OpenCL)
cv::cvtColor(videoFrame, videoFrameRGBA, cv::COLOR_RGB2BGRA); cv::cvtColor(videoFrame, videoFrameRGBA, cv::COLOR_RGB2BGRA);
@ -154,7 +154,7 @@ int main(int argc, char **argv) {
//Render using OpenGL //Render using OpenGL
gl::begin(); gl::begin();
render_scene(); render_scene(WIDTH, HEIGHT);
gl::end(); gl::end();
//Aquire the frame buffer for use by OpenCL //Aquire the frame buffer for use by OpenCL

Loading…
Cancel
Save