百度云链接:https://console.bce.baidu.com/?fromai=1#/aip/overview
1、1首先去百度文字识别创建应用,获取ak和sk
配置ak和sk
1、2 jniLibs文件夹复制过去
2、识别身份证信息方法:
/**** 解析身份证图片** @param idCardSide 身份证正反面* @param filePath 图片路径*/
private void recIDCard(final String idCardSide, String filePath) {Log.i("charge ID card", idCardSide);IDCardParams param = new IDCardParams();param.setImageFile(new File(filePath));// 设置身份证正反面param.setIdCardSide(idCardSide);// 设置方向检测param.setDetectDirection(true);// 设置图像参数压缩质量0-100, 越大图像质量越好但是请求时间越长。 不设置则默认值为20param.setImageQuality(40);OCR.getInstance().recognizeIDCard(param, new OnResultListener<IDCardResult>() {@Overridepublic void onResult(IDCardResult idCardResult) {Log.i("charge ID card", String.valueOf(idCardResult));if (idCardResult != null) {if (idCardSide.equals("back")) {String signDate = "";String expiryDate = "";String issueAuthority = "";if (idCardResult.getSignDate() != null) {signDate = idCardResult.getSignDate().toString();}if (idCardResult.getExpiryDate() != null) {expiryDate = idCardResult.getExpiryDate().toString();}if (idCardResult.getIssueAuthority() != null) {issueAuthority = idCardResult.getIssueAuthority().toString();}mContent.setText("签发机关: " + issueAuthority + "\n\n" +"有效期限: " + signDate + "-" + expiryDate + "\n\n");}else {String name = "";String sex = "";String nation = "";String num = "";String address = "";if (idCardResult.getName() != null) {name = idCardResult.getName().toString();}if (idCardResult.getGender() != null) {sex = idCardResult.getGender().toString();}if (idCardResult.getEthnic() != null) {nation = idCardResult.getEthnic().toString();}if (idCardResult.getIdNumber() != null) {num = idCardResult.getIdNumber().toString();}if (idCardResult.getAddress() != null) {address = idCardResult.getAddress().toString();}mContent.setText("姓名: " + name + "\n\n" +"性别: " + sex + "\n\n" +"民族: " + nation + "\n\n" +"身份证号码: " + num + "\n\n" +"住址: " + address + "\n\n");}}}@Overridepublic void onError(OCRError ocrError) {Toast.makeText(DetailActivity.this, "识别出错,请查看log错误代码", Toast.LENGTH_SHORT).show();Log.d("MainActivity", "onError: " + ocrError.getMessage());}});}
识别效果
在线回复bug:qq1085220040
demo链接:https://download.csdn.net/download/meixi_android/11014640