人脸对比返回的是空
epot32 发布于2018-05 浏览:1127 回复:3
0
收藏
{"result":[],"result_num":0,"log_id":3718971441051513},想问下是不是这个人脸必须注册才能进行 比对啊
收藏
点赞
0
个赞
共3条回复 最后由epot32回复于2018-05
#4epot32回复于2018-05

已解决,谢谢2楼帮忙。解决办法是

1.所有的工具类都使用百度提供的工具类,下载地址http://aixiaoshuai.mydoc.io/?t=234826
2.所有图片都已文件路径的方式访问,如果图片是bitmap对象,那先存储到本地,在通过api提供的FileUtil.readFileByBytes(filePath2)方式获取到字节数组。

3.对字节数组进行base64使用第一步下载地址中的Base64Util

4.进行UrlEncode

5.使用第一步下载地址中的HttpUtil参照官方文档进行请求获取人脸对比结果。

困扰好久的问题终于解决,感谢2楼,内牛满面啊!

0
#3epot32回复于2018-05

用的v2的接口 用java语言代码如下

// 摄像头捕获图片
String infos = ImageUtils.bitmapToBase64(bitmaps);
imgParam2 = URLEncoder.encode(infos, "UTF-8");

// 本地图片
InputStream inputStream = getResources().getAssets().open("24.jpg");
byte[] bytes = IOUtil.readBytes(inputStream);
localPic = byteArray2Syt(bytes);

String images = "images="+imgParam2+","+localPic;

 

String url = "https://aip.baidubce.com/rest/2.0/face/v2/match?access_token="+mToken;
Log.d("face","token="+mToken+"images="+images);
String param = "images="+images;

OKHttpUtils.getInstance(context).url(url).headers("Content-Type","application/x-www-form-urlencoded")
.postJsonString(param).postExecute(new UserCallback(context) {
@Override
public void onSuccess(Call call, String response) {
// DebugLog.e(response+"");
if (response != null && !response.contains("error_code")){
listen.onSuccess(response);
}else {
listen.onSuccess(new IOException(response));
}


}

@Override
public void onFail(Call call, IOException e) {
// DebugLog.e(e.getMessage()+"");

listen.onFailed(e);
}
});

0
#2用户已被禁言回复于2018-05

并不是。你是用V2还是V3版本的接口?是用什么语言?

方便代码贴出吗?

1
TOP
切换版块