最后编辑于2022-04
- 需要安装numpy opencv
pip install numpy
pip install opencv-python
- Python调用示例代码及返回数据处理
'''
Created on 2018-8-24
Python学习全靠百度AI文档
@author: 小帅丶
'''
import cv2
import base64
import numpy as np
import urllib3,base64
import json
from urllib.parse import urlencode
access_token='自己的token'
http=urllib3.PoolManager()
url='https://aip.baidubce.com/rest/2.0/image-classify/v1/body_seg?access_token='+access_token
f = open('G:/gestureface.jpg','rb')
#参数image:图像base64编码
img = base64.b64encode(f.read())
params={'image':img}
#对base64数据进行urlencode处理
params=urlencode(params)
request=http.request('POST',
url,
body=params,
headers={'Content-Type':'application/x-www-form-urlencoded'})
#对返回的byte字节进行处理。Python3输出位串,而不是可读的字符串,需要进行转换
result = str(request.data,'utf-8')
#返回参数json序列化处理
res = json.loads(result)
labelmap = base64.b64decode(res['labelmap'])
nparr = np.fromstring(labelmap,np.uint8)
labelimg = cv2.imdecode(nparr,1)
#402,402为原图的宽高 请自定替换哦
labelimg = cv2.resize(labelimg,(402,402),interpolation=cv2.INTER_NEAREST)
im_new = np.where(labelimg==1, 255, labelimg)
cv2.imwrite('G:/test22.jpg', im_new)
- 使用到的原图
- 处理后的图片
请登录后评论
TOP
切换版块
关于keyerror, 我的解决:
option = {"type": "labelmap"}
seg_res = client.bodySeg(image, option)
labelmap = base64.b64decode(seg_res['labelmap'])
请问怎么解决的呀
请问您·解决了吗
错误原因:因为调用返回的是错误值,故产生了后面的这个错误。
需要到百度AI里面去重新编辑自己创建的应用,把对应的功能打上勾。参考({"{"error_msg":"No permission to access data","error_code":6}处理方案 - 唐尧 - 博客园 (cnblogs.com))
显示KeyError: 'labelmap',怎么解决,求问谢谢
怎么解决的,可以造福一下大家吗,目前也遇到了这个问题
c# 使用使用人像分离接口时,出现 requested security protocol is not supported(运行环境4.4)
请问解决了吗?我也遇到了
请问下,怎么解决的,我也遇到这个问题了,谢谢
access_token这个怎么来的啊?
显示KeyError: 'labelmap',怎么解决,求问谢谢
已解决,麻烦了。
请教一下,命令行labelmap = base64.b64decode(res['labelmap']),显示KeyError: 'labelmap',怎么解决。
转数组矩阵吧。我也是做Java的。
大佬请问从labelmap 下方的代码是什么意思,本人是做java的,看不太懂python
https://ai.baidu.com 底部有各个模块的QQ群号哦
请问群号是多少?
部分接口是内测的。你需要单独申请哦。加群找群管或提交工单
请问一下,我创建的是人体识别的应用,根据给的AK与SK生成了access_token。为什么还是返回没有权限?
造福大家呀,66666