用Python实现人像动漫化
2024-08-31 02:05:16
用Python实现人像动漫化
本文章会教你如何使用Python实现人像动漫化,先看看效果实例:
实现过程如下:
本案例是使用百度的API来实现的,首先需要进入百度AI开放平台注册账号,具体流程就不讲了。登陆后我们可以看到如下界面:
import base64
import requests
# 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"]
'''
人像动漫化
'''
request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"
# 二进制方式打开需要处理图片文件
f = open('原图.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('动漫图.jpg', 'wb')
img = (response.json()['image'])
f.write(base64.b64decode(img))
f.close()
最新文章
- 使用Xmanager访问CentOS远程桌面
- javascript高级程序设计---第二、三章
- 经典收藏 50个jQuery Mobile开发技巧集萃
- [转] - 经典SQL语句大全
- dom4j读写XML文件
- IOS学习之路-- 指针&;宏函数
- Comparator和Comparable
- Weex 学习教程
- LaTex 下编译后不能显示中文,或者中文乱码
- N个任务掌握java系列之统计一篇文章中单词出现的次数
- LINQ 图解
- 免费git服务器以及使用过程中遇到的问题
- intellij-添加文档注释模板
- 基于js的数据结构与算法-数组
- SSM框架报HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException错
- 开源库RxJava、ButterKnife
- Linux:http配置
- 01_python_初始python
- jQuery找到GridView控件ItemTemplate模版内的控件
- PyQt5--GridLayoutMultiLine