当前位置:网站首页>谁说抠图要会 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
边栏推荐
- Solutions to common problems in visualization (IX) background color
- Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)
- 详解MySQL中timestamp和datetime时区问题导致做DTS遇到的坑
- Applet payment
- Jupyter Lab 十大高生产力插件
- Mba-day6 logic - hypothetical reasoning exercises
- 分享两个实用的shell脚本
- Facing the global market, platefarm today logs in to four major global platforms such as Huobi
- 数据库管理软件SQLPro for SQLite for Mac 2022.30
- Solve the problem of "suncertpathbuilderexception: unable to find valid certification path to requested target"
猜你喜欢
随机推荐
Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)
SWAT - Introduction to Samba web management tool
Mysql排序的特性详情
第六站神京门户-------手机号码的转换
MySQL8.0升级的踩坑历险记
Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)
PlatoFarm推出正式版游戏经济模型的特点分析
活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
Implementation of inserting millions of data into MySQL database in 10 seconds
MySQL failed to insert the datetime type field without single quotation marks
Usage of rename in cygwin
Detailed explanation of integer data type tinyint in MySQL
JDBC – PreparedStatement – 如何设置 Null 值?
Promise详解
mysql分表之后如何平滑上线详解
@valid,@Validated 的学习笔记
Detailed explanation of writing sequence and execution sequence of MySQL series SQL query statements
How to Ping Baidu development board
Mba-day6 logic - hypothetical reasoning exercises
Excel · VBA array bubble sorting function