Skip to content

Commit 5610793

Browse files
Merge remote-tracking branch 'origin/new-generator' into new-generator
2 parents 8fb5820 + 75127f8 commit 5610793

File tree

1 file changed

+84
-86
lines changed
  • example/src/main/java/com/regula/documentreader/webclient/example

1 file changed

+84
-86
lines changed

example/src/main/java/com/regula/documentreader/webclient/example/Main.java

Lines changed: 84 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -45,106 +45,104 @@ public static void main(String[] args) throws IOException, ApiException {
4545
var whitePageRequestImage = new ProcessRequestImage(whitePage0, Light.WHITE, 0);
4646

4747
var requestParams = new ProcessParams()
48-
.scenario(Scenario.FULL_PROCESS)
49-
.resultTypeOutput(
50-
Arrays.asList(
51-
// actual results
52-
Result.STATUS, 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
48+
.scenario(Scenario.FULL_PROCESS)
49+
.resultTypeOutput(
50+
Arrays.asList(
51+
// actual results
52+
Result.STATUS, 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+
)
5960
)
60-
)
61-
.alreadyCropped(true);
61+
.alreadyCropped(true);
6262

6363
RecognitionRequest request = new RecognitionRequest(requestParams, List.of(whitePageRequestImage));
6464

6565
String finalApiBaseUrl = apiBaseUrl;
6666

67-
new Thread(() -> {
68-
var api = new DocumentReaderApi(finalApiBaseUrl);
67+
var api = new DocumentReaderApi(finalApiBaseUrl);
6968

70-
// Uncomment one of the lines below if you want to transfer the license with each request
69+
// Uncomment one of the lines below if you want to transfer the license with each request
7170
// if (licenseFromEnv != null) api.setLicense(licenseFromEnv);
7271
// if (licenseFromFile != null) api.setLicense(licenseFromFile);
7372

74-
var info = api.ping();
75-
System.out.println();
76-
System.out.format(
77-
"-----------------------------------------------------------------" + "\n"
78-
+ "Web API version: " + info.getVersion() + "\n"
79-
+ "-----------------------------------------------------------------");
80-
RecognitionResponse response = api.process(request);
81-
var requestJson = request.json();
82-
var responseJson = response.json();
83-
84-
// to send raw request(ex encrypted one) with overriding processing params here use next api
85-
// RecognitionResponse response = api.process(request, requestParams);
86-
87-
var status = response.status();
88-
var docOverallStatus = status.getOverallStatus() == CheckResult.OK ? "valid" : "not valid";
89-
var docOpticalTextStatus = status.getDetailsOptical().getText();
90-
91-
var docType = response.documentType() == null ? "Unknown" : response.documentType().getDocumentName();
92-
93-
var docNumberField = response.text().getField(DOCUMENT_NUMBER);
94-
var docNumberFieldByName = response.text().getField("Document Number");
95-
96-
var docNumberVisual = docNumberField.getValue(Source.VISUAL);
97-
var docNumberMrz = docNumberField.getValue(Source.MRZ);
98-
var docNumberVisualValidity = docNumberField.sourceValidity(Source.VISUAL);
99-
var docNumberMrzValidity = docNumberField.sourceValidity(Source.MRZ);
100-
var docNumberMrzVisualMatching = docNumberField.crossSourceComparison(Source.MRZ, Source.VISUAL);
101-
102-
System.out.println();
103-
System.out.format("-----------------------------------------------------------------" + "\n"
104-
+ "Document Type: " + docType + "\n"
105-
+ "Document Overall Status: " + docOverallStatus + "\n"
106-
+ "Document Number Visual: " + docNumberVisual + "\n"
107-
+ "Document Number MRZ: " + docNumberMrz + "\n"
108-
+ "Validity Of Document Number Visual: " + docNumberVisualValidity + "\n"
109-
+ "Validity Of Document Number MRZ: " + docNumberMrzValidity + "\n"
110-
+ "MRZ-Visual values comparison: " + docNumberMrzVisualMatching + "\n"
111-
+ "-----------------------------------------------------------------");
112-
System.out.println();
113-
114-
if (response.text() != null) {
115-
for (TextField field : response.text().getFieldList()) {
116-
System.out.format(
117-
"Field: " + " "
118-
+ field.getFieldName() + " "
119-
+ "Value: " + " "
120-
+ field.getValueList().get(0).getValue() + " "
121-
+ "Source: " + field.getValueList().get(0).getSource()
122-
+ "\n");
123-
}
124-
System.out.format("---------------------------------------------------------------");
125-
} else {
126-
System.out.format(" NO TEXT DATA");
127-
System.out.format("---------------------------------------------------------------");
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+
System.out.println();
102+
System.out.format("-----------------------------------------------------------------" + "\n"
103+
+ "Document Type: " + docType + "\n"
104+
+ "Document Overall Status: " + docOverallStatus + "\n"
105+
+ "Document Number Visual: " + docNumberVisual + "\n"
106+
+ "Document Number MRZ: " + docNumberMrz + "\n"
107+
+ "Validity Of Document Number Visual: " + docNumberVisualValidity + "\n"
108+
+ "Validity Of Document Number MRZ: " + docNumberMrzValidity + "\n"
109+
+ "MRZ-Visual values comparison: " + docNumberMrzVisualMatching + "\n"
110+
+ "-----------------------------------------------------------------");
111+
System.out.println();
112+
113+
if (response.text() != null) {
114+
for (TextField field : response.text().getFieldList()) {
115+
System.out.format(
116+
"Field: " + " "
117+
+ field.getFieldName() + " "
118+
+ "Value: " + " "
119+
+ field.getValueList().get(0).getValue() + " "
120+
+ "Source: " + field.getValueList().get(0).getSource()
121+
+ "\n");
128122
}
123+
System.out.format("---------------------------------------------------------------");
124+
} else {
125+
System.out.format(" NO TEXT DATA");
126+
System.out.format("---------------------------------------------------------------");
127+
}
129128

130-
var documentImage = response.images().getField(GraphicFieldType.DOCUMENT_FRONT).getValue();
131-
var portraitField = response.images().getField(GraphicFieldType.PORTRAIT);
132-
var portraitFromVisual = portraitField.getValue(Source.VISUAL);
129+
var documentImage = response.images().getField(GraphicFieldType.DOCUMENT_FRONT).getValue();
130+
var portraitField = response.images().getField(GraphicFieldType.PORTRAIT);
131+
var portraitFromVisual = portraitField.getValue(Source.VISUAL);
133132

134-
try {
135-
saveFile("document-image.jpg", documentImage);
136-
} catch (IOException e) {
137-
throw new RuntimeException(e);
138-
}
139-
try {
140-
saveFile("portrait.jpg", portraitFromVisual);
141-
} catch (IOException e) {
142-
throw new RuntimeException(e);
143-
}
133+
try {
134+
saveFile("document-image.jpg", documentImage);
135+
} catch (IOException e) {
136+
throw new RuntimeException(e);
137+
}
138+
try {
139+
saveFile("portrait.jpg", portraitFromVisual);
140+
} catch (IOException e) {
141+
throw new RuntimeException(e);
142+
}
144143

145-
// how to get low lvl individual results
146-
LexicalAnalysisResult lexResult = response.resultByType(Result.LEXICAL_ANALYSIS);
147-
}).start();
144+
// how to get low lvl individual results
145+
LexicalAnalysisResult lexResult = response.resultByType(Result.LEXICAL_ANALYSIS);
148146

149147
System.exit(0);
150148
}

0 commit comments

Comments
 (0)