這篇文章主要介紹了python實現人工智能Ai摳圖功能,本文經過實例代碼給你們介紹的很是詳細,具備必定的參考借鑑價值,須要的朋友能夠參考下
![](http://static.javashuo.com/static/loading.gif)
代碼
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次免費試用次數。.