Python使用Rembg库去除图片背景

一、引入Rembg库

bash 复制代码
#库地址
https://github.com/danielgatis/rembg
bash 复制代码
#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

二、使用

python 复制代码
from rembg import remove
from PIL import Image

input_path = 'input.png'
output_path = 'output.png'

input = Image.open(input_path)
output = remove(input)
output.save(output_path)

三、效果

相关推荐
TF男孩14 分钟前
ARQ:一款低成本的消息队列,实现每秒万级吞吐
后端·python·消息队列
该用户已不存在5 小时前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
站大爷IP7 小时前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python
用户83562907805113 小时前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
侃侃_天下13 小时前
最终的信号类
开发语言·c++·算法
c8i13 小时前
python中类的基本结构、特殊属性于MRO理解
python
echoarts13 小时前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
liwulin050613 小时前
【ESP32-CAM】HELLO WORLD
python
Aomnitrix13 小时前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
Doris_202314 小时前
Python条件判断语句 if、elif 、else
前端·后端·python