refactoring

pull/3471/head
kallaballa 3 years ago
parent 9f5f2a1e30
commit 340dda66fd
  1. 7
      src/optflow/optflow-demo.cpp
  2. 8
      src/tetra/tetra-demo.cpp
  3. 8
      src/video/video-demo.cpp

@ -3,10 +3,11 @@
constexpr unsigned long WIDTH = 1920; constexpr unsigned long WIDTH = 1920;
constexpr unsigned long HEIGHT = 1080; constexpr unsigned long HEIGHT = 1080;
constexpr float SCALE_FACTOR = 0.5f; constexpr float SCALE_FACTOR = 0.5f;
constexpr bool OFFSCREEN = false; constexpr bool OFFSCREEN = true;
constexpr int VA_HW_DEVICE_INDEX = 0; constexpr int VA_HW_DEVICE_INDEX = 0;
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;
constexpr float MAX_POINTS = 500000.0;
#include "../common/subsystems.hpp" #include "../common/subsystems.hpp"
#include <vector> #include <vector>
@ -69,7 +70,7 @@ void visualize_sparse_optical_flow(const cv::UMat& prevGrey, const cv::UMat &nex
float area = cv::contourArea(hull); float area = cv::contourArea(hull);
float density = (detectedPoints.size() / area); float density = (detectedPoints.size() / area);
float stroke = 30.0 * sqrt(area / (nextGrey.cols * nextGrey.rows * 4)); float stroke = 30.0 * sqrt(area / (nextGrey.cols * nextGrey.rows * 4));
size_t currentMaxPoints = density * 500000.0; size_t currentMaxPoints = density * MAX_POINTS;
size_t copyn = std::min(detectedPoints.size(), (size_t(std::ceil(currentMaxPoints)) - prevPoints.size())); size_t copyn = std::min(detectedPoints.size(), (size_t(std::ceil(currentMaxPoints)) - prevPoints.size()));
if (prevPoints.size() < currentMaxPoints) { if (prevPoints.size() < currentMaxPoints) {
@ -159,7 +160,7 @@ int main(int argc, char **argv) {
break; break;
cv::resize(videoFrame, resized, frameBufferSize); cv::resize(videoFrame, resized, frameBufferSize);
cv::resize(resized, down, cv::Size(0, 0), SCALE_FACTOR, SCALE_FACTOR); cv::resize(videoFrame, down, cv::Size(WIDTH * SCALE_FACTOR, HEIGHT * SCALE_FACTOR));
cv::cvtColor(resized, background, cv::COLOR_RGB2BGRA); cv::cvtColor(resized, background, cv::COLOR_RGB2BGRA);
cv::cvtColor(down, downNextGrey, cv::COLOR_RGB2GRAY); cv::cvtColor(down, downNextGrey, cv::COLOR_RGB2GRAY);

@ -12,7 +12,7 @@ constexpr const int VA_HW_DEVICE_INDEX = 0;
using std::cerr; using std::cerr;
using std::endl; using std::endl;
void init_tetrahedron() { void init_scene() {
glViewport(0, 0, WIDTH, HEIGHT); glViewport(0, 0, WIDTH, HEIGHT);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
@ -30,7 +30,7 @@ void init_tetrahedron() {
glRotatef(70, 0, 1, 0); glRotatef(70, 0, 1, 0);
} }
void render_tetrahedron() { void render() {
glViewport(0, 0, WIDTH , HEIGHT ); glViewport(0, 0, WIDTH , HEIGHT );
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);
@ -103,14 +103,14 @@ int main(int argc, char **argv) {
cv::UMat frameBuffer; cv::UMat frameBuffer;
cv::UMat videoFrame; cv::UMat videoFrame;
init_tetrahedron(); init_scene();
while (true) { while (true) {
//Activate the OpenCL context for OpenGL //Activate the OpenCL context for OpenGL
gl::bind(); gl::bind();
//Render using OpenGL //Render using OpenGL
gl::begin(); gl::begin();
render_tetrahedron(); render();
gl::end(); gl::end();
//Aquire the frame buffer for use by OpenCL //Aquire the frame buffer for use by OpenCL

@ -15,7 +15,7 @@ using std::cerr;
using std::endl; using std::endl;
using std::string; using std::string;
void init_tetrahedron() { void init_scene() {
glViewport(0, 0, WIDTH, HEIGHT); glViewport(0, 0, WIDTH, HEIGHT);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
@ -33,7 +33,7 @@ void init_tetrahedron() {
glRotatef(70, 0, 1, 0); glRotatef(70, 0, 1, 0);
} }
void render_tetrahedron() { void render() {
//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, WIDTH, HEIGHT);
glRotatef(1, 0, 1, 0); glRotatef(1, 0, 1, 0);
@ -125,7 +125,7 @@ int main(int argc, char **argv) {
cv::UMat videoFrame; cv::UMat videoFrame;
cv::UMat videoFrameRGBA; cv::UMat videoFrameRGBA;
init_tetrahedron(); init_scene();
//Activate the OpenCL context for VAAPI //Activate the OpenCL context for VAAPI
va::bind(); va::bind();
@ -154,7 +154,7 @@ int main(int argc, char **argv) {
//Render using OpenGL //Render using OpenGL
gl::begin(); gl::begin();
render_tetrahedron(); render();
gl::end(); gl::end();
//Aquire the frame buffer for use by OpenCL //Aquire the frame buffer for use by OpenCL

Loading…
Cancel
Save