AI攻略:图像风格转换
stroyka 发布于2020-12 浏览:2313 回复:1
0
收藏

.功能描述:

将图像转换成卡通画或素描风格,可用于开展趣味活动或集成到美图应用

2.平台接入

具体接入方式比较简单,可以参考我的另一个帖子,这里就不重复了:

http://ai.baidu.com/forum/topic/show/943327

3.调用攻略(Python3)及评测

3.1首先认证授权:

在开始调用任何API之前需要先进行认证授权,具体的说明请参考:

http://ai.baidu.com/docs#/Auth/top

具体Python3代码如下:

# -*- coding: utf-8 -*-

#!/usr/bin/env python

import urllib

import base64

import json

#client_id 为官网获取的AK, client_secret 为官网获取的SK

client_id =【百度云应用的AK】

client_secret =【百度云应用的SK】

#获取token

def get_token():

    host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret

    request = urllib.request.Request(host)

    request.add_header('Content-Type', 'application/json; charset=UTF-8')

    response = urllib.request.urlopen(request)

    token_content = response.read()

    #print (token_content)

    if token_content:

        token_info = json.loads(token_content)

        token_key = token_info['access_token']

    return token_key

3.2图像风格转换分析接口调用:

详细说明请参考: https://ai.baidu.com/docs#/ImageProcessing-API/824a761a

说明的比较清晰,这里就不重复了。

大家需要注意的是:

API访问URL:https://aip.baidubce.com/rest/2.0/image-process/v1/style_trans

输入图像:base64编码后大小不超过4M,像素乘积不超过2000*2000,最短边至少50px,最长边最大4096px,长宽比3:1以内。注意:图片的base64编码是不包含图片头的,如(data:image/jpg;base64,)

 

支持的风格:cartoon:卡通画风格 pencil:素描风格

 

收藏
点赞
0
个赞
共1条回复 最后由wangwei8638回复于2021-01
#2wangwei8638回复于2021-01

好好编辑一下啊

0
TOP
切换版块