首页 版块 访问AI主站 注册 发帖
epot32
20
积分 积分商城
0
获赞
人脸对比返回的是空
Ta的回复 :用的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<String>(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); } });
3
人脸对比返回的是空
Ta的回复 :已解决,谢谢2楼帮忙。解决办法是 1.所有的工具类都使用百度提供的工具类,下载地址http://aixiaoshuai.mydoc.io/?t=234826 2.所有图片都已文件路径的方式访问,如果图片是bitmap对象,那先存储到本地,在通过api提供的FileUtil.readFileByBytes(filePath2)方式获取到字节数组。 3.对字节数组进行base64使用第一步下载地址中的Base64Util 4.进行UrlEncode 5.使用第一步下载地址中的HttpUtil参照官方文档进行请求获取人脸对比结果。 困扰好久的问题终于解决,感谢2楼,内牛满面啊!
3
切换版块
智能客服