人物动漫化

前几天看到百度邮件说提供了人物动漫化的接口,一上来描(kai)述(chui):运用对抗生成网络技术,结合人脸检测、头发分割、人像分割等技术,为用户量身定制千人千面的二次元动漫形象。

不管用什么高科技技术,先看看效果怎么样,太差建议回炉重造。

https://ai.baidu.com/tech/imageprocess/selfie_anime

打开网址,首先我们先新建一个"图像效果增强"的应用,然后拷贝一下 APIKey 和 SecretKey 的密钥。

然后 python3.6 代码如下:

#coding:utf-8
import base64
import requests


def getToken(ak, sk):
    # client_id 为官网获取的APIKey, client_secret 为官网获取的SecretKey
    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:
         return response.json()


# 人像动漫化
def selfieAnime(filePath, access_token):
    request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"
    f = open(filePath, '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)
    with open('ttt.jpg','wb') as f:
        f.write(base64.b64decode(response.json()['image']))


filePath = 'luer.jpg'
client_id = 'r********************H'
client_secret = 'R**************************p'


token = getToken(client_id, client_secret)
selfie_anime(filePath, token['access_token'])

第一张效果还行吧

关于java的调用代码:

代码较多,存放在码云git仓库中,请自取。

https://gitee.com/mjTree/MyPython/tree/master/有趣代码/百度云API/人物动漫化


至于其他照片,丑到不行。。。。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值