一、目标
之前无意中看到有某位博主写过人像动漫化这样的文章,看着还挺好玩,所以我也想尝试一下。
利用百度智能云中的人工智能,对图片进行处理达到人像动漫化的效果。
二、准备工作
1.百度云智能账号创建
2.图像特效应用
3.开发环境python3.7+pycharm
首先要注册一个百度智能云账号,并创建这个图像特效应用
三、操作流程
3.1 阅读官方文档
当我们要使用一个我们不太了解的东西时,阅读官方文档无疑是最重要的,官方文档一般都写的特别详细,对每一个功能描述的很细节,我们先来看一下
修改代码
import requests import pprint import base64 def get_access_token(id,secret): get_access_token_url='https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id='+id+'&client_secret='+secret response=requests.get(get_access_token_url) content=response.json() access_token=content['access_token'] return access_toke<p>本文来源gao!%daima.com搞$代*!码$网9</p>n def Animation(img_file,access_token): request_url='https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime' f=open(img_file,'rb') image=base64.b64encode(f.read()) params = {"image":image} request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/x-www-form-urlencoded'} response = requests.post(request_url, data=params, headers=headers) pprint.pprint(response.json()) def main(): img_file = '1.jpg'#图片地址 id = '**************************' secret = '**************************' access_token = get_access_token(id, secret) Animation(img_file, access_token) if __name__ == '__main__': main()