使用base64格式需要先将图片转码
先在python2.7中使用了人脸搜索功能,代码如下:
f = open('image/test.jpg','rb')
img = base64.b64encode(f.read())
result=client.search(str(img), imageType, GROUP)
if(result['result']):
for i in (result['result']['user_list']):
#print (i['user_info'][12:])
num=i['user_info'][12:]
print ('%s')% num
else:
print("error!")
但是在python3中使用人脸检测功能时,一直有错误,将str中加上‘utf-8’后解决,最后代码如下:
f = open('test.png', 'rb')
img=base64.b64encode(f.read())
re=client.detect(str(img,'utf-8'), imageType)
if re['result'] :
face_num=re['result']['face_num']
else:
face_num=0
print(re)
print(face_num)
不知道是python版本不同导致的还是百度的两个接口有差别,记录一下以后可能会用到
后来试了试果然是python版本不同,str参数的不同