当前位置:网站首页>谁说抠图要会 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
边栏推荐
- ffmpeg命令行常用参数
- PDMS软光刻加工过程
- Introduction to neo4j authoritative guide, recommended by Qiu Bojun, Zhou Hongxiang, Hu Xiaofeng, Zhou Tao and other celebrities
- 精彩回顾|「源」来如此 第六期 - 开源经济与产业投资
- 我的创作纪念日
- 面向全球市场,PlatoFarm今日登录HUOBI等全球四大平台
- Constraintlayout layout
- Visualization Road (11) detailed explanation of Matplotlib color
- Implementation of partition table of existing data table by MySQL
- STM32接电机驱动,杜邦线供电,然后反烧问题
猜你喜欢
随机推荐
About the three commonly used auxiliary classes of JUC
升级cpolar内网穿透能获得的功能
Learn go language 0x05: the exercise code of map in go language journey
Mysql系列SQL查询语句书写顺序及执行顺序详解
Use of SVN:
Google Earth Engine(GEE)——将原始影像进行升尺度计算(以海南市为例)
Code implementation of general bubbling, selection, insertion, hill and quick sorting
数据库管理软件SQLPro for SQLite for Mac 2022.30
Visual solutions to common problems (VIII) mathematical formulas
VM set up static virtual machine
How to bind a process to a specified CPU
初探 Lambda Powertools TypeScript
详解MySQL中timestamp和datetime时区问题导致做DTS遇到的坑
Visualization Road (11) detailed explanation of Matplotlib color
Jupyter Lab 十大高生产力插件
如何使用JDBC CallableStatement.wasNull()方法调用来查看最后一个OUT参数的值是否为 SQL NULL
Microsoft Access database using PHP PDO ODBC sample
R-drop: a more powerful dropout regularization method
Excel·VBA数组冒泡排序函数
Mba-day6 logic - hypothetical reasoning exercises









