背景
近期在进行图像处理相关需求的时候,处理了图像水印相关需求,想到了图像抠图,去除图像背景,通过查询使用 Rembg 开源库,对其进行环境配置和试用,特此记录。
步骤
- 安装
- 命令行安装 命令行安装 pip install rembg
- 源码安装
- git clone https://github.com/danielgatis/rembg.git
- pip install .
- 额外依赖
- pip install click
- pip install filetype
- pip install watchdog
- pip install aiohttp
- pip install gradio
- pip install asyncer
- 复制模型文件
- cp u2net.onnx /root/.u2net/
- 添加环境变量
- vi ~/.bashrc
- export OMP_NUM_THREADS=10
- . ~/.bashrc
- 执行命令
- rembg i after.png after-out.png
执行过程

[图像处理]基于Rembg的图像背景自动去除工具-输入图像1

[图像处理]基于Rembg的图像背景自动去除工具-输出图像1

[图像处理]基于Rembg的图像背景自动去除工具-输入图像2

[图像处理]基于Rembg的图像背景自动去除工具-输出图像2
总结
基于 Rembg 图像背景自动去除工具,搭建环境后对图片进行抠图。
参考
- https://gitee.com/alexgaoyh
- https://pap-docs.pap.net.cn/