简体   繁体   English

用python和OpenCV在图像内写文本

[英]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 为了将文本放入OpenCV,我写了

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? 如何更新文字?

在此处输入图片说明

You can use format() or if you're using Python 3, you can use f-strings 您可以使用format()如果您使用的是Python 3,则可以使用f字符串

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM