这个是人脸识别时无法检测到图片报的错,有时候我们检测一张图片是否在库里面,当一张图片明显在里面,还检测不到,如下面是我的代码

 package Test1;

 import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap; import org.json.JSONObject; import com.baidu.aip.face.AipFace; /**
* 人脸对比
*/
public class BaiduFaceTest { // 这里填写你自己应用的三项
public static final String APP_ID = "";
public static final String API_KEY = "iinpWTE1pvOnH3YNmk4tG5Z6";
public static final String SECRET_KEY = "LMl3pgidH2AzGcTnOM3qh1x3GFnh6jt5"; public static void main(String[] args) throws IOException {
AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY); String image1 = "C:\\Users\\19575\\Pictures\\Saved Pictures\\紫霞仙子\\a.jpg";
String image2 = "C:\\Users\\19575\\Pictures\\Saved Pictures\\紫霞仙子\\b.jpg"; JSONObject rs = client.search(image1, "BASE64", "group002", new HashMap<>());
// JSONObject rs=client.detect(image1, "URL", new HashMap<>());
System.out.println(rs.toString()); } }

最后才搞明白是因为我们必须把图片转为BASE64才能正确的和库里面的图片比对,下面引入了加密函数

 package Test1;

 import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap; import org.json.JSONObject; import com.baidu.aip.face.AipFace; import sun.misc.BASE64Encoder; /**
* 人脸对比
*/
public class BaiduFaceTest { // 这里填写你自己应用的三项
public static final String APP_ID = "";
public static final String API_KEY = "iinpWTE1pvOnH3YNmk4tG5Z6";
public static final String SECRET_KEY = "LMl3pgidH2AzGcTnOM3qh1x3GFnh6jt5"; public static void main(String[] args) throws IOException {
AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY); String image1 = "C:\\Users\\19575\\Pictures\\Saved Pictures\\紫霞仙子\\c.jpg";
System.out.println(image1);
String image2 = "C:\\Users\\19575\\Pictures\\Saved Pictures\\紫霞仙子\\b.jpg"; String msg=GetImageStr(image1);
JSONObject rs = client.search(msg, "BASE64", "group002", new HashMap<>());
// JSONObject rs=client.detect(image1, "URL", new HashMap<>());
System.out.println(rs.toString()); }
public static String GetImageStr(String imgFile)
{//将图片文件转化为字节数组字符串,并对其进行Base64编码处理
InputStream in = null;
byte[] data = null;
//读取图片字节数组
try
{
in = new FileInputStream(imgFile);
data = new byte[in.available()];
in.read(data);
in.close();
}
catch (IOException e)
{
e.printStackTrace();
}
//对字节数组Base64编码
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);//返回Base64编码过的字节数组字符串
} }

不过加密解密函数无法直接使用,需要通过下面这个教程把自带的jar包导进去

https://blog.csdn.net/u011514810/article/details/72725398

这样可以正确的检测到图片了。

{ "result": null, "log_id": 304592860300941982, "error_msg": "image check fail", "cached": 0, "error_code": 222203, "timestamp": 1556030094 }的更多相关文章

  1. node js fcoin api 出现 api key check fail : {"status":1090,"msg":"Illegal API signature"}

    //主区://ft / btc 不支持市价 买入数量不能小于5个FT 买//ft / eth 支持市价 最小买入eth不能小于0.01 买//ft / usdt 支持市价 最小买入usdt不能小于10 ...

  2. Check failed: mdb_status == 0 (13 vs. 0) Permission denied

    文件权限问题. chown或者chmod即可 另外注意lmdb文件的权限

  3. Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default}) (state=08S01,code=0)

    sparksql 2.和hive2.1.1 由于sparksql中的hive-cli 等包的版本是1.2的需要自己下载,下载替换之后不报错,替换之前做好备份

  4. Check failed: mdb_status == 0 (2 vs. 0) No such file or directory

    运行  ./examples/mnist/train_lenet.sh  时,碰到了这个问题. 一定是路径问题!!!仔细查看prototxt文件里面的各种路径!!! 解决方案: 把.prototxt里 ...

  5. ConcurrentHashMap源码解析(JDK1.8)

    package java.util.concurrent; import java.io.ObjectStreamField; import java.io.Serializable; import ...

  6. proxySQL with SemiSync

    环境信息 hostname IP port role comm ms81 192.168.188.81 3399 master ms82 192.168.188.82 3399 slave ms83 ...

  7. MySQL ProxySQL读写分离使用初探

    目的 在美团点评DBProxy读写分离使用说明文章中已经说明了使用目的,本文介绍ProxySQL的使用方法以及和DBProxy的性能差异.具体的介绍可以看官网的相关说明,并且这个中间件也是percon ...

  8. TransactionTemplate编程式事务管理方式的进阶使用---自定义拓展模板类

    1, 前面一篇的文章介绍了TransactionTemplate的基本使用方法. 同事在其基础上又做了一层封装,这样更贴合本公司的业务与规范. 2, 首先定义了两个接口: ServiceTemplat ...

  9. 用shell脚本挂载linux主机拷贝相应文件copy.sh

    #!/bin/sh # $1 MOUNTDIR $2 TARGETDIR $3 ERRORLOG #参数检查 if test $# -ne 3 then echo "argument che ...

随机推荐

  1. 执行make出现“Warning: File `xxx.c' has modification time 2.6e+04 s in the future“警告的解决方法

    错误描述: 执行make命令时出现"make[2]: Warning: File `xxx.c' has modification time 1.6e+05 s in the future ...

  2. Lua文件操作和串行化

    function n_serialize(data) if type(data)=="number" then io.write(data,"\n") else ...

  3. Django的admin使用

    现在假设我们自己定义了一个用户模型和成员模型,我们需要在Django后台对它进行管理,使用admin可以对模型进行相关的展示设置和管理. from django.contrib import admi ...

  4. localtime 的性能问题及其替代者

    在系统从redhat5升到redhat6的过程中,服务的性能差了很多.经过定位发现是程序中频繁调用localtime/localtime_r所致. 而调用localtime_r 的实现中,对时区进行了 ...

  5. request.getHeader("x-forwarded-for")这是什么意思

    request.getHeader,简单的说就是获取请求的头部信息,根据http协议,它能获取到用户访问链接的信息,以下是我们常用的: request.getHeader("referer& ...

  6. CURL以 POST 请求链接的方式 初始化一个cURL会话来获取一个网页

    /** *POST URL */ function posturl($URL,$data) { $ch = curl_init(); // 创建一个新cURL资源 curl_setopt($ch,CU ...

  7. cocos2d-x 初探helloWorld

    cocos2d-x的main函数代码很少,把一些复杂的接口封装到AppDelegate类里了,“AppDelegate”从词意可以得出是app的代理类,而一些最早的场景都会在AppDelegate类里 ...

  8. 基于Nginx实现集群原理

    1)安装Nginx 2)配置多个Tomcat,并修改端口号(两个端口号不一样即可) 3)在Nginx的Nginx.conf添加如下配置:

  9. Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/images/json: dial unix /var/run/docker.sock: conne

    使用docker报如下错误信息: Got permission denied while trying to connect to the Docker daemon socket at unix:/ ...

  10. 使用 append 方法追加元素

    来自于<sencha touch 权威指南> 学习使用 Ext.DomHelper 组件在页面中追加元素.app.js代码如下: Ext.require(['Ext.form.Panel' ...