|
@@ -39,9 +39,9 @@ public class OcrService {
|
|
|
MyConfig myConfig;
|
|
|
|
|
|
public OcrResult ocrIdCard(String idCardPath) throws Exception{
|
|
|
-// List<String> wordsList = ocrImage(idCardPath);
|
|
|
-// String words = wordsList.stream().map(String::valueOf).collect(Collectors.joining(""));
|
|
|
- String words = "SINGOMINGZ姓名李卓明SINGQBIEDMINZCUZ性别男民族汉SEN的NIENZ NYIEDHAUH出生1997年12月9日DIEGYOUQ住址广西北流市新圩镇西宁街245号GUNGHMINZSINHFWN HAUMAJ公民身份号码450981199712091118";
|
|
|
+ List<String> wordsList = ocrImage(idCardPath);
|
|
|
+ String words = wordsList.stream().map(String::valueOf).collect(Collectors.joining(""));
|
|
|
+ //String words = "SINGOMINGZ姓名李卓明SINGQBIEDMINZCUZ性别男民族汉SEN的NIENZ NYIEDHAUH出生1997年12月9日DIEGYOUQ住址广西北流市新圩镇西宁街245号GUNGHMINZSINHFWN HAUMAJ公民身份号码450981199712091118";
|
|
|
String name = getIdName(words);
|
|
|
String IdCard = getIdCard(words);
|
|
|
OcrResult ocrResult = new OcrResult();
|
|
@@ -49,39 +49,11 @@ public class OcrService {
|
|
|
return ocrResult;
|
|
|
}
|
|
|
|
|
|
- private String getIdCard(String words) {
|
|
|
- int idBeginIndex = StrUtil.indexOf(words, "公民身份号码", 0, false);
|
|
|
- String idCard = StrUtil.sub(words, idBeginIndex+6, idBeginIndex+24);
|
|
|
- if(!IdcardUtil.isValidCard(idCard)){
|
|
|
- idCard = "";
|
|
|
- }
|
|
|
- return idCard;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private String getIdName(String words) {
|
|
|
- int nameBeginIndex = StrUtil.indexOf(words, "姓名", 0, false);
|
|
|
- int nameEndIndex = nameBeginIndex+3;
|
|
|
- for(int i=nameBeginIndex; i<words.length(); i++){
|
|
|
- if(words.charAt(i)>='a' && words.charAt(i)<='z' || words.charAt(i)>='A' && words.charAt(i)<='Z'){
|
|
|
- nameEndIndex = i;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- String name = StrUtil.sub(words, nameBeginIndex+2, nameEndIndex);
|
|
|
- String regFormat = "[\\u4e00-\\u9fa5]{2,4}";
|
|
|
- boolean matches = Pattern.matches(regFormat, name);
|
|
|
- if(!matches){
|
|
|
- name = "";
|
|
|
- }
|
|
|
- return name;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
public OcrResult ocrIcCard(String icCardPath) throws Exception{
|
|
|
- //List<String> wordsList = ocrImage(icCardPath);
|
|
|
- //String words = sortIcWords(wordsList);
|
|
|
- String words = "0024745姓名:黄恩华性别:男身份证号码:450681197409172411本证有效期自2021年01月01日起至2022年12月31日止发证单位:东兴市商务和口岸管理局";
|
|
|
+ List<String> wordsList = ocrImage(icCardPath);
|
|
|
+ String words = sortIcWords(wordsList);
|
|
|
+ //String words = "0024745姓名:黄恩华性别:男身份证号码:450681197409172411本证有效期自2021年01月01日起至2022年12月31日止发证单位:东兴市商务和口岸管理局";
|
|
|
String icNo = getIcNo(words);
|
|
|
String name = getIcName(words);
|
|
|
String idCard = getIcIdCard(words);
|
|
@@ -198,5 +170,34 @@ public class OcrService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private String getIdCard(String words) {
|
|
|
+ int idBeginIndex = StrUtil.indexOf(words, "公民身份号码", 0, false);
|
|
|
+ String idCard = StrUtil.sub(words, idBeginIndex+6, idBeginIndex+24);
|
|
|
+ if(!IdcardUtil.isValidCard(idCard)){
|
|
|
+ idCard = "";
|
|
|
+ }
|
|
|
+ return idCard;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getIdName(String words) {
|
|
|
+ int nameBeginIndex = StrUtil.indexOf(words, "姓名", 0, false);
|
|
|
+ int nameEndIndex = nameBeginIndex+3;
|
|
|
+ for(int i=nameBeginIndex; i<words.length(); i++){
|
|
|
+ if(words.charAt(i)>='a' && words.charAt(i)<='z' || words.charAt(i)>='A' && words.charAt(i)<='Z'){
|
|
|
+ nameEndIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String name = StrUtil.sub(words, nameBeginIndex+2, nameEndIndex);
|
|
|
+ String regFormat = "[\\u4e00-\\u9fa5]{2,4}";
|
|
|
+ boolean matches = Pattern.matches(regFormat, name);
|
|
|
+ if(!matches){
|
|
|
+ name = "";
|
|
|
+ }
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|