PS技术不够,Python来凑!python实现人工智能Ai抠图功能

407 阅读1分钟
这篇文章主要介绍了python实现人工智能Ai抠图功能,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下


代码

from removebg import RemoveBg
import requests
import os
if __name__ == '__main__':
 path = '%s\picture'%os.getcwd()
 ispath = os.path.exists(path)
 if not ispath:
  os.mkdir(path)
 response = requests.post(
  'https://api.remove.bg/v1.0/removebg',
  files={'image_file': open(path+'/juqiamyi.jpg', 'rb')},
  # data={'size': 'auto','bg_color':'FFB6C1'},
  data={'size': 'auto'},
  headers={'X-Api-Key': '****YOU API KEY****'},
 )
 if response.status_code == requests.codes.ok:
  with open(path+'/juqiamyi.png', 'wb') as out:
   out.write(response.content)
 else:
  print("Error:", response.status_code, response.text)

说明一下,主要是调用第三方的api,申请一个账户会得到一个KEY,每个账户没一个月有50次免费试用次数。.


抠过图后:**
还是有点瑕疵的