python实例_Python语言相片人像抠图源码实例

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-29 23:40   28   0

Python+Paddlehub相片人像抠图实例

无需PS软件,手动制作自己的抠图工具,在只有一张图片,需要细致地抠出人物的情况下,能帮你减少抠图步骤;在有多张图片需要抠的情况下,能直接帮你输出这些人物的基本轮廓

准备相片:

b4dac24a6ad57f6212d54058f88aa58b.png

安装相关的依赖包:

python -m pip install paddlepaddle

上传或拷贝需要抠图的图片和背景图片放到对应的文件夹中,并通过代码加载需要抠图的图片,进行展示:

# 待预测图片test_img_path = ["./girl.jpg"]  import matplotlib.pyplot as plt import matplotlib.image as mpimg  img = mpimg.imread(test_img_path[0])  # 展示待预测图片plt.figure(figsize=(10,10))plt.imshow(img) plt.axis('off') plt.show()

加载预训练模型

import paddlehub as hub module = hub.Module(name="deeplabv3p_xception65_humanseg") input_dict = {"image": test_img_path} # execute predict and print the resultresults = module.segmentation(data=input_dict)for result in results:    print(result) # 预测结果展示test_img_path = "./humanseg_output/girl.png"img = mpimg.imread(test_img_path)plt.figure(figsize=(10,10))plt.imshow(img) plt.axis('off') plt.show()

运行效果展示:

e6fbd4b0de0b9554cb978558249e1074.png
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP