Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-19185 portrait comparison #141

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/workflows/run-smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
- run: dotnet build src/Regula.DocumentReader.NetCoreExample -c Release
- working-directory: src/Regula.DocumentReader.NetCoreExample/bin/Release/net6.0/
dotnet-version: |
8.0.x
- name: Build
run: |
dotnet build src/Regula.DocumentReader.NetCoreExample -c Release
dotnet build src/Regula.DocumentReader.NetCoreExamplePortraitComparison -c Release

- name: Run basic sample
run: ./Regula.DocumentReader.NetCoreExample
env:
API_BASE_PATH: "https://nightly-api.regulaforensics.com"
TEST_LICENSE: ${{secrets.TEST_LICENSE}}
working-directory: src/Regula.DocumentReader.NetCoreExample/bin/Release/net8.0/

- name: Run Portrait comparison
run: ./Regula.DocumentReader.NetCoreExamplePortraitComparison
working-directory: src/Regula.DocumentReader.NetCoreExamplePortraitComparison/bin/Release/net8.0/
2 changes: 1 addition & 1 deletion .github/workflows/sast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
# List of paths (space separated) to ignore
# Supports PATTERNS
# EXCLUDE_PATHS: 'foo bar/baz file.txt dir/*.yml'
EXCLUDE_PATHS: '*docker-compose.y*ml'
EXCLUDE_PATHS: '*docker-compose.y*ml, src/Regula.DocumentReader.WebClient/Client/ApiClient.cs'
# List of rules (space separated) to ignore
# EXCLUDE_RULES: 'generic.secrets.security.detected-aws-account-id.detected-aws-account-id'
# See https://github.com/semgrep/semgrep-rules for rules registry
Expand Down
6 changes: 1 addition & 5 deletions .openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ src/Regula.DocumentReader.WebClient/Properties/**
src/Regula.DocumentReader.WebClient/Model/ContainerList.cs
src/Regula.DocumentReader.WebClient/Model/AuthenticityCheckResult.cs
**/*AllOf.cs

# classes, modified after generation
src/Regula.DocumentReader.WebClient/Model/ResultItem.cs
src/Regula.DocumentReader.WebClient/Model/AuthenticityCheckResultItem.cs
src/Regula.DocumentReader.WebClient/Model/AuthParams.cs
src/Regula.DocumentReader.WebClient/Model/ResultItem.cs
6 changes: 6 additions & 0 deletions Regula.DocumentReader.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Regula.DocumentReader.NetCo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Regula.DocumentReader.NetCoreExampleEncryptedRcl", "src\Regula.DocumentReader.NetCoreExampleEncryptedRcl\Regula.DocumentReader.NetCoreExampleEncryptedRcl.csproj", "{1A61741A-298F-4722-8626-00DF9787C683}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Regula.DocumentReader.NetCoreExamplePortraitComparison", "src\Regula.DocumentReader.NetCoreExamplePortraitComparison\Regula.DocumentReader.NetCoreExamplePortraitComparison.csproj", "{DC05980A-7291-4BD2-B9E6-AA0EAADD6198}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -26,6 +28,10 @@ Global
{1A61741A-298F-4722-8626-00DF9787C683}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A61741A-298F-4722-8626-00DF9787C683}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A61741A-298F-4722-8626-00DF9787C683}.Release|Any CPU.Build.0 = Release|Any CPU
{DC05980A-7291-4BD2-B9E6-AA0EAADD6198}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC05980A-7291-4BD2-B9E6-AA0EAADD6198}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC05980A-7291-4BD2-B9E6-AA0EAADD6198}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC05980A-7291-4BD2-B9E6-AA0EAADD6198}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions csharp-generator-config.json
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
}
2 changes: 1 addition & 1 deletion src/Regula.DocumentReader.NetCoreExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void Main()
var uvPage0 = File.ReadAllBytes("UV.jpg");

