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

安裝
CPU版
pip?install?rembg
GPU版
pip?install?rembg[gpu]
快速上手
命令行調(diào)用
安裝成功后,可以在命令行中調(diào)動Rembg。如果只對單個圖片進行處理
rembg?i?path/to/input.png?path/to/output.png
對多個圖片文件處理(批處理),
rembg?p?path/to/input?path/to/output
在Python中使用
把圖片讀取為二進制數(shù)據(jù)
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)
來源:大鄧和他的Python

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