身份证识别不出来
zhnxxxn 发布于2019-12 浏览:3322 回复:5
0
收藏

一直报错!!!

try{
                String name2=upFile.getSavedFileName();
                AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
                client.setConnectionTimeoutInMillis(2000);
                client.setSocketTimeoutInMillis(60000);
                HashMap options = new HashMap<>();
                options.put("detect_direction", "true");
                options.put("detect_risk", "false");
                JSONObject frontres = client.idcard("D:\\Tomcat 9.0\\webapps\\rjxs\\image\\"+name2, "front", options);
                JSONObject words_result=(JSONObject) frontres.get("words_result");
                JSONObject name1 = (JSONObject) words_result.get("姓名");
                JSONObject nation = (JSONObject) words_result.get("民族");
                JSONObject address = (JSONObject) words_result.get("住址");
                JSONObject IDNumber = (JSONObject) words_result.get("公民身份号码");
                JSONObject sex = (JSONObject) words_result.get("性别");
                request.setAttribute("name11",name1.get("words"));
                request.setAttribute("nation1", nation.get("words"));
                request.setAttribute("address1", address.get("words"));
                request.setAttribute("IDNumber1", IDNumber.get("words"));
                request.setAttribute("sex1", sex.get("words"));

}
catch(Exception e)
{	
	backNews="";
	upFile.setBackNews(backNews+e);
	RequestDispatcher dispatcher=request.getRequestDispatcher("reload.jsp");
    dispatcher.forward(request,response);
	//response.sendRedirect("inputRegisterMess.jsp");
	
}
收藏
点赞
0
个赞
共5条回复 最后由用户已被禁言回复于2022-04
#6用户已被禁言回复于2019-12
#4 zhnxxxn回复
还有 另一张图 好像识别成功了 又报其他错了![图片]

错误码 官方都是有文字列出来的。建议先自己稍微仔细看一下百度PM们辛苦写的文档。

https://ai.baidu.com/ai-doc/OCR/dk3h7y5vr

1
#5用户已被禁言回复于2019-12
#3 zhnxxxn回复
[图片] 这是识别不成功的意思吧...

实际测试使用 最好是真实的身份证。

0
#4zhnxxxn回复于2019-12

还有 另一张图 好像识别成功了 又报其他错了!

0
#3zhnxxxn回复于2019-12

这是识别不成功的意思吧...

0
#2用户已被禁言回复于2019-12

json解析报错。不确定是不是接口没有识别出来的问题

你先别着急解析你要的数据。整个json数据打印出来看一下。

 

JSONObject frontres = client.idcard("D:\\Tomcat 9.0\\webapps\\rjxs\\image\\"+name2, "front", options);

这里直接打印frontres.toString(2) 先看是不是识别成功 再考虑你后续的具体值的获取代码

 

也可以参考我的帖子 https://ai.baidu.com/forum/topic/show/498362  我用的是fastjson  SDK 默认用的是org.json 需要toString 再用fastjson解析成JavaBean

1
TOP
切换版块