var requestParams = new RecognitionParams()
.WithScenario(Scenario.FULL_AUTH)
.WithScenario(Scenario.FULL_PROCESS)
.WithResultTypeOutput(new List<int>
{
// actual results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Main()
?? "https://api.regulaforensics.com";

var requestParams = new RecognitionParams()
.WithScenario(Scenario.FULL_AUTH)
.WithScenario(Scenario.FULL_PROCESS)
.WithResultTypeOutput(new List<int>
{
// actual results
Expand All @@ -36,7 +36,7 @@ public static void Main()
var licenseData = Convert.FromBase64String(licenseString);
var encryptedRclData = Convert.FromBase64String(encryptedRclString);

var request = new RecognitionRequest(requestParams, new ContainerList(new List<ResultItem>()
var request = new RecognitionRequest(requestParams, new ContainerList(list: new List<ResultItem>()
{
new LicenseResult(licenseData, licenseData.Length, 0, 0, 0, Result.LICENSE),
new EncryptedRCLResult(encryptedRclData, encryptedRclData.Length, 0, 0, 0, Result.ENCRYPTED_RCL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<Product>DocumentReader WebClient Example EncryptedRcl</Product>
<PackageId>Regula.DocumentReader.NetCoreExampleEncryptedRcl</PackageId>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Regula.DocumentReader.WebClient\Regula.DocumentReader.WebClient.csproj" />
Expand Down
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);

}
}
}
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Documents recognition as easy as reading two bytes. # Clients: * [JavaScript](https://github.com/regulaforensics/DocumentReader-web-js-client) client for the browser and node.js based on axios * [Java](https://github.com/regulaforensics/DocumentReader-web-java-client) client compatible with jvm and android * [Python](https://github.com/regulaforensics/DocumentReader-web-python-client) 3.5+ client * [C#](https://github.com/regulaforensics/DocumentReader-web-csharp-client) client for .NET & .NET Core
*
* The version of the OpenAPI document: 5.5.0
* The version of the OpenAPI document: 7.2.0
*
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
Expand All @@ -30,21 +30,11 @@ namespace Regula.DocumentReader.WebClient.Model
/// </summary>
[DataContract]
[JsonConverter(typeof(JsonSubtypes), "type")]
[JsonSubtypes.KnownSubType(typeof(SecurityFeatureResult), AuthenticityResultType.UV_LUMINESCENCE)]
[JsonSubtypes.KnownSubType(typeof(SecurityFeatureResult), AuthenticityResultType.IR_B900)]
[JsonSubtypes.KnownSubType(typeof(IdentResult), AuthenticityResultType.IMAGE_PATTERN)]
[JsonSubtypes.KnownSubType(typeof(SecurityFeatureResult), AuthenticityResultType.AXIAL_PROTECTION)]
[JsonSubtypes.KnownSubType(typeof(FiberResult), AuthenticityResultType.UV_FIBERS)]
[JsonSubtypes.KnownSubType(typeof(IdentResult), AuthenticityResultType.IR_VISIBILITY)]
[JsonSubtypes.KnownSubType(typeof(OCRSecurityTextResult), AuthenticityResultType.OCR_SECURITY_TEXT)]
[JsonSubtypes.KnownSubType(typeof(PhotoIdentResult), AuthenticityResultType.IPI)]
[JsonSubtypes.KnownSubType(typeof(SecurityFeatureResult), AuthenticityResultType.PHOTO_EMBED_TYPE)]
[JsonSubtypes.KnownSubType(typeof(SecurityFeatureResult), AuthenticityResultType.HOLOGRAMS)]
[JsonSubtypes.KnownSubType(typeof(SecurityFeatureResult), AuthenticityResultType.PHOTO_AREA)]
[JsonSubtypes.KnownSubType(typeof(IdentResult), AuthenticityResultType.PORTRAIT_COMPARISON)]
[JsonSubtypes.KnownSubType(typeof(SecurityFeatureResult), AuthenticityResultType.BARCODE_FORMAT_CHECK)]
[JsonSubtypes.KnownSubType(typeof(IdentResult), AuthenticityResultType.KINEGRAM)]
[JsonSubtypes.KnownSubType(typeof(IdentResult), AuthenticityResultType.LETTER_SCREEN)]
[JsonSubtypes.KnownSubType(typeof(PhotoIdentResult), "PhotoIdentResult")]
[JsonSubtypes.KnownSubType(typeof(OCRSecurityTextResult), "OCRSecurityTextResult")]
[JsonSubtypes.KnownSubType(typeof(SecurityFeatureResult), "SecurityFeatureResult")]
[JsonSubtypes.KnownSubType(typeof(IdentResult), "IdentResult")]
[JsonSubtypes.KnownSubType(typeof(FiberResult), "FiberResult")]
public partial class AuthenticityCheckResultItem : IEquatable<AuthenticityCheckResultItem>, IValidatableObject
{
/// <summary>
Expand All @@ -55,11 +45,11 @@ protected AuthenticityCheckResultItem() { }
/// <summary>
/// Initializes a new instance of the <see cref="AuthenticityCheckResultItem" /> class.
/// </summary>
/// <param name="type">Same as authenticity result type, but used for safe parsing of not-described values. See authenticity result type (required) (default to 0).</param>
/// <param name="type">Same as authenticity result type, but used for safe parsing of not-described values: https://docs.regulaforensics.com/develop/doc-reader-sdk/web-service/development/enums/authenticity-result-type/ (required) (default to 0).</param>
/// <param name="elementResult">elementResult.</param>
/// <param name="elementDiagnose">elementDiagnose.</param>
/// <param name="percentValue">percentValue.</param>
public AuthenticityCheckResultItem(int type = 0, int elementResult = default(int), int elementDiagnose = default(int), int percentValue = 0)
public AuthenticityCheckResultItem(int type = 0, int elementResult = default(int), int elementDiagnose = default(int), int percentValue = default(int))
{
// to ensure "type" is required (not null)
if (type == null)
Expand All @@ -70,25 +60,19 @@ protected AuthenticityCheckResultItem() { }
{
this.Type = type;
}
this.PercentValue = percentValue;

this.ElementResult = elementResult;
this.ElementDiagnose = elementDiagnose;
this.PercentValue = percentValue;
}

/// <summary>
/// Same as authenticity result type, but used for safe parsing of not-described values. See authenticity result type
/// Same as authenticity result type, but used for safe parsing of not-described values: https://docs.regulaforensics.com/develop/doc-reader-sdk/web-service/development/enums/authenticity-result-type/
/// </summary>
/// <value>Same as authenticity result type, but used for safe parsing of not-described values. See authenticity result type</value>
/// <value>Same as authenticity result type, but used for safe parsing of not-described values: https://docs.regulaforensics.com/develop/doc-reader-sdk/web-service/development/enums/authenticity-result-type/</value>
[DataMember(Name="Type", EmitDefaultValue=true)]
public int Type { get; set; }

/// <summary>
/// Gets or Sets PercentValue
/// </summary>
[DataMember(Name="PercentValue", EmitDefaultValue=false)]
public int PercentValue { get; set; }


/// <summary>
/// Gets or Sets ElementResult
/// </summary>
Expand All @@ -101,6 +85,12 @@ protected AuthenticityCheckResultItem() { }
[DataMember(Name="ElementDiagnose", EmitDefaultValue=false)]
public int ElementDiagnose { get; set; }

/// <summary>
/// Gets or Sets PercentValue
/// </summary>
[DataMember(Name="PercentValue", EmitDefaultValue=false)]
public int PercentValue { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand All @@ -112,6 +102,7 @@ public override string ToString()
sb.Append(" Type: ").Append(Type).Append("\n");
sb.Append(" ElementResult: ").Append(ElementResult).Append("\n");
sb.Append(" ElementDiagnose: ").Append(ElementDiagnose).Append("\n");
sb.Append(" PercentValue: ").Append(PercentValue).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand All @@ -122,7 +113,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}

/// <summary>
Expand Down Expand Up @@ -160,6 +151,11 @@ public bool Equals(AuthenticityCheckResultItem input)
this.ElementDiagnose == input.ElementDiagnose ||
(this.ElementDiagnose != null &&
this.ElementDiagnose.Equals(input.ElementDiagnose))
) &&
(
this.PercentValue == input.PercentValue ||
(this.PercentValue != null &&
this.PercentValue.Equals(input.PercentValue))
);
}

Expand All @@ -178,6 +174,8 @@ public override int GetHashCode()
hashCode = hashCode * 59 + this.ElementResult.GetHashCode();
if (this.ElementDiagnose != null)
hashCode = hashCode * 59 + this.ElementDiagnose.GetHashCode();
if (this.PercentValue != null)
hashCode = hashCode * 59 + this.PercentValue.GetHashCode();
return hashCode;
}
}
Expand Down
Loading
Loading