DLTech21 / ZXingCamera

Camera for Android,身份证号码识别 (本地,实时)
40 stars 5 forks source link

能否做一个对焦拍照,然后调用接口识别 #9

Open M45ter opened 5 years ago

M45ter commented 5 years ago

能否做一个对焦拍照,然后调用接口识别,或者把idcard_ocr应用部分开源出来,自己调用so里的方法做识别-.-,目前的方式需要把身份证持续调整在框内才好识别,对操作要求比较高

devzwy commented 5 years ago

楼主部分代码可以拿出来。只不过到动态库那块就没了。😄

 private void decodeBitmap(byte[] data, int width, int height) {
        try {
            this.bitmap = this.getBitmap(data, width, height);
//            aty.setbt(bitmap);
            this.bitmap = BmpUtil.getScaleBitmap(this.bitmap, 800, false);
//            View v = aty.getView();
//            v.buildDrawingCache();
//            this. bitmap = v.getDrawingCache();
        } catch (Exception var12) {
            var12.printStackTrace();
        }

        boolean var4 = false;
        int var5 = -1;//身份证上人脸的位置
        IdentityInfo var6 = new IdentityInfo();
        if (this.f == IDCardEnum.FaceEmblem.getValue()) {
            if (this.bitmap != null) {
                this.d.a(this.bitmap);
//                aty.setbt(bitmap);
                OFRect var7 = new OFRect();

                try {
                    if (InvokeSoLib.getInstance() != null) {
                        // 得到身份证翻拍照上面人脸位置
                        var5 = InvokeSoLib.getInstance().getFacePosSyc(this.d.c(), this.d.a(), this.d.b(), var7);
                        if (var5 == 0) {

                            //进这里表示摄像头有检测到物体,但并不代表检测到了身份证
                            com.facefr.a.a var8 = new com.facefr.a.a((float) this.d.a(), (float) this.d.b());
                            if ((float) var7.iTop >= var8.a() && (float) var7.iRight <= var8.c()
                                    && (float) var7.iLeft >= var8.b() && (float) var7.iBottom <= var8.d()) {
                                //进到这里表示检测到了身份证图片
                                //把图片裁剪到只有身份证大小的bitmap
                                Bitmap var9 = BmpUtil.clipOcrBitmap(this.bitmap);

                                ByteArrayOutputStream var10 = new ByteArrayOutputStream();
                                var9.compress(CompressFormat.JPEG, 100, var10);
                                IDCard var11 = IDDetectGo.getInstance().detect(this.aty, var10.toByteArray());
                                System.out.println("idCard///////" + var11.toString());
                                if (var11 != null) {
                                    var5 = 0;
                                    if (TextUtils.isEmpty(var11.getCardNo())) {
                                        var4 = false;
                                    } else {
                                        var6.setAddress(var11.getAddress());
                                        var6.setBirthday(var11.getBirth());
                                        var6.setCertid(var11.getCardNo());
                                        var6.setName(var11.getName());
                                        var6.setFork(var11.getEthnicity());
                                        var6.setSex(var11.getSex());
                                        var6.setType(IDCardEnum.FaceEmblem);
                                        var4 = true;
                                    }
                                }
                            } else {
                                //检测到摄像头中无身份证
                                var4 = false;
                            }
                        }

                        System.out.println("isQualified///////" + var4 + " iReturn////" + var5);
                    }
                } catch (Exception var13) {
                    var13.printStackTrace();
                }
            }
        } else if (this.f == IDCardEnum.NationalEmblem.getValue()) {
            Bitmap var14 = BmpUtil.clipOcrBitmap(this.bitmap);
            ByteArrayOutputStream var15 = new ByteArrayOutputStream();
            var14.compress(CompressFormat.JPEG, 100, var15);
            IDCard var16 = IDDetectGo.getInstance().detect(this.aty, var15.toByteArray());
            System.out.println("idCard///////" + var16.toString());
            if (var16 != null) {
                var5 = 0;
                if (!TextUtils.isEmpty(var16.getAuthority()) && !TextUtils.isEmpty(var16.getPeriod())) {
                    var6.setIssue_authority(var16.getAuthority());
                    var6.setVaild_priod(var16.getPeriod());
                    var4 = true;
                } else {
                    var4 = false;
                }
            }
        }

        if (!this.a(var5, var4, var6) && null != this.aty.getHandler()) {
            this.aty.getHandler().sendEmptyMessage(R.id.ocr_face_decode_failed);
        }

    }
M45ter commented 5 years ago

@devzwy 是的,支持作者大佬开源出来,核心是在so那块,可以是文件下载

DLTech21 commented 5 years ago

不用实时对焦,直接拍完照然后检测?