如何在python中的背景图像中嵌入文本图像?

时间:2019-06-08 06:07:42

标签: python numpy opencv text

我正在尝试使用python将文本嵌入背景图像中。背景图像为1.jpg,文本图像为2.jpg。背景图像包含一面墙,我要在其上嵌入文本区域2.jpg,其中包含场景文本“ Poppins”。有人可以帮我解决代码吗?

给出示例输入

enter image description here

示例输出如下:

enter image description here

尽管我用油漆涂过!!原始示例输出应如下所示,其中自然场景文本嵌入图像的背景中

enter image description here

示例文本图像为:

enter image description here

哪个是提取的场景文字

1 个答案:

答案 0 :(得分:2)

如果要将一个图像粘贴到另一个图像上,则您的文本文件应为.png文件(以便覆盖文件不包含背景数据),然后可以使用以下代码导入PIL库: / p>

from PIL import Image

image1 = Image.open('img1.jpg')
image2 = Image.open('img2.png')

image1.paste(image2, (0,0))

image1.show()

更改(0,0)值可在x,y坐标上四处移动png文本图像。