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.
Downloading...
#include <opencv2/v4d/v4d.hpp>
using namespace cv;
using namespace cv::v4d;
int main() {
//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);
});
return win->display();
});
}
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