Loading...
Searching...
No Matches
Form based GUI

Prev Tutorial: Custom Source and Sink
Next Tutorial: V4D

Original author Amir Hassan (kallaballa) amir@.nosp@m.viel.nosp@m.-zu.o.nosp@m.rg
Compatibility OpenCV >= 4.7

Font rendering with form based GUI

Draws "Hello World" to the screen and let's you control the font size and color with a GUI.

Font rendering with Form-based GUI
Downloading...
using namespace cv;
using namespace cv::v4d;
int main() {
Ptr<V4D> window = V4D::make(960, 960, "Font Rendering with GUI", false, false, 0);
//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
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.
win->nvg([&](const Size& sz) {
using namespace cv::v4d::nvg;
clear();
fontSize(size);
fontFace("sans-bold");
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());
});
return win->display();
});
}
Template class for specifying the size of an image or rectangle.
Definition: types.hpp:335
_Tp height
the height
Definition: types.hpp:363
_Tp width
the width
Definition: types.hpp:362
std::shared_ptr< _Tp > Ptr
Definition: cvstd_wrapper.hpp:23
Definition: nvg.hpp:19
Definition: framebuffercontext.hpp:25
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106