|
|
@@ -247,19 +247,19 @@ public class BaiduOcrUtil { |
|
|
|
JSONObject wordsResult = object.getJSONObject("words_result"); |
|
|
|
if (wordsResult == null) throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("身份证识别返回为空"); |
|
|
|
|
|
|
|
if(wordsResult.getJSONObject("姓名") != null) res.setName(wordsResult.getJSONObject("姓名").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("性别") != null) res.setGender(wordsResult.getJSONObject("性别").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("民族") != null) res.setNation(wordsResult.getJSONObject("民族").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("出生") != null){ |
|
|
|
String birthdayStr = wordsResult.getJSONObject("出生").getString("words"); |
|
|
|
String birthday = LocalDate.parse(birthdayStr, DateTimeFormatter.ofPattern("yyyyMMdd")).format(DateTimeFormatter.ofPattern("yyyy.MM.dd")); |
|
|
|
res.setBirthday(birthday); |
|
|
|
} |
|
|
|
if(wordsResult.getJSONObject("住址") != null) res.setAddress(wordsResult.getJSONObject("住址").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("姓名") != null) res.setName(wordsResult.getJSONObject("姓名").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("公民身份号码") != null) res.setIdno(wordsResult.getJSONObject("公民身份号码").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("性别") != null) res.setGender(wordsResult.getJSONObject("性别").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("民族") != null) res.setNation(wordsResult.getJSONObject("民族").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("失效日期") != null) res.setEnddate(wordsResult.getJSONObject("失效日期").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("签发机关") != null) res.setAgency(wordsResult.getJSONObject("签发机关").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("签发日期") != null) res.setBegindate(wordsResult.getJSONObject("签发日期").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("签发机关") != null) res.setAgency(wordsResult.getJSONObject("签发机关").getString("words")); |
|
|
|
|
|
|
|
res.setCode("0"); |
|
|
|
res.setRespCode("0000"); |
|
|
@@ -277,25 +277,34 @@ public class BaiduOcrUtil { |
|
|
|
JSONObject wordsResult = object.getJSONObject("words_result"); |
|
|
|
if (wordsResult == null) throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("行驶证识别返回为空"); |
|
|
|
|
|
|
|
if(wordsResult.getJSONObject("品牌型号") != null) res.setModel(wordsResult.getJSONObject("品牌型号").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("使用性质") != null) res.setCharacter(wordsResult.getJSONObject("使用性质").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("发动机号码") != null) res.setEngine(wordsResult.getJSONObject("发动机号码").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("住址") != null) res.setAddress(wordsResult.getJSONObject("住址").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("车辆识别代号") != null) res.setVin(wordsResult.getJSONObject("车辆识别代号").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("车辆类型") != null) res.setVehicle(wordsResult.getJSONObject("车辆类型").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("整备质量") != null) res.setUnladen(wordsResult.getJSONObject("整备质量").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("号牌号码") != null) { |
|
|
|
res.setPlate_a(wordsResult.getJSONObject("号牌号码").getString("words")); |
|
|
|
res.setPlate_b(wordsResult.getJSONObject("号牌号码").getString("words")); |
|
|
|
} |
|
|
|
if(wordsResult.getJSONObject("备注") != null) res.setNote(wordsResult.getJSONObject("备注").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("准牵引总质量") != null) res.setTowing(wordsResult.getJSONObject("准牵引总质量").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("车辆类型") != null) res.setVehicle(wordsResult.getJSONObject("车辆类型").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("所有人") != null) res.setMan(wordsResult.getJSONObject("所有人").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("住址") != null) res.setAddress(wordsResult.getJSONObject("住址").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("使用性质") != null) res.setCharacter(wordsResult.getJSONObject("使用性质").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("品牌型号") != null) res.setModel(wordsResult.getJSONObject("品牌型号").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("车辆识别代号") != null) res.setVin(wordsResult.getJSONObject("车辆识别代号").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("发动机号码") != null) res.setEngine(wordsResult.getJSONObject("发动机号码").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("注册日期") != null){ |
|
|
|
String registerStr = wordsResult.getJSONObject("注册日期").getString("words"); |
|
|
|
String register = LocalDate.parse(registerStr, DateTimeFormatter.ofPattern("yyyyMMdd")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|
|
|
res.setRegister(register); |
|
|
|
} |
|
|
|
if(wordsResult.getJSONObject("发证日期") != null){ |
|
|
|
String issueStr = wordsResult.getJSONObject("发证日期").getString("words"); |
|
|
|
String issue = LocalDate.parse(issueStr, DateTimeFormatter.ofPattern("yyyyMMdd")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|
|
|
res.setIssue(issue); |
|
|
|
} |
|
|
|
if(wordsResult.getJSONObject("发证单位") != null) res.setIssueUnit(wordsResult.getJSONObject("发证单位").getString("words")); |
|
|
|
|
|
|
|
if(wordsResult.getJSONObject("档案编号") != null) res.setFile(wordsResult.getJSONObject("档案编号").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("核定载人数") != null) res.setApc(wordsResult.getJSONObject("核定载人数").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("总质量") != null) res.setGross(wordsResult.getJSONObject("总质量").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("检验记录") != null) res.setInspection(wordsResult.getJSONObject("检验记录").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("整备质量") != null) res.setUnladen(wordsResult.getJSONObject("整备质量").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("核定载质量") != null) res.setAlc(wordsResult.getJSONObject("核定载质量").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("所有人") != null) res.setMan(wordsResult.getJSONObject("所有人").getString("words")); |
|
|
|
|
|
|
|
if(wordsResult.getJSONObject("外廓尺寸") != null){ |
|
|
|
String outsideDimensions = wordsResult.getJSONObject("外廓尺寸").getString("words"); |
|
|
|
if (StringUtils.hasText(outsideDimensions) && outsideDimensions.contains("^")) { |
|
|
@@ -304,26 +313,12 @@ public class BaiduOcrUtil { |
|
|
|
outsideDimensions = outsideDimensions.toLowerCase(); |
|
|
|
res.setOverall(outsideDimensions); |
|
|
|
} |
|
|
|
if(wordsResult.getJSONObject("发证日期") != null){ |
|
|
|
String issueStr = wordsResult.getJSONObject("发证日期").getString("words"); |
|
|
|
String issue = LocalDate.parse(issueStr, DateTimeFormatter.ofPattern("yyyyMMdd")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|
|
|
res.setIssue(issue); |
|
|
|
} |
|
|
|
if(wordsResult.getJSONObject("注册日期") != null){ |
|
|
|
String registerStr = wordsResult.getJSONObject("注册日期").getString("words"); |
|
|
|
String register = LocalDate.parse(registerStr, DateTimeFormatter.ofPattern("yyyyMMdd")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|
|
|
res.setRegister(register); |
|
|
|
} |
|
|
|
// XXX |
|
|
|
if(wordsResult.getJSONObject("档案编号") != null) res.setFile(wordsResult.getJSONObject("档案编号").getString("words")); |
|
|
|
// JSONObject jsonFileNum = words_result.getJSONObject("档案编号"); |
|
|
|
// if (jsonFileNum != null) { |
|
|
|
// String fileNum = jsonFileNum.getString("words"); |
|
|
|
// vehicleLicense.setFileNo(fileNum); |
|
|
|
// } |
|
|
|
if(wordsResult.getJSONObject("准牵引总质量") != null) res.setTowing(wordsResult.getJSONObject("准牵引总质量").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("备注") != null) res.setNote(wordsResult.getJSONObject("备注").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("证芯编号") != null) res.setCode(wordsResult.getJSONObject("证芯编号").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("燃油类型") != null) res.setFuel(wordsResult.getJSONObject("燃油类型").getString("words")); |
|
|
|
|
|
|
|
res.setCode("0"); |
|
|
|
res.setPictureSize("0"); |
|
|
|
res.setRespCode("0000"); |
|
|
|
res.setRespMessage("ocr识别成功"); |
|
|
|
res.setStatusDesc("成功"); |
|
|
@@ -355,6 +350,7 @@ public class BaiduOcrUtil { |
|
|
|
if(wordsResult.getJSONObject("地址") != null) res.setAdress(wordsResult.getJSONObject("地址").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("登记机关") != null) res.setRegAuthority(wordsResult.getJSONObject("登记机关").getString("words")); |
|
|
|
if(wordsResult.getJSONObject("类型") != null) res.setType(wordsResult.getJSONObject("类型").getString("words")); |
|
|
|
|
|
|
|
res.setCode("0"); |
|
|
|
res.setRespCode("0000"); |
|
|
|
res.setRespMessage("ocr识别成功"); |
|
|
@@ -458,7 +454,7 @@ public class BaiduOcrUtil { |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
String imagePath = "C:\\Users\\32258\\Desktop\\gy\\ocr测试图片\\身份证.jpg"; // 图片文件的路径 |
|
|
|
String imagePath = "C:\\Users\\32258\\Desktop\\gy\\ocr测试图片\\行驶证.jpg"; // 图片文件的路径 |
|
|
|
try { |
|
|
|
// 读取图片文件 |
|
|
|
File file = new File(imagePath); |
|
|
@@ -480,7 +476,7 @@ public class BaiduOcrUtil { |
|
|
|
// String s = "http://192.168.100.63:8123/rest/2.0/ocr/v1/idcard?access_token=\"24.5ef02634e73ed6f7d9d161f706b6c4ea.2592000.1729009172.282335-26580024\""; |
|
|
|
// System.out.println(s.replaceAll("\"","")); |
|
|
|
BaiduOcrUtil baiduOcrUtil = new BaiduOcrUtil(); |
|
|
|
baiduOcrUtil.ocrIdCardRecognize(base64Image,"front"); |
|
|
|
baiduOcrUtil.ocrVehicleLicenseRecognize(base64Image,"front"); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |