当前位置:网站首页>谁说抠图要会 PS?这个开源神器还能批量抠,效果拔群!
谁说抠图要会 PS?这个开源神器还能批量抠,效果拔群!
2022-04-23 11:15:00 【还债大湿兄】
转载:https://blog.csdn.net/osfront/article/details/114692606
【导语】:一款可用于快速移除背景图片的开源工具,安装配置后可在服务器、命令行中对图片进行批量操作。
简介
rembg 是使用 Python 实现的用于移除背景图片的工具,要求 Python 3.8 或更高版本,支持批量操作,使用方式比较灵活,可以直接使用命令行、作为服务运行、在 docker 中使用,还可以作为库调用。
下载安装
项目的源码地址是:
https://github.com/danielgatis/rembg
要求 Python 3.8 或更高版本,使用以下命令进行安装:
pip install rembg
简单使用
1、在命令行中使用
在命令行中可以对服务端图片、本地图片以及整个文件夹图片进行操作,如下:
(1)对远程图片进行操作:
curl -s http://input.png | rembg > output.png
(2)对本地图片进行操作:
rembg -o path/to/output.png path/to/input.png
(3)对整个文件夹里的图片进行操作:
rembg -p path/to/inputs
2、作为服务使用
(1)启动服务
rembg-server
(2)如果图片可以直接链接访问,则可以通过浏览器直接打开以下地址操作:
http://localhost:5000?url=http://image.png
也可以使用HTML表单通过上传文件的形式进行操作:
<form action="http://localhost:5000" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit" value="upload"/>
</form>
1
2
3
3、在docker中使用
在docker中使用也很方便,直接运行以下命令:
curl -s http://input.png | docker run -i -v ~/.u2net:/root/.u2net danielgatis/rembg:latest > output.png
4、作为库调用
直接在脚本里调用也很简便,先创建app.py,内容如下:
import sys
from rembg.bg import remove
sys.stdout.buffer.write(remove(sys.stdin.buffer.read()))
1
2
再执行命令运行:
cat input.png | python app.py > out.png
项目样例使用效果:
高级使用
有些图片可能使用alpha matting模式(即使用-a -ae 15选项)处理效果会更加完美,命令如下:
curl -s http://input.png | rembg -a -ae 15 > output.png
效果对比图如下:
结语
remgb简单介绍就到这里了,感兴趣的童鞋可以亲自下载安装体验一下,更详细介绍,请见项目主页。
开源前哨 日常分享热门、有趣和实用的开源项目。参与维护 10万+ Star 的开源技术资源库,包括:Python、Java、C/C++、Go、JS、CSS、Node.js、PHP、.NET 等。
版权声明
本文为[还债大湿兄]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_30377315/article/details/118610154
边栏推荐
- Upgrade the functions available for cpolar intranet penetration
- Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)
- Alarm scene recognition
- Mba-day5 Mathematics - application problems - engineering problems
- Mba-day5 Mathematics - application problems - engineering problems
- Mba-day5 Mathematics - application problems - engineering problems
- 26. 删除有序数组中的重复项
- Google Earth Engine(GEE)——将原始影像进行升尺度计算(以海南市为例)
- Constraintlayout layout
- 26. Delete duplicates in ordered array
猜你喜欢
随机推荐
vm设置静态虚拟机
Learning go language 0x01: start from the official website
Visual common drawing (I) stacking diagram
Understanding of fileprovider path configuration strategy
VM set up static virtual machine
MBA-day5數學-應用題-工程問題
Typora operation skill description (I) md
Solutions to common problems in visualization (IX) background color
R-drop: a more powerful dropout regularization method
Typora operation skill description (I)
Detailed explanation of MySQL creation stored procedure and function
MySQL面试题讲解之如何设置Hash索引
Oracle连通性测试小工具
MySQL partition table can be classified by month
GO接口使用
Implementation of inserting millions of data into MySQL database in 10 seconds
Understand the key points of complement
Database management software sqlpro for SQLite for Mac 2022.30
How to Ping Baidu development board
Visualization Road (10) detailed explanation of segmentation canvas function









