用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()

最新文章

  1. 使用Xmanager访问CentOS远程桌面
  2. javascript高级程序设计---第二、三章
  3. 经典收藏 50个jQuery Mobile开发技巧集萃
  4. [转] - 经典SQL语句大全
  5. dom4j读写XML文件
  6. IOS学习之路-- 指针&宏函数
  7. Comparator和Comparable
  8. Weex 学习教程
  9. LaTex 下编译后不能显示中文,或者中文乱码
  10. N个任务掌握java系列之统计一篇文章中单词出现的次数
  11. LINQ 图解
  12. 免费git服务器以及使用过程中遇到的问题
  13. intellij-添加文档注释模板
  14. 基于js的数据结构与算法-数组
  15. SSM框架报HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException错
  16. 开源库RxJava、ButterKnife
  17. Linux:http配置
  18. 01_python_初始python
  19. jQuery找到GridView控件ItemTemplate模版内的控件
  20. PyQt5--GridLayoutMultiLine

热门文章

  1. ELK实战部署
  2. c++ 的学习 第二集函数的重载
  3. P1758-[NOI2009]管道取珠【dp】
  4. ARC122C-Calculator【乱搞,构造】
  5. P3971-[TJOI2014]Alice and Bob【贪心】
  6. 使用AC自动机解决文章匹配多个候选词问题
  7. kendoUI 多选下拉列表 kendoMultiSelect
  8. Oracle实时数据抽取项目问题总结
  9. postgresql高可用集群部署
  10. ArrayList-源码分析-自动扩容机制