more imgui porting

pull/3471/head
kallaballa 2 years ago
parent f26b620724
commit 260be3181d
  1. 6
      modules/v4d/include/opencv2/v4d/v4d.hpp
  2. 2
      modules/v4d/samples/beauty-demo.cpp
  3. 2
      modules/v4d/samples/cube-demo.cpp
  4. 2
      modules/v4d/samples/custom_source_and_sink.cpp
  5. 2
      modules/v4d/samples/display_image.cpp
  6. 2
      modules/v4d/samples/display_image_fb.cpp
  7. 2
      modules/v4d/samples/font-demo.cpp
  8. 2
      modules/v4d/samples/font_rendering.cpp
  9. 31
      modules/v4d/samples/font_with_gui.cpp
  10. 2
      modules/v4d/samples/many_cubes-demo.cpp
  11. 2
      modules/v4d/samples/nanovg-demo.cpp
  12. 3
      modules/v4d/samples/optflow-demo.cpp
  13. 2
      modules/v4d/samples/pedestrian-demo.cpp
  14. 2
      modules/v4d/samples/render_opengl.cpp
  15. 2
      modules/v4d/samples/shader-demo.cpp
  16. 2
      modules/v4d/samples/vector_graphics.cpp
  17. 2
      modules/v4d/samples/vector_graphics_and_fb.cpp
  18. 2
      modules/v4d/samples/video-demo.cpp
  19. 2
      modules/v4d/samples/video_editing.cpp
  20. 5
      modules/v4d/src/detail/nanovgcontext.cpp
  21. 7
      modules/v4d/src/v4d.cpp

