用Python去除图片背景:​Rembg库

来源:大邓和他的Python

Python 的 Rembg 库可以去掉图片中的背景,效果如下

098212ea466cff0613edc66064674f41.png


安装

CPU版

pip install rembg

GPU版

pip install rembg[gpu]

快速上手

命令行调用

安装成功后,可以在命令行中调动Rembg。如果只对单个图片进行处理

rembg i path/to/input.png path/to/output.png

对多个图片文件处理(批处理),

rembg p path/to/input path/to/output

在Python中使用

把图片读取为二进制数据

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)
 
 
 
 
 
 

 
 
-------- End --------
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值