cv2.putText 文字换行('n')无法解析换行

xiaoxiao2021-02-28  70

OpenCV putText() new line character

cv2.putText 在向图像中添加文本信息时,如果在待添加的文本中含有换行转义符,一般它是无法正确处理的:

cv2.putText(img, "This is \n some text", (50,50), cv2.FONT_HERSHEY_SIMPLEX, .6, (0, 255, 0), 1, 2)

一种解决方案如下:

img = cv2.imread('boat.png') text = 'This is \nsome text' y0, dy = 50, 25 for i, txt in enumerate(text.split('\n')): y = y0+i*dy cv2.putText(img, txt, (50, y), cv2.FONT_HERSHEY_SIMPLEX, .6, (0, 255, 0), 1, 2) cv2.imshow('img', img) cv2.waitKey(0)
转载请注明原文地址: https://www.6miu.com/read-39057.html

最新回复(0)