-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from regulaforensics/sp-19185-portrait-compar…
…ison SP-19185 portrait comparison
- Loading branch information
Showing
22 changed files
with
476 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"packageName": "Regula.DocumentReader.WebClient", | ||
"typeMappings": { | ||
"boolean": "bool?" | ||
}, | ||
"nullableReferenceTypes": true, | ||
"optionalAssemblyInfo": true, | ||
"isRestSharp_106_10_1_above" :true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/Regula.DocumentReader.NetCoreExamplePortraitComparison/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using Regula.DocumentReader.WebClient.Api; | ||
using Regula.DocumentReader.WebClient.Model; | ||
using Regula.DocumentReader.WebClient.Model.Ext; | ||
using Regula.DocumentReader.WebClient.Model.Ext.Autheticity; | ||
|
||
namespace Regula.DocumentReader.NetCoreExamplePortraitComparison | ||
{ | ||
internal static class Program | ||
{ | ||
private const string API_BASE_PATH = "API_BASE_PATH"; | ||
private const string TEST_LICENSE = "TEST_LICENSE"; | ||
private const string LICENSE_FILE_NAME = "regula.license"; | ||
|
||
public static void Main() | ||
{ | ||
// ************************************************************************************************ | ||
// * This example demonstrates how to perform a full document processing with portrait comparison * | ||
// * using FaceAPI Web Server * | ||
// ************************************************************************************************ | ||
|
||
var apiBaseUrl = Environment.GetEnvironmentVariable(API_BASE_PATH) ?? "https://api.regulaforensics.com"; | ||
|
||
var licenseFromEnv = | ||
Environment.GetEnvironmentVariable(TEST_LICENSE); // optional, used here only for smoke test purposes | ||
var licenseFromFile = File.Exists(LICENSE_FILE_NAME) | ||
? File.ReadAllBytes(LICENSE_FILE_NAME) | ||
: null; | ||
|
||
var whitePage0 = File.ReadAllBytes("WHITE.jpg"); | ||
|
||
var requestParams = new RecognitionParams() | ||
.WithScenario(Scenario.FULL_PROCESS) | ||
.WithResultTypeOutput(new List<int> | ||
{ | ||
// actual results | ||
Result.STATUS, Result.AUTHENTICITY, Result.TEXT, Result.IMAGES, | ||
Result.DOCUMENT_TYPE, Result.DOCUMENT_TYPE_CANDIDATES, Result.DOCUMENT_POSITION, | ||
// Portrait comparison | ||
Result.PORTRAIT_COMPARISON | ||
}) | ||
.WithFaceApi("https://faceapi.regulaforensics.com") | ||
.WithAuthParam(new AuthParams(checkPhotoComparison: true)) | ||
.WithLog(false); | ||
|
||
|
||
var api = licenseFromEnv != null | ||
? new DocumentReaderApi(apiBaseUrl).WithLicense(licenseFromEnv) | ||
: new DocumentReaderApi(apiBaseUrl).WithLicense(licenseFromFile); | ||
|
||
var request = new RecognitionRequest(requestParams, new List<ProcessRequestImage> | ||
{ | ||
new ProcessRequestImage(new ImageDataExt(whitePage0), Light.WHITE), | ||
}); | ||
request.ExtPortrait = Convert.ToBase64String(File.ReadAllBytes("portrait.png")); | ||
|
||
var response = api.Process(request); | ||
// var authHeaders = new Dictionary<string, string>() | ||
// { | ||
// { "Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes("USER:PASSWORD"))}" } | ||
// }; | ||
var comparison = response.PortraitComparison(); | ||
|
||
Console.WriteLine(response.Log()); | ||
|
||
// overall status results | ||
var status = response.Status(); | ||
var docOverallStatus = status.OverallStatus == CheckResult.OK ? "valid" : "not valid"; | ||
var docOpticalTextStatus = status.DetailsOptical.Text == CheckResult.OK ? "valid" : "not valid"; | ||
|
||
// text results | ||
var docNumberField = response.Text().GetField(TextFieldType.DOCUMENT_NUMBER); | ||
var docNumberVisual = docNumberField.GetValue(Source.VISUAL); | ||
var docNumberMrz = docNumberField.GetValue(Source.MRZ); | ||
var docNumberVisualValidity = docNumberField.SourceValidity(Source.VISUAL); | ||
var docNumberMrzValidity = docNumberField.SourceValidity(Source.MRZ); | ||
var docNumberMrzVisualMatching = docNumberField.CrossSourceComparison(Source.MRZ, Source.VISUAL); | ||
|
||
var docType = response.DocumentType(); | ||
|
||
|
||
var docAuthenticity = response.Authenticity(); | ||
var docIRB900 = docAuthenticity.IrB900Checks(); | ||
var info = api.Ping(); | ||
// var info = api.Ping(headers: authHeaders); | ||
|
||
Console.WriteLine("-----------------------------------------------------------------"); | ||
Console.WriteLine($" API Version: {info.Version}"); | ||
Console.WriteLine("-----------------------------------------------------------------"); | ||
Console.WriteLine($" Document Overall Status: {docOverallStatus}"); | ||
Console.WriteLine($" Document Optical Text Status: {docOpticalTextStatus}"); | ||
Console.WriteLine($" Document Number Visual: {docNumberVisual}"); | ||
Console.WriteLine($" Document Number MRZ: {docNumberMrz}", docNumberMrz); | ||
Console.WriteLine($" Document Name: {docType.DocumentName}"); | ||
Console.WriteLine($"Validity Of Document Number Visual: {docNumberVisualValidity}"); | ||
Console.WriteLine($" Validity Of Document Number MRZ: {docNumberMrzValidity}"); | ||
Console.WriteLine($" MRZ-Visual values comparison: {docNumberMrzVisualMatching}"); | ||
Console.WriteLine($" Portrait Comparison Percents: {comparison.AuthenticityCheckList.List[0].List[0].PercentValue}"); | ||
Console.WriteLine("-----------------------------------------------------------------"); | ||
|
||
// images results | ||
var documentImage = response.Images().GetField(GraphicFieldType.DOCUMENT_FRONT).GetValue(); | ||
var portraitField = response.Images().GetField(GraphicFieldType.PORTRAIT); | ||
var portraitFromVisual = portraitField.GetValue(Source.VISUAL); | ||
|
||
File.WriteAllBytes("document-image.jpg", documentImage); | ||
File.WriteAllBytes("portrait.jpg", portraitFromVisual); | ||
|
||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...reExamplePortraitComparison/Regula.DocumentReader.NetCoreExamplePortraitComparison.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Update="portrait.png"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="WHITE.jpg"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Regula.DocumentReader.WebClient\Regula.DocumentReader.WebClient.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+252 KB
src/Regula.DocumentReader.NetCoreExamplePortraitComparison/portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.