非常简洁干净的一个背景移除工具,可以命令行方式运行、也可以web方式运行,也可以python代码方式运行,安装运行都非常简单。原理是基于图像分割和Matting算法,支持u2net的一些列模型。开源:https://github.com/danielgatis/rembg安装# CPU版本 pip install rembg # 如果有GPU,也可以安装GPU版 pip install rembg[gpu]运行# 命令行方式 rembg i path/to/input.png path/to/output.png # web方式 rembg sPython代码例子from rembg import remove input_path = "input.png" output_path = "output.png" with open(input_path, "rb") as i: with open(output_path, "wb") as o: input = i.read() output = remove(input) o.write(output)