8
8
9
9
namespace Regula . DocumentReader . NetCoreExample
10
10
{
11
- internal static class Program
12
- {
13
- private const string API_BASE_PATH = "API_BASE_PATH" ;
14
- private const string TEST_LICENSE = "TEST_LICENSE" ;
15
- private const string LICENSE_FILE_NAME = "regula.license" ;
16
-
17
- public static void Main ( )
18
- {
19
- var apiBaseUrl = Environment . GetEnvironmentVariable ( API_BASE_PATH ) ?? "https://api.regulaforensics.com" ;
20
-
21
- var licenseFromEnv =
22
- Environment . GetEnvironmentVariable ( TEST_LICENSE ) ; // optional, used here only for smoke test purposes
23
- var licenseFromFile = File . Exists ( LICENSE_FILE_NAME )
24
- ? File . ReadAllBytes ( LICENSE_FILE_NAME )
25
- : null ;
26
-
27
- var whitePage0 = File . ReadAllBytes ( "WHITE.jpg" ) ;
28
- var irPage0 = File . ReadAllBytes ( "IR.jpg" ) ;
29
- var uvPage0 = File . ReadAllBytes ( "UV.jpg" ) ;
30
-
31
- var requestParams = new RecognitionParams ( )
32
- . WithScenario ( Scenario . FULL_AUTH )
33
- . WithResultTypeOutput ( new List < int >
34
- {
35
- // actual results
36
- Result . STATUS , Result . AUTHENTICITY , Result . TEXT , Result . IMAGES ,
37
- Result . DOCUMENT_TYPE , Result . DOCUMENT_TYPE_CANDIDATES , Result . DOCUMENT_POSITION ,
38
- // legacy results
39
- Result . MRZ_TEXT , Result . VISUAL_TEXT , Result . BARCODE_TEXT , Result . RFID_TEXT ,
40
- Result . VISUAL_GRAPHICS , Result . BARCODE_GRAPHICS , Result . RFID_GRAPHICS ,
41
- Result . LEXICAL_ANALYSIS , Result . IMAGE_QUALITY
42
- } ) ;
43
-
44
- var request = new RecognitionRequest ( requestParams , new List < ProcessRequestImage >
45
- {
46
- new ProcessRequestImage ( new ImageDataExt ( whitePage0 ) , Light . WHITE ) ,
47
- new ProcessRequestImage ( new ImageDataExt ( irPage0 ) , Light . IR ) ,
48
- new ProcessRequestImage ( new ImageDataExt ( uvPage0 ) , Light . UV )
49
- } ) ;
50
- var api = licenseFromEnv != null
51
- ? new DocumentReaderApi ( apiBaseUrl ) . WithLicense ( licenseFromEnv )
52
- : new DocumentReaderApi ( apiBaseUrl ) . WithLicense ( licenseFromFile ) ;
53
-
54
- var response = api . Process ( request ) ;
11
+ internal static class Program
12
+ {
13
+ private const string API_BASE_PATH = "API_BASE_PATH" ;
14
+ private const string TEST_LICENSE = "TEST_LICENSE" ;
15
+ private const string LICENSE_FILE_NAME = "regula.license" ;
16
+
17
+ public static void Main ( )
18
+ {
19
+ var apiBaseUrl = Environment . GetEnvironmentVariable ( API_BASE_PATH ) ?? "https://api.regulaforensics.com" ;
20
+
21
+ var licenseFromEnv =
22
+ Environment . GetEnvironmentVariable ( TEST_LICENSE ) ; // optional, used here only for smoke test purposes
23
+ var licenseFromFile = File . Exists ( LICENSE_FILE_NAME )
24
+ ? File . ReadAllBytes ( LICENSE_FILE_NAME )
25
+ : null ;
26
+
27
+ var whitePage0 = File . ReadAllBytes ( "WHITE.jpg" ) ;
28
+ var irPage0 = File . ReadAllBytes ( "IR.jpg" ) ;
29
+ var uvPage0 = File . ReadAllBytes ( "UV.jpg" ) ;
30
+
31
+ var requestParams = new RecognitionParams ( )
32
+ . WithScenario ( Scenario . FULL_AUTH )
33
+ . WithResultTypeOutput ( new List < int >
34
+ {
35
+ // actual results
36
+ Result . STATUS , Result . AUTHENTICITY , Result . TEXT , Result . IMAGES ,
37
+ Result . DOCUMENT_TYPE , Result . DOCUMENT_TYPE_CANDIDATES , Result . DOCUMENT_POSITION ,
38
+ // legacy results
39
+ Result . MRZ_TEXT , Result . VISUAL_TEXT , Result . BARCODE_TEXT , Result . RFID_TEXT ,
40
+ Result . VISUAL_GRAPHICS , Result . BARCODE_GRAPHICS , Result . RFID_GRAPHICS ,
41
+ Result . LEXICAL_ANALYSIS , Result . IMAGE_QUALITY
42
+ } )
43
+ . WithLog ( false ) ;
44
+
45
+ var request = new RecognitionRequest ( requestParams , new List < ProcessRequestImage >
46
+ {
47
+ new ProcessRequestImage ( new ImageDataExt ( whitePage0 ) , Light . WHITE ) ,
48
+ new ProcessRequestImage ( new ImageDataExt ( irPage0 ) , Light . IR ) ,
49
+ new ProcessRequestImage ( new ImageDataExt ( uvPage0 ) , Light . UV )
50
+ } ) ;
51
+ var api = licenseFromEnv != null
52
+ ? new DocumentReaderApi ( apiBaseUrl ) . WithLicense ( licenseFromEnv )
53
+ : new DocumentReaderApi ( apiBaseUrl ) . WithLicense ( licenseFromFile ) ;
54
+
55
+ var response = api . Process ( request ) ;
56
+
57
+ Console . WriteLine ( response . Log ( ) ) ;
55
58
56
59
var requestJson = request . Json ;
57
- var responseJson = response . Json ;
58
-
59
- // overall status results
60
- var status = response . Status ( ) ;
61
- var docOverallStatus = status . OverallStatus == CheckResult . OK ? "valid" : "not valid" ;
62
- var docOpticalTextStatus = status . DetailsOptical . Text == CheckResult . OK ? "valid" : "not valid" ;
63
-
64
- // text results
65
- var docNumberField = response . Text ( ) . GetField ( TextFieldType . DOCUMENT_NUMBER ) ;
66
- var docNumberVisual = docNumberField . GetValue ( Source . VISUAL ) ;
67
- var docNumberMrz = docNumberField . GetValue ( Source . MRZ ) ;
68
- var docNumberVisualValidity = docNumberField . SourceValidity ( Source . VISUAL ) ;
69
- var docNumberMrzValidity = docNumberField . SourceValidity ( Source . MRZ ) ;
70
- var docNumberMrzVisualMatching = docNumberField . CrossSourceComparison ( Source . MRZ , Source . VISUAL ) ;
71
-
72
- var docType = response . DocumentType ( ) ;
73
-
74
-
75
- var docAuthenticity = response . Authenticity ( ) ;
76
- var docIRB900 = docAuthenticity . IrB900Checks ( ) ;
77
- var docIRB900Blank = docIRB900 ? . ChecksByElement ( SecurityFeatureType . BLANK ) ;
78
-
79
- var docImagePattern = docAuthenticity . ImagePatternChecks ( ) ;
80
- var docImagePatternBlank = docImagePattern ? . ChecksByElement ( SecurityFeatureType . BLANK ) ;
81
-
82
- var docImageQuality = response . ImageQualityChecks ( ) ;
83
-
84
- var info = api . Ping ( ) ;
85
- Console . WriteLine ( "-----------------------------------------------------------------" ) ;
86
- Console . WriteLine ( $ " API Version: { info . Version } ") ;
87
- Console . WriteLine ( "-----------------------------------------------------------------" ) ;
88
- Console . WriteLine ( $ " Document Overall Status: { docOverallStatus } ") ;
89
- Console . WriteLine ( $ " Document Optical Text Status: { docOpticalTextStatus } ") ;
90
- Console . WriteLine ( $ " Document Number Visual: { docNumberVisual } ") ;
91
- Console . WriteLine ( $ " Document Number MRZ: { docNumberMrz } ", docNumberMrz ) ;
92
- Console . WriteLine ( $ " Document Name: { docType . DocumentName } ") ;
93
- Console . WriteLine ( $ "Validity Of Document Number Visual: { docNumberVisualValidity } ") ;
94
- Console . WriteLine ( $ " Validity Of Document Number MRZ: { docNumberMrzValidity } ") ;
95
- Console . WriteLine ( $ " MRZ-Visual values comparison: { docNumberMrzVisualMatching } ") ;
96
- Console . WriteLine ( "-----------------------------------------------------------------" ) ;
97
-
98
- // images results
99
- var documentImage = response . Images ( ) . GetField ( GraphicFieldType . DOCUMENT_FRONT ) . GetValue ( ) ;
100
- var portraitField = response . Images ( ) . GetField ( GraphicFieldType . PORTRAIT ) ;
101
- var portraitFromVisual = portraitField . GetValue ( Source . VISUAL ) ;
102
-
103
- File . WriteAllBytes ( "document-image.jpg" , documentImage ) ;
104
- File . WriteAllBytes ( "portrait.jpg" , portraitFromVisual ) ;
105
-
106
- // how to get low lvl individual results
107
- // var lexResult = response.ResultByType<LexicalAnalysisResult>(Result.LEXICAL_ANALYSIS);
108
- }
109
- }
60
+ var responseJson = response . Json ;
61
+
62
+ // overall status results
63
+ var status = response . Status ( ) ;
64
+ var docOverallStatus = status . OverallStatus == CheckResult . OK ? "valid" : "not valid" ;
65
+ var docOpticalTextStatus = status . DetailsOptical . Text == CheckResult . OK ? "valid" : "not valid" ;
66
+
67
+ // text results
68
+ var docNumberField = response . Text ( ) . GetField ( TextFieldType . DOCUMENT_NUMBER ) ;
69
+ var docNumberVisual = docNumberField . GetValue ( Source . VISUAL ) ;
70
+ var docNumberMrz = docNumberField . GetValue ( Source . MRZ ) ;
71
+ var docNumberVisualValidity = docNumberField . SourceValidity ( Source . VISUAL ) ;
72
+ var docNumberMrzValidity = docNumberField . SourceValidity ( Source . MRZ ) ;
73
+ var docNumberMrzVisualMatching = docNumberField . CrossSourceComparison ( Source . MRZ , Source . VISUAL ) ;
74
+
75
+ var docType = response . DocumentType ( ) ;
76
+
77
+
78
+ var docAuthenticity = response . Authenticity ( ) ;
79
+ var docIRB900 = docAuthenticity . IrB900Checks ( ) ;
80
+ var docIRB900Blank = docIRB900 ? . ChecksByElement ( SecurityFeatureType . BLANK ) ;
81
+
82
+ var docImagePattern = docAuthenticity . ImagePatternChecks ( ) ;
83
+ var docImagePatternBlank = docImagePattern ? . ChecksByElement ( SecurityFeatureType . BLANK ) ;
84
+
85
+ var docImageQuality = response . ImageQualityChecks ( ) ;
86
+
87
+ var info = api . Ping ( ) ;
88
+ Console . WriteLine ( "-----------------------------------------------------------------" ) ;
89
+ Console . WriteLine ( $ " API Version: { info . Version } ") ;
90
+ Console . WriteLine ( "-----------------------------------------------------------------" ) ;
91
+ Console . WriteLine ( $ " Document Overall Status: { docOverallStatus } ") ;
92
+ Console . WriteLine ( $ " Document Optical Text Status: { docOpticalTextStatus } ") ;
93
+ Console . WriteLine ( $ " Document Number Visual: { docNumberVisual } ") ;
94
+ Console . WriteLine ( $ " Document Number MRZ: { docNumberMrz } ", docNumberMrz ) ;
95
+ Console . WriteLine ( $ " Document Name: { docType . DocumentName } ") ;
96
+ Console . WriteLine ( $ "Validity Of Document Number Visual: { docNumberVisualValidity } ") ;
97
+ Console . WriteLine ( $ " Validity Of Document Number MRZ: { docNumberMrzValidity } ") ;
98
+ Console . WriteLine ( $ " MRZ-Visual values comparison: { docNumberMrzVisualMatching } ") ;
99
+ Console . WriteLine ( "-----------------------------------------------------------------" ) ;
100
+
101
+ // images results
102
+ var documentImage = response . Images ( ) . GetField ( GraphicFieldType . DOCUMENT_FRONT ) . GetValue ( ) ;
103
+ var portraitField = response . Images ( ) . GetField ( GraphicFieldType . PORTRAIT ) ;
104
+ var portraitFromVisual = portraitField . GetValue ( Source . VISUAL ) ;
105
+
106
+ File . WriteAllBytes ( "document-image.jpg" , documentImage ) ;
107
+ File . WriteAllBytes ( "portrait.jpg" , portraitFromVisual ) ;
108
+
109
+ // how to get low lvl individual results
110
+ // var lexResult = response.ResultByType<LexicalAnalysisResult>(Result.LEXICAL_ANALYSIS);
111
+ }
112
+ }
110
113
}
0 commit comments