11package com .regula .documentreader .webclient .example ;
22
33
4+ import static com .regula .documentreader .webclient .model .TextFieldType .DOCUMENT_NUMBER ;
5+
46import com .regula .documentreader .webclient .ApiException ;
57import com .regula .documentreader .webclient .api .DocumentReaderApi ;
68import com .regula .documentreader .webclient .model .CheckResult ;
79import com .regula .documentreader .webclient .model .LexicalAnalysisResult ;
810import com .regula .documentreader .webclient .model .Light ;
911import com .regula .documentreader .webclient .model .Result ;
1012import com .regula .documentreader .webclient .model .Scenario ;
11- import com .regula .documentreader .webclient .model .SecurityFeatureType ;
1213import com .regula .documentreader .webclient .model .Source ;
14+ import com .regula .documentreader .webclient .model .TextField ;
1315import com .regula .documentreader .webclient .model .ext .ProcessRequestImage ;
1416import com .regula .documentreader .webclient .model .ext .RecognitionParams ;
1517import com .regula .documentreader .webclient .model .ext .RecognitionRequest ;
1618import com .regula .documentreader .webclient .model .ext .RecognitionResponse ;
1719
18- import javax .annotation .Nullable ;
1920import java .io .IOException ;
2021import java .nio .file .Files ;
2122import java .nio .file .Path ;
2223import java .util .List ;
2324
24- import static com .regula .documentreader .webclient .model .GraphicFieldType .DOCUMENT_FRONT ;
25- import static com .regula .documentreader .webclient .model .GraphicFieldType .PORTRAIT ;
26- import static com .regula .documentreader .webclient .model .TextFieldType .DOCUMENT_NUMBER ;
25+ import javax .annotation .Nullable ;
2726
2827public class Main {
2928 public static final String API_BASE_PATH = "API_BASE_PATH" ;
3029 public static final String TEST_LICENSE = "TEST_LICENSE" ;
30+
3131 public static void main (String [] args ) throws IOException , ApiException {
3232
3333 var apiBaseUrl = System .getenv (API_BASE_PATH );
@@ -37,87 +37,114 @@ public static void main(String[] args) throws IOException, ApiException {
3737 var licenseFromEnv = System .getenv (TEST_LICENSE ); // optional, used here only for smoke test purposes
3838 var licenseFromFile = readFile ("regula.license" );
3939
40+
4041 byte [] whitePage0 = readFile ("WHITE.jpg" );
41- byte [] irPage0 = readFile ("IR.jpg" );
42- byte [] uvPage0 = readFile ("UV.jpg" );
4342
4443 var whitePageRequestImage = new ProcessRequestImage (whitePage0 , Light .WHITE , 0 );
45- var irPageRequestImage = new ProcessRequestImage (irPage0 , Light .IR , 0 );
46- var uvPageRequestImage = new ProcessRequestImage (uvPage0 , Light .UV , 0 );
4744
4845 var requestParams = new RecognitionParams ()
49- .withScenario (Scenario .FULL_AUTH )
50- .withResultTypeOutput (
51- // actual results
52- Result .STATUS , Result .AUTHENTICITY , Result .TEXT , Result .IMAGES ,
53- Result .DOCUMENT_TYPE , Result .DOCUMENT_TYPE_CANDIDATES , Result .IMAGE_QUALITY ,
54- Result .DOCUMENT_POSITION ,
55- // legacy results
56- Result .MRZ_TEXT , Result .VISUAL_TEXT , Result .BARCODE_TEXT , Result .RFID_TEXT ,
57- Result .VISUAL_GRAPHICS , Result .BARCODE_GRAPHICS , Result .RFID_GRAPHICS ,
58- Result .LEXICAL_ANALYSIS
59- );
46+ .withScenario (Scenario .FULL_PROCESS )
47+ // .withResultTypeOutput(
48+ // // actual results
49+ // Result.STATUS, Result.TEXT, Result.IMAGES,
50+ // Result.DOCUMENT_TYPE, Result.DOCUMENT_TYPE_CANDIDATES, Result.IMAGE_QUALITY,
51+ // Result.DOCUMENT_POSITION,
52+ // // legacy results
53+ // Result.MRZ_TEXT, Result.VISUAL_TEXT, Result.BARCODE_TEXT, Result.RFID_TEXT,
54+ // Result.VISUAL_GRAPHICS, Result.BARCODE_GRAPHICS, Result.RFID_GRAPHICS,
55+ // Result.LEXICAL_ANALYSIS
56+ // )
57+ .withAlreadyCropped (true );
6058
6159 RecognitionRequest request = new RecognitionRequest (
62- requestParams , List .of (whitePageRequestImage , irPageRequestImage , uvPageRequestImage )
60+ requestParams , List .of (whitePageRequestImage )
6361 );
6462
65- var api = new DocumentReaderApi (apiBaseUrl );
66-
67- if (licenseFromEnv != null ) api .setLicense (licenseFromEnv );
68- if (licenseFromFile != null ) api .setLicense (licenseFromFile );
69-
70- var info = api .ping ();
71- System .out .println ("-----------------------------------------------------------------" );
72- System .out .format ("Web API version %s%n" , info .getVersion ());
73-
74- RecognitionResponse response = api .process (request );
75-
76- var requestJson = request .json ();
77- var responseJson = response .json ();
78-
79- // to send raw request(ex encrypted one) with overriding processing params here use next api
80- // RecognitionResponse response = api.process(request, requestParams);
81-
82- var status = response .status ();
83- var docOverallStatus = status .getOverallStatus () == CheckResult .OK ? "valid" : "not valid" ;
84- var docOpticalTextStatus = status .getDetailsOptical ().getText ();
85-
86- var docNumberField = response .text ().getField (DOCUMENT_NUMBER );
87- var docNumberFieldByName = response .text ().getField ("Document Number" );
88-
89- var docNumberVisual = docNumberField .getValue (Source .VISUAL );
90- var docNumberMrz = docNumberField .getValue (Source .MRZ );
91- var docNumberVisualValidity = docNumberField .sourceValidity (Source .VISUAL );
92- var docNumberMrzValidity = docNumberField .sourceValidity (Source .MRZ );
93- var docNumberMrzVisualMatching = docNumberField .crossSourceComparison (Source .MRZ , Source .VISUAL );
94-
95- var docAuthenticity = response .authenticity ();
96-
97- var docIRB900 = docAuthenticity .irB900Checks ();
98- var docIRB900Blank = docIRB900 .checksByElement (SecurityFeatureType .BLANK );
99-
100- var docImagePattern = docAuthenticity .imagePatternChecks ();
101- var docImagePatternBlank = docImagePattern .checksByElement (SecurityFeatureType .BLANK );
102-
103- System .out .println ("-----------------------------------------------------------------" );
104- System .out .format (" Document Overall Status: %s%n" , docOverallStatus );
105- System .out .format (" Document Number Visual: %s%n" , docNumberVisual );
106- System .out .format (" Document Number MRZ: %s%n" , docNumberMrz );
107- System .out .format ("Validity Of Document Number Visual: %s%n" , docNumberVisualValidity );
108- System .out .format (" Validity Of Document Number MRZ: %s%n" , docNumberMrzValidity );
109- System .out .format (" MRZ-Visual values comparison: %s%n" , docNumberMrzVisualMatching );
110- System .out .format ("-----------------------------------------------------------------" );
111-
112- var documentImage = response .images ().getField (DOCUMENT_FRONT ).getValue ();
113- var portraitField = response .images ().getField (PORTRAIT );
114- var portraitFromVisual = portraitField .getValue (Source .VISUAL );
115- saveFile ("document-image.jpg" , documentImage );
116- saveFile ("portrait.jpg" , portraitFromVisual );
11763
118- // how to get low lvl individual results
119- LexicalAnalysisResult lexResult = response .resultByType (Result .LEXICAL_ANALYSIS );
120- System .exit (0 );
64+ String finalApiBaseUrl = apiBaseUrl ;
65+
66+ new Thread (() -> {
67+ var api = new DocumentReaderApi (finalApiBaseUrl );
68+
69+ // Uncomment one of the lines below if you want to transfer the license with each request
70+ // if (licenseFromEnv != null) api.setLicense(licenseFromEnv);
71+ // if (licenseFromFile != null) api.setLicense(licenseFromFile);
72+
73+ var info = api .ping ();
74+ System .out .println ();
75+ System .out .format (
76+ "-----------------------------------------------------------------" + "\n "
77+ + "Web API version: " + info .getVersion () + "\n "
78+ + "-----------------------------------------------------------------" );
79+ RecognitionResponse response = api .process (request );
80+ var requestJson = request .json ();
81+ var responseJson = response .json ();
82+
83+ // to send raw request(ex encrypted one) with overriding processing params here use next api
84+ // RecognitionResponse response = api.process(request, requestParams);
85+
86+ var status = response .status ();
87+ var docOverallStatus = status .getOverallStatus () == CheckResult .OK ? "valid" : "not valid" ;
88+ var docOpticalTextStatus = status .getDetailsOptical ().getText ();
89+
90+ var docType = response .documentType () == null ? "Unknown" : response .documentType ().getDocumentName ();
91+
92+ var docNumberField = response .text ().getField (DOCUMENT_NUMBER );
93+ var docNumberFieldByName = response .text ().getField ("Document Number" );
94+
95+ var docNumberVisual = docNumberField .getValue (Source .VISUAL );
96+ var docNumberMrz = docNumberField .getValue (Source .MRZ );
97+ var docNumberVisualValidity = docNumberField .sourceValidity (Source .VISUAL );
98+ var docNumberMrzValidity = docNumberField .sourceValidity (Source .MRZ );
99+ var docNumberMrzVisualMatching = docNumberField .crossSourceComparison (Source .MRZ , Source .VISUAL );
100+
101+ // var docAuthenticity = response.authenticity();
102+
103+ // var docIRB900 = docAuthenticity.irB900Checks();
104+ // var docIRB900Blank = docIRB900.checksByElement(SecurityFeatureType.BLANK);
105+
106+ // var docImagePattern = docAuthenticity.imagePatternChecks();
107+ // var docImagePatternBlank = docImagePattern.checksByElement(SecurityFeatureType.BLANK);
108+
109+ System .out .format ("-----------------------------------------------------------------" + "\n "
110+ + "Document Type: " + docType + "\n "
111+ + "Document Overall Status: " + docOverallStatus + "\n "
112+ + "Document Number Visual: " + docNumberVisual + "\n "
113+ + "Document Number MRZ: " + docNumberMrz + "\n "
114+ + "Validity Of Document Number Visual: " + docNumberVisualValidity + "\n "
115+ + "Validity Of Document Number MRZ: " + docNumberMrzValidity + "\n "
116+ + "MRZ-Visual values comparison: " + docNumberMrzVisualMatching + "\n "
117+ + "-----------------------------------------------------------------" );
118+
119+ if (response .text () != null ) {
120+ for (TextField field : response .text ().getFieldList ()) {
121+ System .out .format (
122+ "Field: " + " "
123+ + field .getFieldName () + " "
124+ + "Value: " + " "
125+ + field .getValueList ().get (0 ).getValue () + " "
126+ + "Source: " + field .getValueList ().get (0 ).getSource ()
127+ + "\n " );
128+ }
129+ System .out .format ("---------------------------------------------------------------" );
130+ } else {
131+ System .out .format (" NO TEXT DATA" );
132+ System .out .format ("---------------------------------------------------------------" );
133+ }
134+
135+ // var documentImage = response.images().getField(DOCUMENT_FRONT).getValue();
136+ // var portraitField = response.images().getField(PORTRAIT);
137+ // var portraitFromVisual = portraitField.getValue(Source.VISUAL);
138+ // saveFile("document-image.jpg", documentImage);
139+ // saveFile("portrait.jpg", portraitFromVisual);
140+
141+ // how to get low lvl individual results
142+ LexicalAnalysisResult lexResult = response .resultByType (Result .LEXICAL_ANALYSIS );
143+
144+ }).start ();
145+
146+
147+ // System.exit(0);
121148 }
122149
123150 @ Nullable
0 commit comments