用Python去除圖片背景:?Rembg庫(kù)
Python 的 Rembg 庫(kù)可以去掉圖片中的背景,效果如下

安裝
CPU版
pip?install?rembg
GPU版
pip?install?rembg[gpu]
快速上手
命令行調(diào)用
安裝成功后,可以在命令行中調(diào)動(dòng)Rembg。如果只對(duì)單個(gè)圖片進(jìn)行處理
rembg?i?path/to/input.png?path/to/output.png
對(duì)多個(gè)圖片文件處理(批處理),
rembg?p?path/to/input?path/to/output
在Python中使用
把圖片讀取為二進(jìn)制數(shù)據(jù)
from?rembg?import?remove
#待處理的圖片路徑
input_path?=?'input.png'
#處理后存儲(chǔ)的圖片路徑
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)
來(lái)源:大鄧和他的Python

加入知識(shí)星球【我們談?wù)摂?shù)據(jù)科學(xué)】
500+小伙伴一起學(xué)習(xí)!
·?推薦閱讀?·
在jupyter中實(shí)現(xiàn)實(shí)時(shí)協(xié)同是一種什么體驗(yàn)
評(píng)論
圖片
表情
