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

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

    一种解决方案如下:

    1. img = cv2.imread('boat.png')
    2. text = 'This is \nsome text'
    3. y0, dy = 50, 25
    4. for i, txt in enumerate(text.split('\n')):
    5. y = y0+i*dy
    6. cv2.putText(img, txt, (50, y), cv2.FONT_HERSHEY_SIMPLEX, .6, (0, 255, 0), 1, 2)
    7. cv2.imshow('img', img)
    8. cv2.waitKey(0)

    https://blog.csdn.net/lanchunhui/article/details/71229235