@ -6,11 +6,6 @@
#ifndef SRC_OPENCV_V4D_V4D_HPP_
#define SRC_OPENCV_V4D_V4D_HPP_
# define V4D_INIT_MAIN(w, h, title, offscreen, debug, samples) ({ \
cv::Ptr<cv::v4d::V4D> v4d = cv::v4d::V4D::make(cv::Size(w, h), cv::Size(), title, offscreen, debug, samples); \
v4d; \
})
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/threading.h>
@ -121,6 +116,7 @@ public:
* @param samples MSAA samples.
* @param debug Create a debug OpenGL context.
*/
CV_EXPORTS static cv::Ptr<V4D> make(int w, int h, const string& title, bool offscreen = false, bool debug = false, int samples = 0);
CV_EXPORTS static cv::Ptr<V4D> make(const cv::Size& size, const cv::Size& fbsize, const string& title, bool offscreen = false, bool debug = false, int samples = 0);
/*!
* Default destructor

@ -333,7 +333,7 @@ int main(int argc, char **argv) {
int main() {
#endif
using namespace cv::v4d;
cv::Ptr<V4D> window = V4D_INIT_MAIN(WIDTH, HEIGHT, "Beautification Demo", false, false, 0);
cv::Ptr<V4D> window = V4D::make(WIDTH, HEIGHT, "Beautification Demo", false, false, 0);
window->printSystemInfo();
facemark->loadModel("assets/lbfmodel.yaml");

@ -242,7 +242,7 @@ static bool iteration(cv::Ptr<V4D> window) {
}
int main() {
cv::Ptr<V4D> window = V4D_INIT_MAIN(WIDTH, HEIGHT, "Cube Demo", false, false, 0);
cv::Ptr<V4D> window = V4D::make(WIDTH, HEIGHT, "Cube Demo", false, false, 0);
window->printSystemInfo();
cerr << "\n\t" << reinterpret_cast<const char*>(glGetString(GL_VERSION))
<< "\n\t" << reinterpret_cast<const char*>(glGetString(GL_RENDERER)) << endl;

@ -7,7 +7,7 @@ using namespace cv;
using namespace cv::v4d;
int main() {
Ptr<V4D> window = V4D_INIT_MAIN(960, 960, "Custom Source/Sink", false, false, 0);
Ptr<V4D> window = V4D::make(960, 960, "Custom Source/Sink", false, false, 0);
string hr = "Hello Rainbow!";
//Make a source that generates rainbow frames.

@ -8,7 +8,7 @@ int main() {
//Creates a V4D window for on screen rendering with a window size of 720p and a framebuffer of the same size.
//Please note that while the window size may change the framebuffer size may not. If you need multiple framebuffer
//sizes you need multiple V4D objects
cv::Ptr<V4D> window = V4D_INIT_MAIN(960, 960, "Display Image", false, false, 0);
cv::Ptr<V4D> window = V4D::make(960, 960, "Display Image", false, false, 0);
//Loads an image as a UMat (just in case we have hardware acceleration available)
#ifdef __EMSCRIPTEN__

@ -6,7 +6,7 @@ using namespace cv::v4d;
int main() {
//Creates a V4D object
Ptr<V4D> window = V4D_INIT_MAIN(960, 960, "Display Image and FB", false, false, 0);
Ptr<V4D> window = V4D::make(960, 960, "Display Image and FB", false, false, 0);
//Loads an image as a UMat (just in case we have hardware acceleration available)
#ifdef __EMSCRIPTEN__

@ -204,7 +204,7 @@ static bool iteration(cv::Ptr<V4D> window) {
int main() {
try {
cv::Ptr<V4D> window = V4D_INIT_MAIN(WIDTH, HEIGHT, "Font Demo", false, false, 0);
cv::Ptr<V4D> window = V4D::make(WIDTH, HEIGHT, "Font Demo", false, false, 0);
// if(!OFFSCREEN) {
// setup_gui(window);
// }

@ -4,7 +4,7 @@ using namespace cv;
using namespace cv::v4d;
int main() {
cv::Ptr<V4D> window = V4D_INIT_MAIN(960, 960, "Font Rendering", false, false, 0);
cv::Ptr<V4D> window = V4D::make(960, 960, "Font Rendering", false, false, 0);
//The text to render
string hw = "Hello World";

@ -4,28 +4,23 @@ using namespace cv;
using namespace cv::v4d;
int main() {
Ptr<V4D> window = V4D_INIT_MAIN(960, 960, "Font Rendering with GUI", false, false, 0);
Ptr<V4D> window = V4D::make(960, 960, "Font Rendering with GUI", false, false, 0);
//The text color. NanoGUI uses rgba with floating point
// nanogui::Color textColor = {0.0f, 0.0f, 1.0f, 1.0f};
//The font size
float size = 40.0f;
//The text hue
float color[3] = {1.0f, 0.0f, 0.0f};
//The text
string hw = "hello world";
//Setup the GUI. First thing you should do is create a light-weight dialog and add widgets as needed.
//Variables passed to the FormHelper (e.g. via makeFormVariable) will be directly modified by the GUI.
//Please note that you can build more complex GUIs if you use NanoGUI directly on the created dialog
//instead of creating widgets through FormHelper::make* calls.
// window->nanogui([&](FormHelper& form) {
// //Create a light-weight dialog
// form.makeDialog(5, 30, "Settings");
// //Create a group
// form.makeGroup("Font");
// //Create a from variable. The type of widget is deduced from the variable type.
// form.makeFormVariable("Font Size", size, 1.0f, 100.0f, true, "pt", "Font size of the text crawl");
// //Create a color picker
// form.makeColorPicker("Text Color", textColor, "The text color");
// });
//Setup the GUI
window->imgui([&](ImGuiContext* ctx) {
using namespace ImGui;
SetCurrentContext(ctx);
Begin("Settings");
SliderFloat("Font Size", &size, 1.0f, 100.0f);
ColorPicker3("Text Color", color);
End();
});
window->run([&](Ptr<V4D> win) {
//Render the text at the center of the screen using parameters from the GUI.
@ -34,7 +29,7 @@ int main() {
clear();
fontSize(size);
fontFace("sans-bold");
fillColor(Scalar(255, 0, 0, 255));
fillColor(Scalar(color[2] * 255, color[1] * 255, color[0] * 255, 255));
textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
text(sz.width / 2.0, sz.height / 2.0, hw.c_str(), hw.c_str() + hw.size());
});

@ -254,7 +254,7 @@ static bool iteration(cv::Ptr<V4D> window) {
}
int main() {
cv::Ptr<V4D> window = V4D_INIT_MAIN(WIDTH, HEIGHT, "Many Cubes Demo", false, false, 0);
cv::Ptr<V4D> window = V4D::make(WIDTH, HEIGHT, "Many Cubes Demo", false, false, 0);
window->printSystemInfo();
#ifndef __EMSCRIPTEN__

@ -184,7 +184,7 @@ int main(int argc, char **argv) {
#else
int main() {
#endif
cv::Ptr<V4D> window = V4D_INIT_MAIN(WIDTH, HEIGHT, "Mandelbrot Shader Demo", false, false, 0);
cv::Ptr<V4D> window = V4D::make(WIDTH, HEIGHT, "Mandelbrot Shader Demo", false, false, 0);
window->printSystemInfo();
#ifndef __EMSCRIPTEN__

@ -488,8 +488,7 @@ int main() {
#endif
try {
using namespace cv::v4d;
cv::Ptr<V4D> window = V4D_INIT_MAIN(WIDTH, HEIGHT, "Sparse Optical Flow Demo", false, false, 0);
cv::Ptr<V4D> window = V4D::make(WIDTH, HEIGHT, "Sparse Optical Flow Demo", false, false, 0);
window->printSystemInfo();
if (!OFFSCREEN) {

@ -235,7 +235,7 @@ int main(int argc, char **argv) {
int main() {
#endif
using namespace cv::v4d;
cv::Ptr<V4D> window = V4D_INIT_MAIN(WIDTH, HEIGHT, "Pedestrian Demo", false, false, 0);
cv::Ptr<V4D> window = V4D::make(WIDTH, HEIGHT, "Pedestrian Demo", false, false, 0);
hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());
window->printSystemInfo();

@ -5,7 +5,7 @@ using namespace cv;
using namespace cv::v4d;
int main() {
Ptr<V4D> window = V4D_INIT_MAIN(960, 960, "GL Blue Screen", false, false, 0);
Ptr<V4D> window = V4D::make(960, 960, "GL Blue Screen", false, false, 0);
window->gl([]() {
//Sets the clear color to blue

@ -339,7 +339,7 @@ int main(int argc, char** argv) {
int main() {
#endif
try {
cv::Ptr<V4D> window = V4D_INIT_MAIN(WIDTH, HEIGHT, "Mandelbrot Shader Demo", false, false, 0);
cv::Ptr<V4D> window = V4D::make(WIDTH, HEIGHT, "Mandelbrot Shader Demo", false, false, 0);
// if (!OFFSCREEN) {
// setup_gui(window);

@ -4,7 +4,7 @@ using namespace cv;
using namespace cv::v4d;
int main() {
Ptr<V4D> window = V4D_INIT_MAIN(960, 960, "Vector Graphics", false, false, 0);
Ptr<V4D> window = V4D::make(960, 960, "Vector Graphics", false, false, 0);
window->run([](Ptr<V4D> win) {
//Creates a NanoVG context and draws googly eyes that occasionally blink.

@ -5,7 +5,7 @@ using namespace cv;
using namespace cv::v4d;
int main() {
Ptr<V4D> window = V4D_INIT_MAIN(960, 960, "Vector Graphics and Framebuffer", false, false, 0);
Ptr<V4D> window = V4D::make(960, 960, "Vector Graphics and Framebuffer", false, false, 0);
window->run([](Ptr<V4D> win) {
//Again creates a NanoVG context and draws googly eyes

@ -218,7 +218,7 @@ int main(int argc, char** argv) {
int main() {
#endif
using namespace cv::v4d;
cv::Ptr<V4D> window = V4D_INIT_MAIN(WIDTH, HEIGHT, "Video Demo", false, false, 0);
cv::Ptr<V4D> window = V4D::make(WIDTH, HEIGHT, "Video Demo", false, false, 0);
window->printSystemInfo();
#ifndef __EMSCRIPTEN__

@ -4,7 +4,7 @@ using namespace cv;
using namespace cv::v4d;
int main(int argc, char** argv) {
Ptr<V4D> window = V4D_INIT_MAIN(960, 960, "Video Editing", false, false, 0);
Ptr<V4D> window = V4D::make(960, 960, "Video Editing", false, false, 0);
//In case of WebAssembly
CV_UNUSED(argc);

@ -30,10 +30,11 @@ NanoVGContext::NanoVGContext(FrameBufferContext& fbContext) :
if (!context_)
throw std::runtime_error("Could not initialize NanoVG!");
}
int font = nvgCreateFont(context_, "icons", "assets/entypo.ttf");
font = nvgCreateFont(context_, "sans", "assets/Roboto-Regular.ttf");
font = nvgCreateFont(context_, "sans-bold", "assets/Roboto-Bold.ttf");
#ifdef __EMSCRIPTEN__
run_sync_on_main<12>([&,this](){
mainFbContext_.initWebGLCopy(fbCtx().getIndex());
});
#endif
});
}

@ -14,10 +14,15 @@
namespace cv {
namespace v4d {
cv::Ptr<V4D> V4D::make(int w, int h, const string& title, bool offscreen, bool debug, int samples) {
V4D* v4d = new V4D(cv::Size(w,h), cv::Size(), title, offscreen, debug, samples);
v4d->setVisible(!offscreen);
return v4d->self();
}
cv::Ptr<V4D> V4D::make(const cv::Size& size, const cv::Size& fbsize, const string& title, bool offscreen, bool debug, int samples) {
V4D* v4d = new V4D(size, fbsize, title, offscreen, debug, samples);
v4d->setVisible(!offscreen);
v4d->printSystemInfo();
return v4d->self();
}

Loading…
Cancel
Save