0

I would like to render a custom text on an image using opencv, while having a white outline around the text, with the inside of the text being black. Currently I am only able to print the text in a single static color (black in this case) like so:

cv2.putText(img, "My text", (x, y), font, font_size, (0, 0, 0), font_thickness, lineType = cv2.LINE_AA)

How can I achieve an effect like the one shown below, where the outline of the text is printed in white, and the inner part in black?

enter image description here

Note: The text is placed on an image, so the remaining space (the grey space in the example image) around the text should be transparent.

Kyu96
  • 1,159
  • 2
  • 17
  • 35
  • 1
    dont abuse a computer-vision library for "effects", please. – berak Nov 17 '21 at 11:03
  • 1
    Excuse me? I am not abusing the library for special effects, I simply like to increase the visibility over the overlayed text, no point in adding additional dependencies for such a minor thing. – Kyu96 Nov 17 '21 at 12:07

1 Answers1

4

You could draw the text twice on the image: one for your outline and the other for your text.

cv2.putText(image,"text",(180,150),cv2.FONT_HERSHEY_COMPLEX,3,(255,255,255),16,cv2.LINE_AA)
cv2.putText(image,"text",(180,150),cv2.FONT_HERSHEY_COMPLEX,3,(0,0,0),4,cv2.LINE_AA)

enter image description here