码迷,mamicode.com
首页 > 其他好文 > 详细

removebg抠图小工具

时间:2019-07-24 19:22:42      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:too   port   mbg   request   技术   get   span   总结   requests   

技术图片

由于比较简单,直接上代码(removebg接口官网),更多小工具获取

(1)官网API,需注册获取X-Api-Key:removebg_官网api.py  
技术图片
 1 import requests
 2 response = requests.post(
 3     https://api.remove.bg/v1.0/removebg,
 4     files={image_file: open(/path/to/file.jpg, rb)},
 5     data={size: auto},
 6     headers={X-Api-Key: INSERT_YOUR_API_KEY_HERE},
 7 )
 8 
 9 if response.status_code == requests.codes.ok:
10     with open(no-bg.png, wb) as out:
11         out.write(response.content)
12 else:
13     print("Error:", response.status_code, response.text)
removebg_官网api.py
(2)单个图片抠图removebg_one.py
技术图片
1 #https://www.remove.bg/api
2 #pip install removebg
3 
4 from removebg import RemoveBg
5 rmbg = RemoveBg("DG2WMZrZNnU2oG8fb7mzv6Ja", "error.log") # 引号内是你获取的API
6 rmbg.remove_background_from_img_file(r"E:\Python项目\总结复习\抠图removebg_\images\1.jpg",size="4k") #图片地址
removebg_one.py
(3)批量抠图removebg_more.py
技术图片
1 from removebg import RemoveBg
2 import os
3 
4 rmbg = RemoveBg("DG2WMZrZNnU2oG8fb7mzv6Ja", "error.log")# 引号内是你获取的API
5 path = os.path.join(os.getcwd(),images)#图片放到程序的同级文件夹images 里面
6 # print(os.listdir(path))
7 for pic in os.listdir(path):
8     rmbg.remove_background_from_img_file(f"{path}\{pic}")
removebg_more.py

 

removebg抠图小工具

标签:too   port   mbg   request   技术   get   span   总结   requests   

原文地址:https://www.cnblogs.com/open-yang/p/11240053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!