• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python实战之百度智能云使人像动漫化

python 搞代码 4年前 (2022-01-09) 27次浏览 已收录 0个评论
文章目录[隐藏]

一、目标

之前无意中看到有某位博主写过人像动漫化这样的文章,看着还挺好玩,所以我也想尝试一下。

利用百度智能云中的人工智能,对图片进行处理达到人像动漫化的效果。

二、准备工作

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

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python实战之百度智能云使人像动漫化
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址