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)

三、效果

相关推荐
yugi98783818 分钟前
基于遗传算法优化主动悬架模糊控制的Matlab实现
开发语言·matlab
moxiaoran57531 小时前
Go语言的错误处理
开发语言·后端·golang
Cemtery1161 小时前
Day26 常见的降维算法
人工智能·python·算法·机器学习
yugi9878381 小时前
MATLAB的多层感知器(MLP)与极限学习机(ELM)实现
开发语言·matlab
星空椰2 小时前
快速掌握FastAPI:高效构建Web API
python·fastapi
塔尖尖儿2 小时前
Python中range()到底是什么演示
python
Never_Satisfied2 小时前
C#获取汉字拼音字母方法总结
开发语言·c#
zh_xuan2 小时前
kotlin 密封类
开发语言·kotlin
码小猿的CPP工坊2 小时前
C++软件开发之内存泄漏闭坑方法
开发语言·c++