- *
⭐️情景引[【云AI】把妹子动漫化,我只改了2行?]:最近刚加[【云AI】把妹子动漫化,我只改了2行?]了百度松果人才培养菁英班,直接被安利了一波百度大脑,用起来真是吓了一跳,不用写模型也能玩转人工智能?
- *
[【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?[【云AI】把妹子动漫化,我只改了2行?]](https://img-blog.csdnimg.cn/776741812ba4466ea495aaccc5f3774f.jpg?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Y-v5Y-v5Y23,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
文章目录
- *
人像动漫化
运用对抗生成网络技术,结合人脸检测、头发分割、人像分割等技术,为用户量身定制千人千面的二次元动漫形象,并支持通过参数设置,生成戴口罩的二次元动漫人像
- *
官方展示的效果~
- *
我制作的效果~
[【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?[【云AI】把妹子动漫化,我只改了2行?]](https://img-blog.csdnimg.cn/42eff274f96f49b9a895fae56fec1eaf.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Y-v5Y-v5Y23,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
- *
是不是很传神?
还有更神奇的!
[【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?[【云AI】把妹子动漫化,我只改了2行?]](https://img-blog.csdnimg.cn/1ac8cf7d16db48b7886445be4ed150f6.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Y-v5Y-v5Y23,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
猫猫变成了透明!
- *
打开百度开发平台,直接注册账户就可以
所有的API都会赠送一定免费额度,大家可以放心尝试哦~
进[【云AI】把妹子动漫化,我只改了2行?]控制台创建应用,选择产品服务->[【云AI】把妹子动漫化,我只改了2行?]像增强与特效
[【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?[【云AI】把妹子动漫化,我只改了2行?]](https://img-blog.csdnimg.cn/914f06e421814409b97d289ff52b5bec.jpg?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Y-v5Y-v5Y23,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
- *
[【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?[【云AI】把妹子动漫化,我只改了2行?]](https://img-blog.csdnimg.cn/cf509744e89a4460b2a0dccb582c0378.jpg?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Y-v5Y-v5Y23,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
领取成功后会[【云AI】把妹子动漫化,我只改了2行?]圆圈所示区域显示剩余次数~
- *
点击创建应用,填写应用名称(任意),选择需要的接口(比如 [【云AI】把妹子动漫化,我只改了2行?]像增强与特效–人像动漫化),选择应用归属为个人,随便写一下应用【云AI】把妹子动漫化,我只改了2行?
[【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?[【云AI】把妹子动漫化,我只改了2行?]](https://img-blog.csdnimg.cn/f53bc687b612417fb474d74c2d58d463.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Y-v5Y-v5Y23,size_20,color_FFFFFF,t_70,g_se,x_16)
***
点击左侧应用列表,查看、保存API Key和Secret Key,后面会用到
[【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?【云AI】把妹子动漫化,我只改了2行?[【云AI】把妹子动漫化,我只改了2行?]](https://img-blog.csdnimg.cn/ca7883506acc419e93d7f24deb4c119b.jpg?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Y-v5Y-v5Y23,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
- *
请求示例
HTTP 方法:
POST
请求URL:
https://aip.baidubce.com/rest/2.0/image-process/v1/style_trans
URL参数:
参数
值
access_token
通过API Key和Secret Key获取的access_token,参考”Access Token获取”
Header如下:
参数
值
Content-Type
application/x-www-form-urlencoded
Body中放置请求参数,参数详情如下:
请求参数
参数
是否必选
类型
可选值范围
说明
image
和url二选一
string
-
base64编码后大小不超过10M(参考:原[【云AI】把妹子动漫化,我只改了2行?]大约为8M以内),最短边至少10px,最长边最大5000px,长宽比4:1以内。注意:【云AI】把妹子动漫化,我只改了2行?的base64编码是不包含【云AI】把妹子动漫化,我只改了2行?头的,如
(data:image/jpg;base64,)
url
和image二选一
string
-
【云AI】把妹子动漫化,我只改了2行?完整URL,URL长度不超过1024字节,URL对应的【云AI】把妹子动漫化,我只改了2行?base64编码后大小不超过10M(参考:原[【云AI】把妹子动漫化,我只改了2行?]大约为8M以内),最短边至少10px,最长边最大5000px,长宽比4:1以内,支持jpg/png/bmp格式,当image字段存[【云AI】把妹子动漫化,我只改了2行?]时url字段失效。
option
true
string
cartoon pencil color_pencil warm wave lavender mononoke scream gothic
cartoon:卡通画风格 pencil:铅笔风格 color_pencil:彩色铅笔画风格 warm:彩色糖块油画风格 wave:神奈川冲浪[【云AI】把妹子动漫化,我只改了2行?]油画风格 lavender:薰衣草油画风格 mononoke:奇异油画风格 scream:呐喊油画风格 gothic:哥特油画风格
- *
大家可以进【云AI】把妹子动漫化,我只改了2行?线调试接口](https://cloud.baidu.com/apiexplorer/index.html?Product=GWSE-9MurZfhUhTV&Api=GWAI-brGhFeh4wgi),嫌麻烦的也可以跳过[【云AI】把妹子动漫化,我只改了2行?]一步,直接通过代码调试
- *
官方给出的代码如下:
# encoding:utf-8
import requests
import base64
'''
人像动漫化
'''
request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"
# 二进制方式打开[【云AI】把妹子动漫化,我只改了2行?][【云AI】把妹子动漫化,我只改了2行?]文件
f = open('[本地文件]', 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
access_token = '[调用鉴权接口获取的token]'
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)
if response:
print (response.json())
我们对其稍作修改
# encoding:utf-8
import requests
import base64
def image_process(img_name,client_id,client_secret):
request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"
# 二进制方式打开[【云AI】把妹子动漫化,我只改了2行?][【云AI】把妹子动漫化,我只改了2行?]文件
f = open(img_name, 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
access_token = get_token(client_id,client_secret)
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)
if response:
print (response.json())
return response.json()['image']
- *
官方给出的token获取方式:
# encoding:utf-8
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:
print(response.json())
我们对其稍作修改
def get_token(client_id,client_secret):
# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = f'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}'
response = requests.get(host)
if response:
print(response.json())
return response.json()['access_token']
else:
print('no response!')
然后,运行代码就可以获取处理后【云AI】把妹子动漫化,我只改了2行?的base64编码啦~
# client_id 为官网获取的AK, client_secret 为官网获取的SK
client_id='xxx'
client_secret='xxx'
img_name='img_name.jpg'
img_base64=image_process(img_name,client_id,client_secret)
print(img_base64)
可以发现,官方已经给出了很详细的代码模板,我们真正需要改的部分也就只有 client_id='xxx'
client_secret='xxx'
两行而已~
- *
获取到编码后,可以[【云AI】把妹子动漫化,我只改了2行?]浏览器输[【云AI】把妹子动漫化,我只改了2行?]data:image/jpeg;[你的base64编码,注意需要去掉中括号]
查看【云AI】把妹子动漫化,我只改了2行?
或者使用下面的代码将base64编码转换成【云AI】把妹子动漫化,我只改了2行?
def base2picture(img_base64,img_save):
imgdata = base64.b64decode(img_base64)
with open(img_save,'wb') as f:
f.write(imgdata)
img_save='img_save.jpg'
base2picture(img_base64,img_save)
- *
# encoding:utf-8
import requests
import base64
def image_process(img_name,client_id,client_secret):
request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"
# 二进制方式打开[【云AI】把妹子动漫化,我只改了2行?][【云AI】把妹子动漫化,我只改了2行?]文件
f = open(img_name, 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
access_token = get_token(client_id,client_secret)
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)
if response:
print (response.json())
return response.json()['image']
def get_token(client_id,client_secret):
# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = f'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}'
response = requests.get(host)
if response:
print(response.json())
return response.json()['access_token']
else:
print('no response!')
def base2picture(img_base64,img_save):
imgdata = base64.b64decode(img_base64)
with open(img_save,'wb') as f:
f.write(imgdata)
if __name__=='__main__':
client_id='xxx'
client_secret='xxx'
img_name='1.jpg'
img_base64=image_process(img_name,client_id,client_secret)
print(img_base64)
# 或者[【云AI】把妹子动漫化,我只改了2行?]浏览器输[【云AI】把妹子动漫化,我只改了2行?] data:image/jpeg;[base64]
img_save='2.jpg'
base2picture(img_base64,img_save)
大家都学会了吗?
快去试试吧~