python實(shí)現(xiàn)人像動漫化的示例代碼
利用百度api實(shí)現(xiàn)人像動漫化

百度API地址:https://ai.baidu.com/tech/imageprocess/selfie_anime
技術(shù)文檔:https://ai.baidu.com/ai-doc/IMAGEPROCESS/Mk4i6olx5
注冊百度賬號,開通實(shí)現(xiàn)人像動漫化,創(chuàng)建應(yīng)用。

# encoding:utf-8 import requestsimport base64 # client_id 為官網(wǎng)獲取的AK, client_secret 為官網(wǎng)獲取的SKhost = ’https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【官網(wǎng)獲取的AK】&client_secret=【官網(wǎng)獲取的SK】’response = requests.get(host)if response: access_token= response.json()['access_token']
將上面的【官網(wǎng)獲取的AK】【官網(wǎng)獲取的SK】’ 替換成自己的API Key 和 Secret Key
’’’人像動漫化’’’request_url = 'https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime'# 二進(jìn)制方式打開需要處理圖片文件f = open(’001.jpg’, ’rb’) # 打開需要處理的圖片img = base64.b64encode(f.read()) params = {'image':img}request_url = request_url + '?access_token=' + access_tokenheaders = {’content-type’: ’application/x-www-form-urlencoded’}response = requests.post(request_url, data=params, headers=headers)print(response)if response: # 保存文件 f = open(’t.jpg’, ’wb’) img = (response.json()[’image’]) f.write(base64.b64decode(img)) f.close()
到此這篇關(guān)于python實(shí)現(xiàn)人像動漫化的示例代碼的文章就介紹到這了,更多相關(guān)python 人像動漫化內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 一文帶你徹底理解Java序列化和反序列化2. 用Spring JMS使異步消息變得簡單3. PHP驗(yàn)證碼工具-Securimage4. js實(shí)現(xiàn)碰撞檢測5. 關(guān)于IDEA 2020.3 多窗口視圖丟失的問題6. JS實(shí)現(xiàn)前端動態(tài)分頁碼代碼實(shí)例7. javascript實(shí)現(xiàn)貪吃蛇小練習(xí)8. Python 制作查詢商品歷史價(jià)格的小工具9. ASP.NET MVC使用jQuery ui的progressbar實(shí)現(xiàn)進(jìn)度條10. Python 下載Bing壁紙的示例

網(wǎng)公網(wǎng)安備