OpenCV putText() new line character

Unfortunately putText doesn't correctly handle \n symbols. See the relevant rejected pull request. You need to split your text yourself and make several putText calls, something like:

text = "This is \n some text"
y0, dy = 50, 4
for i, line in enumerate(text.split('\n')):
    y = y0 + i*dy
    cv2.putText(img, line, (50, y ), cv2.FONT_HERSHEY_SIMPLEX, 1, 2)

Here's another example:

https://gist.github.com/EricCousineau-TRI/596f04c83da9b82d0389d3ea1d782592

Basically, same as elyase's answer, but using getTextSize() as well (though I had to increase line size a bit larger than expected).

Tags:

Python

Opencv