Home > Back-end >  How can i draw outline or shadow to a text with using OpenCV?
How can i draw outline or shadow to a text with using OpenCV?

Time:07-19

In my C project, im using OpenCV library to implement image processing algorithms. I want to draw outline or shadow to texts that i drew on frames with using OpenCV's putText function. I have researched about it but only solution that i found is drawing the same text twice. This solution drops the FPS of my overall project because im drawing many texts on the frames.

Do i have to code a new font library for my project or is there any simpler solutions to it?

thanks in advance.

EDIT: I tried FreeType with different ttf fonts that i found in various websites. Yes, there are some fonts that has default shadow or outlines in it. The problem here is i can't change the colour of the shadow of it. Yes, i can change the colour of overall font but shadow colour becomes the same as the font. I want black or white shadow that can highlight the text.

CodePudding user response:

You could use freetype. OpenCV can be compiled with FreeType which will allow you to load fonts from ttf files. then you can look up for a free font online which suits four needs of make your own ttf file.

Here is a link on how to use FreeType with opencv. https://docs.opencv.org/3.4/d9/dfa/classcv_1_1freetype_1_1FreeType2.html

CodePudding user response:

The simplest thing to do is draw the text once to an empty image, say A. then mask your main image several times with A, shifting A as required.

  • Related