百度身份证文字识别

首先去百度智能云申请身份证识别接口 然后就用如下 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("图片绝对路径");
    }

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值