一、引入Rembg库
#库地址
https://github.com/danielgatis/rembg
#CPU使用
pip install rembg # for library
pip install rembg[cli] # for library + cli#GPU使用(系统支持onnxruntime-gpu)
pip install rembg[gpu] # for library
pip install rembg[gpu,cli] # for library + cli
二、使用
from rembg import remove
from PIL import Imageinput_path = 'input.png'
output_path = 'output.png'input = Image.open(input_path)
output = remove(input)
output.save(output_path)