Loading...
Searching...
No Matches
Font rendering

Prev Tutorial: OpenGL Rendering
Next Tutorial: Video editing

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

Render Hello World

Draws "Hello World" to the screen using NanoVG. Demos some basic font options.

Font rendering
Downloading...
using namespace cv;
using namespace cv::v4d;
class FontRenderingPlan: public Plan {
//The text to render
string hw_ = "Hello World";
public:
void infer(Ptr<V4D> win) override {
//Render the text at the center of the screen. Note that you can load you own fonts.
win->nvg([](const Size &sz, const string &str) {
using namespace cv::v4d::nvg;
clear();
fontSize(40.0f);
fontFace("sans-bold");
fillColor(Scalar(255, 0, 0, 255));
textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
text(sz.width / 2.0, sz.height / 2.0, str.c_str(),
str.c_str() + str.size());
}, win->fbSize(), hw_);
}
};
int main() {
cv::Ptr<V4D> window = V4D::make(960, 960, "Font Rendering");
window->run<FontRenderingPlan>(0);
}
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
Definition: nvg.hpp:20
Definition: backend.hpp:15
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106