refactoring, renaming and commenting

pull/3471/head
kallaballa 2 years ago
parent 0d8b6e4afa
commit e55cb74a35
  1. 22
      modules/viz2d/include/opencv2/viz2d/util.hpp
  2. 8
      modules/viz2d/include/opencv2/viz2d/viz2d.hpp
  3. 10
      modules/viz2d/samples/cpp/beauty/beauty-demo.cpp
  4. 6
      modules/viz2d/samples/cpp/font/font-demo.cpp
  5. 8
      modules/viz2d/samples/cpp/nanovg/nanovg-demo.cpp
  6. 10
      modules/viz2d/samples/cpp/optflow/optflow-demo.cpp
  7. 8
      modules/viz2d/samples/cpp/pedestrian/pedestrian-demo.cpp
  8. 10
      modules/viz2d/samples/cpp/shader/shader-demo.cpp
  9. 6
      modules/viz2d/samples/cpp/tetra/tetra-demo.cpp
  10. 8
      modules/viz2d/samples/cpp/video/video-demo.cpp
  11. 2
      modules/viz2d/src/detail/framebuffercontext.cpp
  12. 38
      modules/viz2d/src/util.cpp
  13. 6
      modules/viz2d/src/viz2d.cpp

@ -27,26 +27,26 @@ class Viz2D;
* Returns the OpenGL Version information.
* @return a string object with the OpenGL version information
*/
CV_EXPORTS std::string get_gl_info();
CV_EXPORTS std::string getGlInfo();
/*!
* Returns the OpenCL Version information.
* @return a string object with the OpenCL version information
*/
CV_EXPORTS std::string get_cl_info();
CV_EXPORTS std::string getClInfo();
/*!
* Determines if Intel VAAPI is supported
* @return true if it is supported
*/
CV_EXPORTS bool is_intel_va_supported();
CV_EXPORTS bool isIntelVaSupported();
/*!
* Determines if cl_khr_gl_sharing is supported
* @return true if it is supported
*/
CV_EXPORTS bool is_cl_gl_sharing_supported();
CV_EXPORTS bool isClGlSharingSupported();
/*!
* Pretty prints system information.
*/
CV_EXPORTS void print_system_info();
CV_EXPORTS void printSystemInfo();
/*!
* Tells the application if it's alright to keep on running.
* Note: If you use this mechanism signal handlers are installed
@ -60,7 +60,7 @@ CV_EXPORTS bool keepRunning();
* @param v2d The Viz2D object to operate on
* @param graphical if this parameter is true the FPS drawn on display
*/
CV_EXPORTS void update_fps(cv::Ptr<Viz2D> viz2d, bool graphical);
CV_EXPORTS void updateFps(cv::Ptr<Viz2D> viz2d, bool graphical);
#ifndef __EMSCRIPTEN__
/*!
@ -73,7 +73,7 @@ CV_EXPORTS void update_fps(cv::Ptr<Viz2D> viz2d, bool graphical);
* @param vaDeviceIndex The VAAPI device index to use.
* @return A VAAPI enabled sink object.
*/
CV_EXPORTS Sink make_va_sink(const string& outputFilename, const int fourcc, const float fps,
CV_EXPORTS Sink makeVaSink(const string& outputFilename, const int fourcc, const float fps,
const cv::Size& frameSize, const int vaDeviceIndex);
/*!
* Creates an Intel VAAPI enabled VideoCapture source object to use in conjunction with #Viz2D::setSource().
@ -82,7 +82,7 @@ CV_EXPORTS Sink make_va_sink(const string& outputFilename, const int fourcc, con
* @param vaDeviceIndex The VAAPI device index to use.
* @return A VAAPI enabled source object.
*/
CV_EXPORTS Source make_va_source(const string& inputFilename, const int vaDeviceIndex);
CV_EXPORTS Source makeVaSource(const string& inputFilename, const int vaDeviceIndex);
/*!
* Creates a VideoWriter sink object to use in conjunction with #Viz2D::setSink().
* This function automatically determines if Intel VAAPI is available and enables it if so.
@ -92,7 +92,7 @@ CV_EXPORTS Source make_va_source(const string& inputFilename, const int vaDevice
* @param frameSize The frame size of the target video.
* @return A (optionally VAAPI enabled) VideoWriter sink object.
*/
CV_EXPORTS Sink make_writer_sink(const string& outputFilename, const int fourcc, const float fps,
CV_EXPORTS Sink makeWriterSink(const string& outputFilename, const int fourcc, const float fps,
const cv::Size& frameSize);
/*!
* Creates a VideoCapture source object to use in conjunction with #Viz2D::setSource().
@ -100,7 +100,7 @@ CV_EXPORTS Sink make_writer_sink(const string& outputFilename, const int fourcc,
* @param inputFilename The file to read from.
* @return A (optionally VAAPI enabled) VideoCapture enabled source object.
*/
CV_EXPORTS Source make_capture_source(const string& inputFilename);
CV_EXPORTS Source makeCaptureSource(const string& inputFilename);
#else
/*!
* Creates a WebCam source object to use in conjunction with #Viz2D::setSource().
@ -109,7 +109,7 @@ CV_EXPORTS Source make_capture_source(const string& inputFilename);
* @param height The frame height to capture (usually the initial height of the Viz2D object)
* @return A WebCam source object.
*/
CV_EXPORTS Source make_capture_source(int width, int height);
CV_EXPORTS Source makeCaptureSource(int width, int height);
#endif
}

@ -138,6 +138,14 @@ CV_EXPORTS class Viz2D {
Sink sink_;
std::function<bool(int key, int scancode, int action, int modifiers)> keyEventCb_;
public:
/*!
* Creates a Viz2D object which is the central object to perform visualizations with.
* @param size The window and framebuffer size
* @param title The window title.
* @param debug Create a debug OpenGL context.
*/
CV_EXPORTS static cv::Ptr<Viz2D> make(const cv::Size& size, const string& title, bool debug = false);
/*!
* Creates a Viz2D object which is the central object to perform visualizations with.
* @param initialSize The initial size of the heavy-weight window.

@ -350,7 +350,7 @@ void iteration() {
cvtColor(frameOut, frameBuffer, cv::COLOR_BGR2BGRA);
});
}
update_fps(v2d, true);
updateFps(v2d, true);
#ifndef __EMSCRIPTEN__
v2d->write();
@ -375,7 +375,7 @@ int main(int argc, char **argv) {
#endif
facemark->loadModel("assets/lbfmodel.yaml");
print_system_info();
printSystemInfo();
v2d->setStretching(stretch);
@ -385,16 +385,16 @@ int main(int argc, char **argv) {
}
#ifndef __EMSCRIPTEN__
Source src = make_capture_source(argv[1]);
Source src = makeCaptureSource(argv[1]);
v2d->setSource(src);
Sink sink = make_writer_sink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
v2d->setSink(sink);
while (keepRunning())
iteration();
#else
Source src = make_capture_source(WIDTH, HEIGHT);
Source src = makeCaptureSource(WIDTH, HEIGHT);
v2d->setSource(src);
emscripten_set_main_loop(iteration, -1, true);
#endif

@ -187,7 +187,7 @@ void iteration() {
cnt = 0;
}
update_fps(v2d, show_fps);
updateFps(v2d, show_fps);
#ifndef __EMSCRIPTEN__
v2d->write();
@ -207,7 +207,7 @@ int main(int argc, char **argv) {
try {
using namespace cv::viz;
print_system_info();
printSystemInfo();
if(!v2d->isOffscreen()) {
setup_gui(v2d);
v2d->setVisible(true);
@ -223,7 +223,7 @@ int main(int argc, char **argv) {
}
#ifndef __EMSCRIPTEN__
Sink sink = make_writer_sink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT));
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT));
v2d->setSink(sink);
while(keepRunning())
iteration();

@ -125,14 +125,14 @@ int main(int argc, char **argv) {
}
cv::Ptr<Viz2D> v2d = Viz2D::make(cv::Size(WIDTH, HEIGHT), cv::Size(WIDTH, HEIGHT), OFFSCREEN, "NanoVG Demo");
print_system_info();
printSystemInfo();
if (!v2d->isOffscreen())
v2d->setVisible(true);
Source src = make_capture_source(argv[1]);
Source src = makeCaptureSource(argv[1]);
v2d->setSource(src);
Sink sink = make_writer_sink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
v2d->setSink(sink);
std::vector<cv::UMat> hsvChannels;
@ -178,7 +178,7 @@ int main(int argc, char **argv) {
draw_color_wheel(sz.width - 300, sz.height - 300, 250.0f, 250.0f, hue);
});
update_fps(v2d, true);
updateFps(v2d, true);
v2d->write();

@ -445,7 +445,7 @@ void iteration() {
#endif
});
update_fps(v2d, show_fps);
updateFps(v2d, show_fps);
#ifndef __EMSCRIPTEN__
v2d->write();
@ -471,7 +471,7 @@ int main(int argc, char **argv) {
exit(1);
}
#endif
print_system_info();
printSystemInfo();
if(!v2d->isOffscreen()) {
#ifndef __EMSCRIPTEN__
@ -485,16 +485,16 @@ int main(int argc, char **argv) {
}
#ifndef __EMSCRIPTEN__
Source src = make_capture_source(argv[1]);
Source src = makeCaptureSource(argv[1]);
v2d->setSource(src);
Sink sink = make_writer_sink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
v2d->setSink(sink);
while (keepRunning())
iteration();
#else
Source src = make_capture_source(WIDTH, HEIGHT);
Source src = makeCaptureSource(WIDTH, HEIGHT);
v2d->setSource(src);
emscripten_set_main_loop(iteration, -1, true);
#endif

@ -116,14 +116,14 @@ int main(int argc, char **argv) {
}
cv::Ptr<Viz2D> v2d = Viz2D::make(cv::Size(WIDTH, HEIGHT), cv::Size(WIDTH, HEIGHT), OFFSCREEN, "Beauty Demo");
print_system_info();
printSystemInfo();
if (!v2d->isOffscreen())
v2d->setVisible(true);
Source src = make_capture_source(argv[1]);
Source src = makeCaptureSource(argv[1]);
v2d->setSource(src);
Sink sink = make_writer_sink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
v2d->setSink(sink);
//BGRA
@ -214,7 +214,7 @@ int main(int argc, char **argv) {
composite_layers(background, frameBuffer, frameBuffer, BLUR_KERNEL_SIZE);
});
update_fps(v2d, true);
updateFps(v2d, true);
v2d->write();

@ -404,7 +404,7 @@ void iteration() {
});
#endif
update_fps(v2d, true);
updateFps(v2d, true);
#ifndef __EMSCRIPTEN__
v2d->write();
@ -424,7 +424,7 @@ int main(int argc, char **argv) {
exit(1);
}
print_system_info();
printSystemInfo();
if(!v2d->isOffscreen()) {
setup_gui(v2d);
v2d->setVisible(true);
@ -432,15 +432,15 @@ int main(int argc, char **argv) {
v2d->gl(init_scene);
#ifndef __EMSCRIPTEN__
Source src = make_capture_source(argv[1]);
Source src = makeCaptureSource(argv[1]);
v2d->setSource(src);
Sink sink = make_writer_sink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT));
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT));
v2d->setSink(sink);
while(keepRunning())
iteration();
#else
Source src = make_capture_source(WIDTH, HEIGHT);
Source src = makeCaptureSource(WIDTH, HEIGHT);
v2d->setSource(src);
emscripten_set_main_loop(iteration, -1, true);
#endif

@ -90,11 +90,11 @@ int main(int argc, char **argv) {
using namespace cv::viz;
cv::Ptr<Viz2D> v2d = Viz2D::make(cv::Size(WIDTH, HEIGHT), cv::Size(WIDTH, HEIGHT), OFFSCREEN, "Tetra Demo");
print_system_info();
printSystemInfo();
if(!v2d->isOffscreen())
v2d->setVisible(true);
Sink sink = make_writer_sink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT));
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), FPS, cv::Size(WIDTH, HEIGHT));
v2d->setSink(sink);
v2d->gl(init_scene);
@ -111,7 +111,7 @@ int main(int argc, char **argv) {
v2d->write();
update_fps(v2d, true);
updateFps(v2d, true);
//If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed.
if (!v2d->display())

@ -94,14 +94,14 @@ int main(int argc, char **argv) {
exit(1);
}
cv::Ptr<Viz2D> v2d = Viz2D::make(cv::Size(WIDTH, HEIGHT), cv::Size(WIDTH, HEIGHT), OFFSCREEN, "Video Demo");
print_system_info();
printSystemInfo();
if(!v2d->isOffscreen())
v2d->setVisible(true);
Source src = make_capture_source(argv[1]);
Source src = makeCaptureSource(argv[1]);
v2d->setSource(src);
Sink sink = make_writer_sink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
Sink sink = makeWriterSink(OUTPUT_FILENAME, cv::VideoWriter::fourcc('V', 'P', '9', '0'), src.fps(), cv::Size(WIDTH, HEIGHT));
v2d->setSink(sink);
v2d->gl(init_scene);
@ -117,7 +117,7 @@ int main(int argc, char **argv) {
glow_effect(frameBuffer, frameBuffer, GLOW_KERNEL_SIZE);
});
update_fps(v2d, true);
updateFps(v2d, true);
v2d->write();

@ -23,7 +23,7 @@ FrameBufferContext::FrameBufferContext(const cv::Size& frameBufferSize) :
glewExperimental = true;
glewInit();
try {
if (is_cl_gl_sharing_supported())
if (isClGlSharingSupported())
cv::ogl::ocl::initializeContextFromGL();
else
clglSharing_ = false;

@ -20,11 +20,11 @@
namespace cv {
namespace viz {
std::string get_gl_info() {
std::string getGlInfo() {
return reinterpret_cast<const char*>(glGetString(GL_VERSION));
}
std::string get_cl_info() {
std::string getClInfo() {
std::stringstream ss;
#ifndef __EMSCRIPTEN__
std::vector<cv::ocl::PlatformInfo> plt_info;
@ -53,7 +53,7 @@ std::string get_cl_info() {
return ss.str();
}
bool is_intel_va_supported() {
bool isIntelVaSupported() {
#ifndef __EMSCRIPTEN__
try {
std::vector<cv::ocl::PlatformInfo> plt_info;
@ -74,7 +74,7 @@ bool is_intel_va_supported() {
return false;
}
bool is_cl_gl_sharing_supported() {
bool isClGlSharingSupported() {
#ifndef __EMSCRIPTEN__
try {
std::vector<cv::ocl::PlatformInfo> plt_info;
@ -95,9 +95,9 @@ bool is_cl_gl_sharing_supported() {
return false;
}
void print_system_info() {
cerr << "OpenGL Version: " << get_gl_info() << endl;
cerr << "OpenCL Platforms: " << get_cl_info() << endl;
void printSystemInfo() {
cerr << "OpenGL Version: " << getGlInfo() << endl;
cerr << "OpenCL Platforms: " << getClInfo() << endl;
}
/*!
@ -137,7 +137,7 @@ bool keepRunning() {
* @param v2d The Viz2D object to operate on
* @param graphical if this parameter is true the FPS drawn on display
*/
void update_fps(cv::Ptr<cv::viz::Viz2D> v2d, bool graphical) {
void updateFps(cv::Ptr<cv::viz::Viz2D> v2d, bool graphical) {
static uint64_t cnt = 0;
static cv::TickMeter tick;
static float fps;
@ -179,7 +179,7 @@ void update_fps(cv::Ptr<cv::viz::Viz2D> v2d, bool graphical) {
}
#ifndef __EMSCRIPTEN__
Sink make_va_sink(const string& outputFilename, const int fourcc, const float fps,
Sink makeVaSink(const string& outputFilename, const int fourcc, const float fps,
const cv::Size& frameSize, const int vaDeviceIndex) {
cv::Ptr<cv::VideoWriter> writer = new cv::VideoWriter(outputFilename, cv::CAP_FFMPEG,
cv::VideoWriter::fourcc('V', 'P', '9', '0'), fps, frameSize, {
@ -194,7 +194,7 @@ Sink make_va_sink(const string& outputFilename, const int fourcc, const float fp
});
}
Source make_va_source(const string& inputFilename, const int vaDeviceIndex) {
Source makeVaSource(const string& inputFilename, const int vaDeviceIndex) {
cv::Ptr<cv::VideoCapture> capture = new cv::VideoCapture(inputFilename, cv::CAP_FFMPEG, {
cv::CAP_PROP_HW_DEVICE, vaDeviceIndex, cv::CAP_PROP_HW_ACCELERATION,
cv::VIDEO_ACCELERATION_VAAPI, cv::CAP_PROP_HW_ACCELERATION_USE_OPENCL, 1 });
@ -207,13 +207,13 @@ Source make_va_source(const string& inputFilename, const int vaDeviceIndex) {
}, fps);
}
#else
Sink make_va_sink(const string &outputFilename, const int fourcc, const float fps, const cv::Size &frameSize, const int vaDeviceIndex) {
Sink makeVaSink(const string &outputFilename, const int fourcc, const float fps, const cv::Size &frameSize, const int vaDeviceIndex) {
return Sink([=](const cv::InputArray& frame){
return false;
});
}
Source make_va_source(const string &inputFilename, const int vaDeviceIndex) {
Source makeVaSource(const string &inputFilename, const int vaDeviceIndex) {
return Source([=](cv::OutputArray& frame){
return false;
}, 0);
@ -221,10 +221,10 @@ Source make_va_source(const string &inputFilename, const int vaDeviceIndex) {
#endif
#ifndef __EMSCRIPTEN__
Sink make_writer_sink(const string& outputFilename, const int fourcc, const float fps,
Sink makeWriterSink(const string& outputFilename, const int fourcc, const float fps,
const cv::Size& frameSize) {
if (is_intel_va_supported()) {
return make_va_sink(outputFilename, fourcc, fps, frameSize, 0);
if (isIntelVaSupported()) {
return makeVaSink(outputFilename, fourcc, fps, frameSize, 0);
}
cv::Ptr<cv::VideoWriter> writer = new cv::VideoWriter(outputFilename, cv::CAP_FFMPEG,
@ -237,9 +237,9 @@ Sink make_writer_sink(const string& outputFilename, const int fourcc, const floa
});
}
Source make_capture_source(const string& inputFilename) {
if (is_intel_va_supported()) {
return make_va_source(inputFilename, 0);
Source makeCaptureSource(const string& inputFilename) {
if (isIntelVaSupported()) {
return makeVaSource(inputFilename, 0);
}
cv::Ptr<cv::VideoCapture> capture = new cv::VideoCapture(inputFilename, cv::CAP_FFMPEG);
@ -253,7 +253,7 @@ Source make_capture_source(const string& inputFilename) {
}
#else
Source make_capture_source(int width, int height) {
Source makeCaptureSource(int width, int height) {
using namespace std;
static cv::Mat tmp(height, width, CV_8UC4);

@ -47,6 +47,12 @@ cv::Scalar colorConvert(const cv::Scalar& src, cv::ColorConversionCodes code) {
return dst;
}
cv::Ptr<Viz2D> Viz2D::make(const cv::Size& size, const string& title, bool debug) {
cv::Ptr<Viz2D> v2d = new Viz2D(size, size, false, title, 4, 6, 0, debug);
v2d->setVisible(true);
return v2d;
}
cv::Ptr<Viz2D> Viz2D::make(const cv::Size& initialSize, const cv::Size& frameBufferSize, bool offscreen,
const string& title, int major, int minor, int samples, bool debug) {
return new Viz2D(initialSize, frameBufferSize, offscreen, title, major, minor, samples, debug);

Loading…
Cancel
Save