{ "result": null, "log_id": 304592860300941982, "error_msg": "image check fail", "cached": 0...

在进行人脸识别时遇到问题,即使图片明显在库中也无法检测到。解决方案是将图片转换为BASE64编码进行比对。要实现这个功能,需要引入加密函数,并参照特定教程导入jar包,具体步骤可在提供的链接中找到。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 1 package Test1;
 2 
 3 import java.io.IOException;
 4 import java.util.Arrays;
 5 import java.util.HashMap;
 6 
 7 import org.json.JSONObject;
 8 
 9 import com.baidu.aip.face.AipFace;
10 
11 /**
12  * 人脸对比
13  */
14 public class BaiduFaceTest {
15 
16 // 这里填写你自己应用的三项
17     public static final String APP_ID = "16090420";
18     public static final String API_KEY = "iinpWTE1pvOnH3YNmk4tG5Z6";
19     public static final String SECRET_KEY = "LMl3pgidH2AzGcTnOM3qh1x3GFnh6jt5";
20 
21 
22 
23     public static void main(String[] args) throws IOException {
24         AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);
25 
26         String image1 = "C:\\Users\\19575\\Pictures\\Saved Pictures\\紫霞仙子\\a.jpg";
27         String image2 = "C:\\Users\\19575\\Pictures\\Saved Pictures\\紫霞仙子\\b.jpg";
28 
29 
30           JSONObject rs = client.search(image1, "BASE64", "group002", new HashMap<>());
31        // JSONObject rs=client.detect(image1, "URL", new HashMap<>());
32         System.out.println(rs.toString(2));
33 
34     }
35 
36 }

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

 1 package Test1;
 2 
 3 import java.io.FileInputStream;
 4 import java.io.IOException;
 5 import java.io.InputStream;
 6 import java.util.HashMap;
 7 
 8 import org.json.JSONObject;
 9 
10 import com.baidu.aip.face.AipFace;
11 
12 import sun.misc.BASE64Encoder;
13 
14 /**
15  * 人脸对比
16  */
17 public class BaiduFaceTest {
18 
19 // 这里填写你自己应用的三项
20     public static final String APP_ID = "16090420";
21     public static final String API_KEY = "iinpWTE1pvOnH3YNmk4tG5Z6";
22     public static final String SECRET_KEY = "LMl3pgidH2AzGcTnOM3qh1x3GFnh6jt5";
23 
24 
25 
26     public static void main(String[] args) throws IOException {
27         AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);
28 
29         String image1 = "C:\\Users\\19575\\Pictures\\Saved Pictures\\紫霞仙子\\c.jpg";
30         System.out.println(image1);
31         String image2 = "C:\\Users\\19575\\Pictures\\Saved Pictures\\紫霞仙子\\b.jpg";
32        
33         String msg=GetImageStr(image1);
34           JSONObject rs = client.search(msg, "BASE64", "group002", new HashMap<>());
35        // JSONObject rs=client.detect(image1, "URL", new HashMap<>());
36         System.out.println(rs.toString(2));
37 
38     }
39     public static String GetImageStr(String imgFile)  
40     {//将图片文件转化为字节数组字符串,并对其进行Base64编码处理  
41         InputStream in = null;  
42         byte[] data = null;  
43         //读取图片字节数组  
44         try   
45         {  
46             in = new FileInputStream(imgFile);          
47             data = new byte[in.available()];  
48             in.read(data);  
49             in.close();  
50         }   
51         catch (IOException e)   
52         {  
53             e.printStackTrace();  
54         }  
55         //对字节数组Base64编码  
56         BASE64Encoder encoder = new BASE64Encoder();  
57         return encoder.encode(data);//返回Base64编码过的字节数组字符串  
58     }  
59 
60 
61 }

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

https://blog.youkuaiyun.com/u011514810/article/details/72725398

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

转载于:https://www.cnblogs.com/henuliulei/p/10759567.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值