Skip to content
On this page

使用 python 移除图片背景(u2net)

sh
pip install rembg
python
from rembg import remove
from PIL import Image

input_path = '/home/seven/Downloads/头像灰衣服.jpg'
output_path = '/home/seven/record/t54/t2.jpg'
inp = Image.open(input_path)
# Convert to RGB mode if not
output = output.convert("RGB")
output = remove(inp)
output.save(output_path)

Released under the MIT License.