python实现人像动漫化的示例代码
作者:mxtianv 时间:2021-08-16 06:36:17
利用百度api实现人像动漫化
百度API地址:https://ai.baidu.com/tech/imageprocess/selfie_anime
技术文档:https://ai.baidu.com/ai-doc/IMAGEPROCESS/Mk4i6olx5
注册百度账号,开通实现人像动漫化,创建应用。
# encoding:utf-8
import requests
import base64
# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【官网获取的AK】&client_secret=【官网获取的SK】'
response = requests.get(host)
if response:
access_token= response.json()["access_token"]
将上面的【官网获取的AK】【官网获取的SK】' 替换成自己的API Key 和 Secret Key
'''
人像动漫化
'''
request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"
# 二进制方式打开需要处理图片文件
f = open('001.jpg', 'rb') # 打开需要处理的图片
img = base64.b64encode(f.read())
params = {"image":img}
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)
print(response)
if response:
# 保存文件
f = open('t.jpg', 'wb')
img = (response.json()['image'])
f.write(base64.b64decode(img))
f.close()
来源:https://blog.csdn.net/mxtianv/article/details/106163311
标签:python,人像动漫化
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中正反斜杠(‘/’和‘\\’)的意义与用法
2023-01-22 14:45:04
Python学习之私有函数,私有变量及封装详解
2022-05-28 13:47:15
![](https://img.aspxhome.com/file/2023/7/127097_0s.png)
用自定义html标签让IE支持html 5新增元素
2008-03-18 12:57:00
基于Python中numpy数组的合并实例讲解
2023-01-23 18:17:26
![](https://img.aspxhome.com/file/2023/2/83702_0s.jpg)
使用pandas实现筛选出指定列值所对应的行
2023-05-06 18:29:53
![](https://img.aspxhome.com/file/2023/2/101032_0s.png)
sqlserver 数据库学习笔记
2011-12-01 08:15:06
使用Python实现管理系统附源码
2023-04-04 04:22:34
![](https://img.aspxhome.com/file/2023/8/117588_0s.jpg)
使用PowerShell实现批量修改或替换文件名
2023-02-08 05:02:10
![](https://img.aspxhome.com/file/2023/0/120920_0s.png)
图文详解OpenCV中光流以及视频特征点追踪
2022-12-30 01:45:08
![](https://img.aspxhome.com/file/2023/6/112466_0s.png)
Python利用pandas处理Excel数据的应用详解
2022-02-08 16:25:02
![](https://img.aspxhome.com/file/2023/6/82546_0s.png)
Python的组合模式与责任链模式编程示例
2023-05-08 07:03:43
详解javascript遍历方式
2023-10-14 16:44:48
Anaconda+Pycharm+Pytorch虚拟环境创建(各种包安装保姆级教学)
2023-06-27 23:21:39
![](https://img.aspxhome.com/file/2023/9/85139_0s.png)
内容页页码的预览导航
2008-07-07 16:43:00
![](https://img.aspxhome.com/file/UploadPic/20087/7/200877164658845s.jpg)
Django框架用户注销功能实现方法分析
2021-07-22 17:58:08
asp如何获知文件最后的修改日期和时间?
2009-11-24 20:49:00
基于Python编写一个语音合成系统
2021-10-14 03:28:16
![](https://img.aspxhome.com/file/2023/7/84067_0s.png)
pandas 像SQL一样使用WHERE IN查询条件说明
2023-07-01 23:26:37
![](https://img.aspxhome.com/file/2023/4/61724_0s.jpg)
python 寻找离散序列极值点的方法
2021-03-13 15:26:15
Oracle 创建监控账户 提高工作效率
2009-10-14 11:47:00
![](https://img.aspxhome.com/file/UploadPic/200910/14/20091014121213816.jpg)