安装RemoveBg
pip install RemoveBg
安装成功!
批量处理图片实现抠图
上代码:
#coding:utf-8
from removebg import RemoveBg
import os
rmbg = RemoveBg("你的API密钥","error.log") #API密钥
path = 'image'
for pic in os.listdir(path): #os.listdir(path)的作用是返回path指定的文件夹包含的文件或文件夹的名字的列表
img_path = os.path.join(path,pic) #把目录和文件名合成一个路径
rmbg.remove_background_from_img_file(img_path) #去除背景
print(f'{img_path} is done')