//识别行驶证
private void recVehicleLicense(String filePath) {
LoadPD.show(AddCarActivity.this, "");
OcrRequestParams param = new OcrRequestParams();
param.setImageFile(new File(filePath));
OCR.getInstance(this).recognizeVehicleLicense(param, new OnResultListener<OcrResponseResult>() {
@Override
public void onResult(OcrResponseResult ocrResponseResult) {
String result = ocrResponseResult.getJsonRes().toString();
try {
JSONObject jsonObject = new JSONObject(result);
JSONObject wordResult = jsonObject.optJSONObject("words_result");
String sbdm = wordResult.optJSONObject("车辆识别代号").optString("words");
String address = wordResult.optJSONObject("住址").optString("words");
String fzdw = wordResult.optJSONObject("发证单位").optString("words");
String fzTime = wordResult.optJSONObject("发证日期").optString("words");
String ppxh = wordResult.optJSONObject("品牌型号").optString("words");
String cType = wordResult.optJSONObject("车辆类型").optString("words");
String syr = wordResult.optJSONObject("所有人").optString("words");
String syxz = wordResult.optJSONObject("使用性质").optString("words");
String fdjhm = wordResult.optJSONObject("发动机号码").optString("words");
String hmhp = wordResult.optJSONObject("号牌号码").optString("words");
String zcrq = wordResult.optJSONObject("注册日期").optString("words");
LoadPD.close();
} catch (Exception e) {
LoadPD.close();
}
}
@Override
public void onError(OCRError ocrError) {
LoadPD.close();
T.showShort(AddCarActivity.this, "未能识别!");
}
});
}
//识别驾驶证
private void recVehicleLicense(String filePath) {
LoadPD.show(AddPeopleActivity.this, "");
OcrRequestParams param = new OcrRequestParams();
param.setImageFile(new File(filePath));
OCR.getInstance(this).recognizeDrivingLicense(param, new OnResultListener<OcrResponseResult>() {
@Override
public void onResult(OcrResponseResult ocrResponseResult) {
String result = ocrResponseResult.getJsonRes().toString();
try {
JSONObject jsonObject = new JSONObject(result);
JSONObject resultZj = jsonObject.optJSONObject("words_result");
String name = resultZj.optJSONObject("姓名").optString("words");
String jszh = resultZj.optJSONObject("证号").optString("words");//驾驶证号
String gdex = resultZj.optJSONObject("性别").optString("words");
String birthady = resultZj.optJSONObject("出生日期").optString("words");
String zjcx = resultZj.optJSONObject("准驾车型").optString("words");//准驾车型
String address = resultZj.optJSONObject("住址").optString("words");
LoadPD.close();
} catch (Exception e) {
LoadPD.close();
} finally {
}
}
@Override
public void onError(OCRError ocrError) {
LoadPD.close();
T.showShort(AddPeopleActivity.this, "未能识别!");
}
});
}
//识别身份证正面
private void recIDCard(final String idCardSide, final String filePath) {
LoadPD.show(AddPeopleActivity.this, "识别中");
IDCardParams param = new IDCardParams();
param.setImageFile(new File(filePath));
// 设置身份证正反面
param.setIdCardSide(idCardSide);
// 设置方向检测
param.setDetectDirection(true);
// 设置图像参数压缩质量0-100, 越大图像质量越好但是请求时间越长。 不设置则默认值为20
param.setImageQuality(20);
OCR.getInstance(this).recognizeIDCard(param, new OnResultListener<IDCardResult>() {
@Override
public void onResult(IDCardResult result) {
LoadPD.close();
try {
if (result != null) {
if (IDCardParams.ID_CARD_SIDE_FRONT.equals(idCardSide)) {
if (result.getDirection() == 0) {
tvIdcard.setText(result.getIdNumber() + "");
tvName.setText(result.getName() + "");
tvZhuzhi.setText(result.getAddress()+"");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onError(OCRError error) {
showErrorMessageDialog(idCardSide);
}
});
}
private void showErrorMessageDialog(final String idCardSide) {
String message = "";
if (IDCardParams.ID_CARD_SIDE_FRONT.equals(idCardSide)) {
message = "识别出错!" + "请确认是身份证正面吗?";
} else {
message = "识别出错!" + "请确认是身份证背面吗?";
}
T.showShort(AddPeopleActivity.this, message);
}