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
using namespace cv;
using namespace cv::v4d;
class FontWithGuiPlan: public Plan {
struct Params {
//The font size
float size_ = 40.0f;
//The text hue
cv::Scalar_<float> color_ = {1.0f, 0.0f, 0.0f, 1.0f};
} params_;
//The text
string hw_ = "hello world";
void gui(Ptr<V4D> window) override {
window->imgui([](Ptr<V4D> win, ImGuiContext* ctx, Params& params) {
using namespace ImGui;
SliderFloat("Font Size", &params.size_, 1.0f, 100.0f);
ColorPicker4("Text Color", params.color_.val);
}, params_);
void infer(Ptr<V4D> window) override {
//Render the text at the center of the screen using parameters from the GUI.
window->nvg([](const Size& sz, const string& str, const Params& params) {
using namespace cv::v4d::nvg;
fillColor(params.color_ * 255.0);
text(sz.width / 2.0, sz.height / 2.0, str.c_str(), str.c_str() + str.size());
}, window->fbSize(), hw_, params_);
int main() {
Ptr<V4D> window = V4D::make(960, 960, "Font Rendering with GUI");
Template class for a 4-element vector derived from Vec.
Definition: types.hpp:670
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
Definition: v4d.hpp:68
std::shared_ptr< _Tp > Ptr
Definition: cvstd_wrapper.hpp:23
PyParams params(const std::string &tag, const std::string &model, const std::string &weights, const std::string &device)
Net::Result infer(cv::GOpaque< cv::Rect > roi, T in)
Calculates response for the specified network (template parameter) for the specified region in the so...
Definition: infer.hpp:474
Definition: nvg.hpp:20
void textAlign(int align)
void fontSize(float size)
void fontFace(const char *font)
void fillColor(const cv::Scalar &color)
void clear(const cv::Scalar &bgra=cv::Scalar(0, 0, 0, 255))
float text(float x, float y, const char *string, const char *end)
Definition: backend.hpp:15
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106