Skip to content

regulaforensics/DocumentReader-web-csharp-client

Repository files navigation

Regula.DocumentReader.WebClient - the C# library for the Regula Document Reader Web API

NuGet version (Regula.OpenApi.WebClient) OpenAPI documentation live

Documents recognition as easy as reading two bytes.

If you have any problems with or questions about this client, please contact us through a GitHub issue. You are invited to contribute new features, fixes, or updates, large or small. We are always thrilled to receive pull requests, and do our best to process them as fast as we can.

Frameworks supported

  • .NET Standard 2.0
  • .NET Framework 4.6.1 or later
  • .Net Core 2.0 or later

Install package

Regula.DocumentReader.WebClient is on the NuGet Package Index:

PM> Install-Package Regula.DocumentReader.WebClient -Version 5.2.0

Example

Performing request:

var imageBytes = File.ReadAllBytes("australia_passport.jpg");
var image = new ProcessRequestImage(new ImageData(imageBytes), Light.WHITE);

var requestParams = new RecognitionParams()
    .WithScenario(Scenario.FULL_PROCESS)
    .WithResultTypeOutput(new List<int> { Result.STATUS, Result.TEXT, Result.IMAGES, Result.DOCUMENT_TYPE });
var request = new RecognitionRequest(requestParams, image);

var api = licenseFromEnv != null 
    ? new DocumentReaderApi(apiBaseUrl).WithLicense(licenseFromEnv)
    : new DocumentReaderApi(apiBaseUrl).WithLicense(licenseFromFile);

var response = api.Process(request);

Parsing results:

var response = api.Process(request);

// status examples
var status = response.Status();
string docOverallStatus = status.OverallStatus == CheckResult.OK ? "valid" : "not valid";
string docOpticalTextStatus = status.DetailsOptical.Text == CheckResult.OK ? "valid" : "not valid";

// text fields examples
var docNumberField = response.Text().GetField(TextFieldType.DOCUMENT_NUMBER);
string docNumberVisual = docNumberField.GetValue(Source.VISUAL);
string docNumberMrz = docNumberField.GetValue(Source.MRZ);
int docNumberVisualValidity = docNumberField.SourceValidity(Source.VISUAL);
int docNumberMrzValidity = docNumberField.SourceValidity(Source.MRZ);
int docNumberMrzVisualMatching = docNumberField.CrossSourceComparison(Source.MRZ, Source.VISUAL);

// images fields examples
var documentImage = response.Images().GetField(GraphicFieldType.DOCUMENT_FRONT).GetValue();
var portraitField = response.Images().GetField(GraphicFieldType.PORTRAIT);
var portraitFromVisual = portraitField.GetValue(Source.VISUAL);

You can find this sample in the example.