// Copyright (c) 2024 BioID GmbH // // Implementation of the JSON data transfer objects as defined with the BWS 3 // protobuf messages and used by the RESTful JSON API. // For a description of the elements please refer to the BWS 3 API reference // at https://developer.bioid.com/BWS/NewBws using System.Text.Json.Serialization; namespace BioID.BWS.Json { /// /// The LivenessDetection request object. See also /// /// RESTful JSON API LivenessDetection /// public class LivenessDetectionRequest { /// /// A list of one or two live images. If a second image is provided, the /// tags of these images can optionally be used for challenge-response. /// public List LiveImages { get; set; } = []; } /// /// The VideoLivenessDetection request object. See also /// /// RESTful JSON API VideoLivenessDetection /// public class VideoLivenessDetectionRequest { /// /// The binary input video data, base64 encoded. /// public string Video { get; set; } = string.Empty; } /// /// The LivenessDetection response object. See also /// /// RESTful JSON API LivenessDetection or /// /// RESTful JSON API VideoLivenessDetection. /// public class LivenessDetectionResponse { /// /// The status of the BWS job that processed the request. /// public JobStatus Status { get; set; } /// /// A list of errors that might have occurred while the request has been processed. /// public List Errors { get; set; } = []; /// /// The calculated image properties for each of the processed images. /// public List ImageProperties { get; set; } = []; /// /// The liveness decision made by BWS. /// public bool Live { get; set; } /// /// An informative liveness score (a value between 0.0 and 1.0) that /// reflects the confidence level of the live decision. /// The higher the score, the more likely the person is a live person. /// public double LivenessScore { get; set; } } /// /// The PhotoVerify request object. See also /// /// RESTful JSON API PhotoVerify /// public class PhotoVerifyRequest { /// /// A list of one or two live images. If two images are provided and /// liveness detection is not disabled, the tags of the second image /// can optionally be used for challenge-response. /// public List LiveImages { get; set; } = []; /// /// The ID-photo image. /// public required string Photo { get; set; } /// /// By default this API automatically calls into the LivenessDetection /// API with the provided. If you do not want to /// perform a liveness detection at all, simply set this flag to true. /// public bool DisableLivenessDetection { get; set; } } // see https://developer.bioid.com/bws/grpc/photoverify /// /// The PhotoVerify response object. See also /// /// RESTful JSON API PhotoVerify. /// public class PhotoVerifyResponse { /// /// The status of the BWS job that processed the request. /// public JobStatus Status { get; set; } /// /// A list of errors that might have occurred while the request has been processed. /// public List Errors { get; set; } = []; /// /// The calculated image properties for each of the provided live images /// in the given order. /// public List ImageProperties { get; set; } = []; /// /// The calculated image properties of the provided ID photo. /// public ImageProperties PhotoProperties { get; set; } = new(); /// /// The actual level of accuracy the specified photo complies with. /// We recommend not to accept verified persons with low verification levels. /// public AccuracyLevel VerificationLevel { get; set; } /// /// An informative verification score (a value between 0.0 and 1.0) that /// reflects the verification level. The higher the score, the more /// likely the live images and ID photo belong to the same person. /// If this score is exactly 0.0, it has not been calculated. /// public double VerificationScore { get; set; } /// /// The liveness decision mabe by BWS in case liveness detection is not disabled. /// public bool Live { get; set; } /// /// An informative liveness score (a value between 0.0 and 1.0) that /// reflects the confidence level of the live decision. /// The higher the score, the more likely the person is a live person. /// public double LivenessScore { get; set; } /// /// Verification accuracy levels. /// [JsonConverter(typeof(JsonStringEnumConverter))] public enum AccuracyLevel { NOT_RECOGNIZED = 0, LEVEL_1, LEVEL_2, LEVEL_3, LEVEL_4, LEVEL_5 } } /// /// Each API call returns a JobStatus /// to indicate, whether the job completed execution successfully or aborted due to any reason. /// [JsonConverter(typeof(JsonStringEnumConverter))] public enum JobStatus { SUCCEEDED = 0, FAULTED = 1, CANCELLED = 2 } /// /// An error /// reported by an API call during job processing. /// public class JobError { /// /// The error-code identifying the reported error message. /// The code is intended to uniquely identify this error. /// public string ErrorCode { get; set; } = string.Empty; /// /// The error message describing the error. /// This is a plain text message. It is in english by default. /// public string Message { get; set; } = string.Empty; } /// /// The ImageData /// object is used to send captured live images or loaded photo images to /// the BioID Web Service. /// Optionally some tags can be associated with each uploaded image. /// public class ImageData { /// /// The binary image data, base64 encoded. /// public required string Image { get; set; } /// /// Depending on the API, an image can be tagged to allow different usage scenarios. /// public List Tags { get; set; } = []; } /// /// The ImageProperties /// object contains the properties of an image as calculated by the /// BioID Web Service for a single input image of video frame. /// public class ImageProperties { /// /// Rotation of the input image. /// public int Rotated { get; set; } /// /// List of faces found in the image. /// public List Faces { get; set; } = []; /// /// An optionally calculated quality assessment score. /// public double QualityScore { get; set; } /// /// List of quality checks and other checks performed. /// public List QualityAssessments { get; set; } = []; /// /// Optional frame number. /// public int FrameNumber { get; set; } } /// /// Description of a /// face image quality check that has been performed. /// public class QualityAssessment { /// /// The quality check performed. /// public string Check { get; set; } = string.Empty; /// /// The outcome of the quality check. This is a score int the range between /// 0.0 and 1.0. The higher the value, the better the check was passed. /// public double Score { get; set; } /// /// A text with additional info about this quality assessment. /// public string Message { get; set; } = string.Empty; } /// /// The Face /// object describes some landmarks of a found face within an image together /// with some optional scores generated by additional DCNNs. /// /// /// Note that the face image is typically mirrored, i.e. the right eye is /// on the left side of the image and vice versa! /// public class Face { /// /// Position of the center of the left eye. /// public required PointD LeftEye { get; set; } /// /// Position of the center of the right eye. /// public required PointD RightEye { get; set; } /// /// A score in the range ]0.0, 1.0] for the probability that the /// detected face is from a live person. The higher the score, the more /// likely the person is a live person. A value of 0.0 indicates, that /// a liveness detection was not performed on this face yet (or failed). /// public double TextureLivenessScore { get; set; } /// /// A score in the range ]0.0, 1.0] for the probability that the face /// motion (calculated with the help of previous images) is a natural /// 3D motion. The higher the score, the more likely the motion is in 3D. /// A value of 0.0 indicates that this score has not been calculated. /// public double MotionLivenessScore { get; set; } /// /// Calculated movement direction of this face relative to the position /// of this face in a previous image in the range ]0, 360] degrees. /// A value of 0.0 indicates that no movement direction has been calculated. /// public double MovementDirection { get; set; } } /// /// Represents an ordered pair of double precision floating point x- and /// y-coordinates that defines a point in a two-dimensional plane. /// public class PointD { /// /// The x-coordinate of the point. /// public double X { get; set; } /// /// The y-coordinate of the point. /// public double Y { get; set; } } //-------------------------------------------------------- // Face Recognition //-------------------------------------------------------- /// /// The Enroll response object. See also /// /// JSON Web API Enroll. /// public class FaceEnrollmentResponse { /// /// The status of the BWS job that processed the request. /// public JobStatus Status { get; set; } /// /// A list of errors that might have occurred while the request has been processed. /// public List Errors { get; set; } = []; /// /// The calculated image properties for each of the provided live images /// in the given order. /// public List ImageProperties { get; set; } = []; /// /// The actual action performed. /// public EnrollmentAction PerformedAction { get; set; } /// /// Number of newly enrolled images. /// public int EnrolledImages { get; set; } /// /// The FaceTemplateStatus of the generated face template without any face thumbnails. /// public FaceTemplateStatus TemplateStatus { get; set; } = new(); /// /// Possible enrollment actions. /// [JsonConverter(typeof(JsonStringEnumConverter))] public enum EnrollmentAction { NONE = 0, NEW_TEMPLATE_CREATED, TEMPLATE_UPDATED, TEMPLATE_UPGRADED, ENROLLMENT_FAILED = -1 } } /// /// The Verify response object. See also /// /// JSON Web API Verify. /// public class FaceVerificationResponse { /// /// The status of the BWS job that processed the request. /// public JobStatus Status { get; set; } /// /// A list of errors that might have occurred while the request has been processed. /// public List Errors { get; set; } = []; /// /// The calculated image properties for the provided image. /// public ImageProperties ImageProperties { get; set; } = new(); /// /// Verification decission made by BWS. /// public bool Verified { get; set; } /// /// The calculated verification score (a value between 0.0 and 1.0) that /// led to the verified decision. The higher the score, the more likely /// the face in the image and the template referenced by the class ID /// belong to the same person. /// public double Score { get; set; } } /// /// The status of a biometric face template as managed by BWS. /// public class FaceTemplateStatus { /// /// Unique class ID associated with the template. /// public long ClassId { get; set; } /// /// Is there a template stored for the this class? /// public bool Available { get; set; } /// /// When has the template been generated the last time. /// public string Enrolled { get; set; } = string.Empty; /// /// List of tags stored with the template. /// public List Tags { get; set; } = []; /// /// The version of the encoder used to calculate the feature vectors for this template. /// public int EncoderVersion { get; set; } /// /// The number of feature vectors (created from the enrolled face images) /// that have been calculated, stored and used to generate the template. /// public int FeatureVectors { get; set; } /// /// The number of thumbnails (created from the enrolled face images) /// that have been stored with the template. /// public int ThumbnailsStored { get; set; } /// /// If thumbnails have been stored and they have been requested (with a /// call to GetTemplateStatus), those are returned with this field. /// public List Thumbnails { get; set; } = []; public class Thumbnail { /// /// Timestamp when the image was enrolled. /// public string Enrolled { get; set; } = string.Empty; /// /// The thumbnail serialized as base64 PNG. /// public string Image { get; set; } = string.Empty; } }