当前位置:   article > 正文

百度api识别身份证 + 银行卡 + 驾驶证 + 行驶证 信息

百度api识别身份证 + 银行卡 + 驾驶证 + 行驶证 信息

你的打赏,是对我最大的支持:

 

 

 

银行卡  调用:

intent = new Intent(MainActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_BANK_CARD);
startActivityForResult(intent, REQUEST_CODE_CAMERA);

驾驶证 调用:

intent = new Intent(MainActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_GENERAL);
startActivityForResult(intent, REQUEST_CODE_DRIVING_LICENSE);

行驶证 调用:

  1. intent = new Intent(MainActivity.this, CameraActivity.class);
  2. intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
  3. intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_GENERAL);
  4. startActivityForResult(intent, REQUEST_CODE_VEHICLE_LICENSE);

 

身份证正面(手动识别) 调用:

  1. intent = new Intent(MainActivity.this, CameraActivity.class);
  2. intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
  3. intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_FRONT);
  4. startActivityForResult(intent, REQUEST_CODE_CAMERA);

身份证反面(手动识别) 调用:

  1. intent = new Intent(MainActivity.this, CameraActivity.class);
  2. intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
  3. intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_BACK);
  4. startActivityForResult(intent, REQUEST_CODE_CAMERA);

 

身份证正面(自动识别) 调用:

  1. intent = new Intent(MainActivity.this, CameraActivity.class);
  2. intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
  3. intent.putExtra(CameraActivity.KEY_NATIVE_ENABLE, true);
  4. intent.putExtra(CameraActivity.KEY_NATIVE_MANUAL, true);
  5. intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_FRONT);
  6. startActivityForResult(intent, REQUEST_CODE_CAMERA);

身份证反面(自动识别) 调用:

  1. intent = new Intent(MainActivity.this, CameraActivity.class);
  2. intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
  3. intent.putExtra(CameraActivity.KEY_NATIVE_ENABLE, true);
  4. intent.putExtra(CameraActivity.KEY_NATIVE_MANUAL, true);
  5. intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_BACK);
  6. startActivityForResult(intent, REQUEST_CODE_CAMERA);

 

 主页权限判断 :

主要事相机的权限:

<uses-permission android:name="android.permission.CAMERA" />

 

 

关键代码:

  1. /**
  2. * 判断相关权限问题
  3. */
  4. public void checkPermission() {
  5. // int checkINSTALL = ActivityCompat.checkSelfPermission(this, android.Manifest.permission.REQUEST_INSTALL_PACKAGES);
  6. int checkSelfPermission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
  7. if (checkSelfPermission == PackageManager.PERMISSION_GRANTED) { //允许 0, 询问 -1
  8. //已经获取到权限 获取用户媒体资源
  9. // checkUpdate();
  10. } else {
  11. //没有拿到权限 是否需要在第二次请求权限的情况下
  12. // 先自定义弹框说明 同意后在请求系统权限(就是是否需要自定义DialogActivity)
  13. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1514);
  14. }
  15. }

 

 

private void initAccessTokenWithAkSk() {
    OCR.getInstance().initAccessTokenWithAkSk(
            new OnResultListener<AccessToken>() {
                @Override
                public void onResult(AccessToken result) {
                    // 本地自动识别需要初始化
                    initLicense();

                    Log.d("MainActivity", "onResult: " + result.toString());
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, "初始化认证成功", Toast.LENGTH_SHORT).show();
                        }
                    });
                }

                @Override
                public void onError(OCRError error) {
                    error.printStackTrace();
                    Log.e("MainActivity", "onError: " + error.getMessage());
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, "初始化认证失败,请检查 key", Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }, getApplicationContext(),
            // 需要自己配置 https://console.bce.baidu.com
            "**************************************",//填写自己的
            // 需要自己配置 https://console.bce.baidu.com
            "***************************************");//填写自己的
}

  1. private void initLicense() {
  2. CameraNativeHelper.init(this, OCR.getInstance().getLicense(),
  3. new CameraNativeHelper.CameraNativeInitCallback() {
  4. @Override
  5. public void onError(int errorCode, Throwable e) {
  6. final String msg;
  7. switch (errorCode) {
  8. case CameraView.NATIVE_SOLOAD_FAIL:
  9. msg = "加载so失败,请确保apk中存在ui部分的so";
  10. break;
  11. case CameraView.NATIVE_AUTH_FAIL:
  12. msg = "授权本地质量控制token获取失败";
  13. break;
  14. case CameraView.NATIVE_INIT_FAIL:
  15. msg = "本地质量控制";
  16. break;
  17. default:
  18. msg = String.valueOf(errorCode);
  19. }
  20. runOnUiThread(new Runnable() {
  21. @Override
  22. public void run() {
  23. Toast.makeText(MainActivity.this,
  24. "本地质量控制初始化错误,错误原因: " + msg, Toast.LENGTH_SHORT).show();
  25. }
  26. });
  27. }
  28. });
  29. }
  30. @Override
  31. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  32. super.onActivityResult(requestCode, resultCode, data);
  33. if (requestCode == REQUEST_CODE_CAMERA && resultCode == Activity.RESULT_OK) {
  34. if (data != null) {
  35. String contentType = data.getStringExtra(CameraActivity.KEY_CONTENT_TYPE);
  36. String filePath = FileUtil.getSaveFile(getApplicationContext()).getAbsolutePath();
  37. if (!TextUtils.isEmpty(contentType)) {
  38. if (CameraActivity.CONTENT_TYPE_ID_CARD_FRONT.equals(contentType)) {
  39. recIDCard(IDCardParams.ID_CARD_SIDE_FRONT, filePath);
  40. } else if (CameraActivity.CONTENT_TYPE_ID_CARD_BACK.equals(contentType)) {
  41. recIDCard(IDCardParams.ID_CARD_SIDE_BACK, filePath);
  42. } else if (CameraActivity.CONTENT_TYPE_BANK_CARD.equals(contentType)) {
  43. recCreditCard(filePath);
  44. }
  45. }
  46. }
  47. }
  48. if (requestCode == REQUEST_CODE_DRIVING_LICENSE && resultCode == Activity.RESULT_OK) {
  49. String filePath = FileUtil.getSaveFile(getApplicationContext()).getAbsolutePath();
  50. recDrivingCard(filePath);
  51. }
  52. if (requestCode == REQUEST_CODE_VEHICLE_LICENSE && resultCode == Activity.RESULT_OK) {
  53. String filePath = FileUtil.getSaveFile(getApplicationContext()).getAbsolutePath();
  54. recVehicleCard(filePath);
  55. }
  56. }

 

 地址:https://console.bce.baidu.com

 

 

 

 

可以查看   应用详情      查看文档    下载SDK

 

下载地址:https://github.com/hl152152/Distinguish.git

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/683081
推荐阅读
相关标签
  

闽ICP备14008679号