zoukankan      html  css  js  c++  java
  • removebg抠图小工具

    由于比较简单,直接上代码(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_images1.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
  • 相关阅读:
    HDU 1813 Escape from Tetris
    BZOJ 2276 Temperature
    BZOJ 4499 线性函数
    BZOJ 3131 淘金
    HDU 5738 Eureka
    POJ 2409 Let it Bead
    POJ 1286 Necklace of Beads
    POJ 1696 Space Ant
    Fox And Jumping
    Recover the String
  • 原文地址:https://www.cnblogs.com/open-yang/p/11240053.html
Copyright © 2011-2022 走看看