user11719635
user11719635

Reputation:

writing text inside image with python and OpenCV

I am writing my calculation result as a text in the image. In order to put a text in OpenCV, I write

font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(resul, '**text**', (10,450), font, 3, (0, 255, 0), 2, cv2.LINE_AA)

but my question is how can I update the text content each time when I am running the code. In other words, my code calculates a distance and gives a new result each time that I am running it. How can I update the text?

Upvotes: 1

Views: 1723

Answers (1)

nathancy
nathancy

Reputation: 46600

enter image description here

You can use format() or if you're using Python 3, you can use f-strings

font = cv2.FONT_HERSHEY_SIMPLEX
distance = 10
cv2.putText(resul, 'Distance: {}'.format(distance), (10,450), font, 3, (0, 255, 0), 2, cv2.LINE_AA)

Upvotes: 1

Related Questions