当前位置:   article > 正文

基于百度ai实现身份证,银行卡自动识别,车牌识别_百度ai 身份证号规范识别

百度ai 身份证号规范识别

1.创建应用 获取应用的API Key和Secret Key

2.下载SDK,将SDK的jar包和依赖包导入自己的项目。

3.下载License文件

4.初始化

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
initAccessTokenWithAkSk();
} else {
Toast.makeText(getApplicationContext(), "需要android.permission.READ_PHONE_STATE", Toast.LENGTH_LONG).show();
}
}

private boolean checkTokenStatus() {
if (!hasGotToken) {
Toast.makeText(getApplicationContext(), "token还未成功获取", Toast.LENGTH_LONG).show();
}
return hasGotToken;
}

/**
* 以license文件方式初始化
*/
private void initAccessToken() {
OCR.getInstance(this).initAccessToken(new OnResultListener<AccessToken>() {
@Override
public void onResult(AccessToken accessToken) {
String token = accessToken.getAccessToken();
hasGotToken = true;
}

@Override
public void onError(OCRError error) {
error.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MyZiliaoActivity.this, "licence方式获取token失败", Toast.LENGTH_SHORT).show();

}
});
}
}, getApplicationContext());
}

/**
* 用明文ak,sk初始化
*/
private void initAccessTokenWithAkSk() {
OCR.getInstance(this).initAccessTokenWithAkSk(new OnResultListener<AccessToken>() {
@Override
public void onResult(AccessToken result) {
String token = result.getAccessToken();
hasGotToken = true;
}

@Override
public void onError(OCRError error) {
error.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MyZiliaoActivity.this, "AK,SK方式获取token失败", Toast.LENGTH_SHORT).show();
}
});
}
}, getApplicationContext(), "xxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxx");
}

/**
* 自定义license的文件路径和文件名称,以license文件方式初始化
*/
private void initAccessTokenLicenseFile() {
OCR.getInstance(this).initAccessToken(new OnResultListener<AccessToken>() {
@Override
public void onResult(AccessToken accessToken) {
String token = accessToken.getAccessToken();
hasGotToken = true;
}

@Override
public void onError(OCRError error) {
error.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MyZiliaoActivity.this, "自定义文件路径licence方式获取token失败", Toast.LENGTH_SHORT).show();

}
});
}
}, "aip.license", getApplicationContext());
}
}

身份证正面
Intent intent = new Intent(MyZiliaoActi

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

闽ICP备14008679号