这篇文章主要介绍了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'},
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次免费试用次数。.