赞
踩
首先去百度智能云申请身份证识别接口 然后就用如下 APP_ID, API_KEY , SECRET_KEY
- //设置APPID/AK/SK
- private static String APP_ID = "";
- private static String API_KEY ="";
- private static String SECRET_KEY = "";
-
- public static String getPictureString(String photoPath) {
- String path = "";
- // 初始化一个AipOcr
- AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
-
- // 可选:设置网络连接参数
- client.setConnectionTimeoutInMillis(2000);
- client.setSocketTimeoutInMillis(60000);
-
- // 传入可选参数调用接口
- HashMap<String, String> options = new HashMap<String, String>();
- // 是否检测朝向
- options.put("detect_direction", "false");
- // 是否检测风险
- options.put("detect_risk", "false");
-
- // 正反面front /back
- String idCardSide = "front";
-
-
- // 参数为本地图片路径
- try {
- JSONObject res = client.idcard(path, idCardSide, options);
- if (res != null) {
- JSONObject idCard = new JSONObject();
- JSONObject words_result = res.getJSONObject("words_result");
- if (res.get("image_status").equals("non_idcard")){
- return "";
- }
- idCard.put("name", words_result.getJSONObject("姓名").get("words"));
- idCard.put("nation", words_result.getJSONObject("民族").get("words"));
- idCard.put("address", words_result.getJSONObject("住址").get("words"));
- idCard.put("sex", words_result.getJSONObject("性别").get("words"));
- idCard.put("birth", words_result.getJSONObject("出生").get("words"));
- idCard.put("number", words_result.getJSONObject("公民身份号码").get("words"));
- return idCard.toString(2);
- } else {
- return "";
- }
- }catch (JSONException e){
- e.printStackTrace();
- }
- return null;
- }
-
- public static void main(String[] args) {
- // String pictureString = getPictureString("图片绝对路径");
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。