diff options
Diffstat (limited to 'src/main/java/info/selflearner/ocr/model')
-rw-r--r-- | src/main/java/info/selflearner/ocr/model/Passport.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/main/java/info/selflearner/ocr/model/Passport.java b/src/main/java/info/selflearner/ocr/model/Passport.java new file mode 100644 index 0000000..8bd928f --- /dev/null +++ b/src/main/java/info/selflearner/ocr/model/Passport.java @@ -0,0 +1,69 @@ +package info.selflearner.ocr.model; + +import java.time.LocalDate; + +public class Passport { + public char type; + public Character subtype; + public String issuer; + public String surname; + public String givenNames; + public String number; + public String nationality; + public LocalDate dateOfBirth; + public Character sex; + public LocalDate expirationDate; + public String personalNumber; + public int[] mrzLinesConfidence; + + public Passport(char type, Character subtype, String issuer, String surname, String givenNames, String number, String nationality, LocalDate dateOfBirth, Character sex, LocalDate expirationDate, String personalNumber, int[] mrzLinesConfidence) { + this.type = type; + this.subtype = subtype; + this.issuer = issuer; + this.surname = surname; + this.givenNames = givenNames; + this.number = number; + this.nationality = nationality; + this.dateOfBirth = dateOfBirth; + this.sex = sex; + this.expirationDate = expirationDate; + this.personalNumber = personalNumber; + this.mrzLinesConfidence = mrzLinesConfidence; + } + + public Passport(String[] mrzLines, int[] mrzLinesConfidence) { + this.type = mrzLines[0].charAt(0); + this.subtype = mrzLines[0].charAt(1) == '<' ? null : mrzLines[0].charAt(0); + this.issuer = mrzLines[0].substring(2, 5); + this.surname = mrzLines[0].substring(5, mrzLines[0].indexOf('<', 6)); + this.givenNames = mrzLines[0].substring(surname.length() + 7, mrzLines[0].indexOf('<', surname.length() + 8)); + this.number = mrzLines[1].substring(0, 9); + this.nationality = mrzLines[1].substring(10, 13); + if (Integer.parseInt("20" + mrzLines[1].substring(13, 15)) < LocalDate.now().getYear()) { + this.dateOfBirth = LocalDate.of(Integer.parseInt("20" + mrzLines[1].substring(13, 15)), Integer.parseInt(mrzLines[1].substring(15, 17)), Integer.parseInt(mrzLines[1].substring(17, 19))); + } else { + this.dateOfBirth = LocalDate.of(Integer.parseInt("19" + mrzLines[1].substring(13, 15)), Integer.parseInt(mrzLines[1].substring(15, 17)), Integer.parseInt(mrzLines[1].substring(17, 19))); + } + this.sex = mrzLines[1].charAt(20) != '<' ? mrzLines[1].charAt(20) : null; + this.expirationDate = LocalDate.of(Integer.parseInt("20" + mrzLines[1].substring(21, 23)), Integer.parseInt(mrzLines[1].substring(23, 25)), Integer.parseInt(mrzLines[1].substring(25, 27))); + this.personalNumber = mrzLines[1].substring(28, 42); + this.mrzLinesConfidence = mrzLinesConfidence; + } + + @Override + public String toString() { + return "Passport{" + + "type=" + type + + ", subtype=" + subtype + + ", issuer='" + issuer + '\'' + + ", surname='" + surname + '\'' + + ", givenNames='" + givenNames + '\'' + + ", number='" + number + '\'' + + ", nationality='" + nationality + '\'' + + ", dateOfBirth=" + dateOfBirth + + ", sex=" + sex + + ", expirationDate=" + expirationDate + + ", personalNumber='" + personalNumber + '\'' + + '}'; + } +} |