from wordcloud import WordCloud
import PIL.Image as image
import numpy as np
import jieba,cv2
def wordCloud():#生成词云
with open("word.txt",encoding="utf-8") as fp:
text=fp.read()
text="".join(jieba.cut(text))
mask=np.array(image.open("wangx.jpg"))
wordCloud=WordCloud(
mask=mask,
background_color="white",
font_path="C:\Windows\Fonts\本墨悠圆.ttf"
).generate(text)
image_produce = wordCloud.to_image()
image_produce.save("wangxpng.png")
image_produce.show()
def photo():#合并图
img1=cv2.imread("wangx.jpg")
img2=cv2.imread("wangxpng.png")
# 图像融合
combine = cv2.addWeighted(img1,0.5,img2,0.7,0)
cv2.imwrite("combine.png",combine)
cv2.imshow('combine',combine)
cv2.waitKey(0)
#主函数
if __name__ == '__main__':
wordCloud()
photo()