Python+Paddlehub相片人像抠图实例
无需PS软件,手动制作自己的抠图工具,在只有一张图片,需要细致地抠出人物的情况下,能帮你减少抠图步骤;在有多张图片需要抠的情况下,能直接帮你输出这些人物的基本轮廓
准备相片:
安装相关的依赖包:
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()
运行效果展示:
|