public string UploadVerifySample()
        {
            string        messages = "";
            List <string> s        = new List <string>();

            s.Add("E:\\Applications\\BiometricAuth\\BiometricAuth\\samples\\voice\\s1.wav");
            s.Add("E:\\Applications\\BiometricAuth\\BiometricAuth\\samples\\voice\\s2.wav");
            s.Add("E:\\Applications\\BiometricAuth\\BiometricAuth\\samples\\image\\sample1.png");
            s.Add("E:\\Applications\\BiometricAuth\\BiometricAuth\\samples\\image\\sample2.png");
            BiometricClassID bcid = new BiometricClassID();

            bcid.ClassID   = 1234;
            bcid.Partition = 10212;
            bcid.Storage   = "bws";
            Sample[] samples;
            try
            {
                samples = s.Select(file => new Sample
                {
                    Trait = file.EndsWith("wav", StringComparison.OrdinalIgnoreCase) ? Trait.Voice : Trait.Face,
                    Data  = System.IO.File.ReadAllBytes(file)
                }).ToArray();
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            BioIDWebServiceClient client = null;

            try
            {
                // connect to  BWS
                client = new BioIDWebServiceClient();

                // go for the commands:
                // - Enrollment
                if (bcid != null)
                {
                    var flags = ClassificationFlags.None;

                    try
                    {
                        bool success = client.Verify(bcid, samples, flags, out messages);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("error...:");
                        Console.WriteLine(e.Message);
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("Exception caught:");
                Console.WriteLine(e.Message);
            }
            return(messages);
        }
예제 #2
0
파일: Program.cs 프로젝트: TipOfit/BWS-cli
        static void Main(string[] args)
        {
            // parse the command-line
            var arguments = new Arguments(args);
            if (arguments["help"] != null || arguments["h"] != null)
            {
                Usage();
                return;
            }

            BiometricClassID bcid;
            bool livedetection, autoenrollment, icao;
            Sample[] samples;
            try
            {
                bcid = ParseBCID(arguments["bcid"]);
                livedetection = (arguments["livedetection"] != null || arguments["l"] != null);
                autoenrollment = (arguments["autoenrollment"] != null || arguments["a"] != null);
                icao = arguments["icao"] != null;

                // load the samples from the given files
                samples = arguments.AnonymousParams.Select(file => new Sample
                {
                    Trait = file.EndsWith("wav", StringComparison.OrdinalIgnoreCase) ? Trait.Voice : Trait.Face,
                    Data = System.IO.File.ReadAllBytes(file)
                }).ToArray();
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not parse/load arguments:");
                Console.WriteLine(e.Message);
                Usage();
                return;
            }

            BioIDWebServiceClient client = null;
            try
            {
                // connect to  BWS
                client = new BioIDWebServiceClient();

                // go for the commands:
                // - Enrollment
                if (arguments["enroll"] != null || arguments["e"] != null)
                {
                    if (bcid == null) { Usage(); return; }
                    var flags = EnrollmentFlags.None;
                    if (livedetection) flags |= EnrollmentFlags.LiveFaceDetection;
                    Console.WriteLine("Enrollment of class {0}/{1}/{2} with {3} samples (Flags: {4}) ...", bcid.Storage, bcid.Partition, bcid.ClassID, samples.Length, flags);
                    string messages;
                    bool success = client.Enroll(bcid, samples, flags, out messages);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(messages);
                }
                // - Verification
                else if (arguments["verify"] != null || arguments["v"] != null)
                {
                    if (bcid == null || samples.Length == 0) { Usage(); return; }
                    var flags = ClassificationFlags.None;
                    if (livedetection) flags |= ClassificationFlags.LiveFaceDetection;
                    if (autoenrollment) flags |= ClassificationFlags.AutoEnrollment;
                    Console.WriteLine("Verification of class {0}/{1}/{2} with {3} samples (Flags: {4}) ...", bcid.Storage, bcid.Partition, bcid.ClassID, samples.Length, flags);
                    string messages;
                    bool success = client.Verify(bcid, samples, flags, out messages);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(messages);
                }
                // - Identification
                else if (arguments["identify"] != null || arguments["i"] != null)
                {
                    if (bcid == null || samples.Length == 0) { Usage(); return; }
                    var flags = ClassificationFlags.None;
                    if (livedetection) flags |= ClassificationFlags.LiveFaceDetection;
                    Console.WriteLine("Identification on partition {0}/{1} with {2} samples (Flags: {3}) ...", bcid.Storage, bcid.Partition, samples.Length, flags);
                    string messages;
                    ScoredClass[] matches;
                    bool success = client.Identify(bcid, samples, flags, 20, out matches, out messages);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(messages);
                    Console.WriteLine("Identification Results (BCID: Score):");
                    if (matches != null)
                        foreach (ScoredClass score in matches.Where(score => score != null))
                            Console.WriteLine("    {0}/{1}/{2}: {3}", score.Storage, score.Partition, score.ClassID, score.Score);
                }
                // - QualityCheck
                else if (arguments["check"] != null || arguments["c"] != null)
                {
                    if (samples.Length == 0) { Usage(); return; }
                    var flags = TestFlags.ExtractTokenData;
                    if (icao) flags = TestFlags.ICAOChecks;
                    Console.WriteLine("QualityCheck of {0} samples (Flags: {1}, Issuer: {2}) ...", samples.Length, flags, "BioID");
                    string messages;
                    Sample[] processedSamples;
                    bool success = client.QualityCheck(samples, flags, "BioID", out processedSamples, out messages);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(messages);
                }
                // - Delete
                else if (arguments["delete"] != null || arguments["d"] != null)
                {
                    if (bcid == null) { Usage(); return; }
                    Console.WriteLine("Deleting class {0}/{1}/{2} ...", bcid.Storage, bcid.Partition, bcid.ClassID);
                    bool success = client.DeleteClass(bcid);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                }
                // - Status
                else
                {
                    Console.WriteLine("Fetching Status ...");
                    string status;
                    bool success = client.Status(out status);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(status);
                }
            }
            catch (System.ServiceModel.FaultException<BioIDWebServiceFault> bioidFault)
            {
                Console.WriteLine("BioIDWebServiceFault {0}:", bioidFault.Detail.Code);
                Console.WriteLine(bioidFault.Detail.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught:");
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (null != client)
                    client.Close();
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: beaubol/BWS-cli
        static void Main(string[] args)
        {
            // parse the command-line
            var arguments = new Arguments(args);

            if (arguments["help"] != null || arguments["h"] != null)
            {
                Usage();
                return;
            }

            BiometricClassID bcid;
            bool             livedetection, autoenrollment, icao;

            Sample[] samples;
            try
            {
                bcid           = ParseBCID(arguments["bcid"]);
                livedetection  = (arguments["livedetection"] != null || arguments["l"] != null);
                autoenrollment = (arguments["autoenrollment"] != null || arguments["a"] != null);
                icao           = arguments["icao"] != null;

                // load the samples from the given files
                samples = arguments.AnonymousParams.Select(file => new Sample
                {
                    Trait = file.EndsWith("wav", StringComparison.OrdinalIgnoreCase) ? Trait.Voice : Trait.Face,
                    Data  = System.IO.File.ReadAllBytes(file)
                }).ToArray();
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not parse/load arguments:");
                Console.WriteLine(e.Message);
                Usage();
                return;
            }

            BioIDWebServiceClient client = null;

            try
            {
                // connect to  BWS
                client = new BioIDWebServiceClient();

                // go for the commands:
                // - Enrollment
                if (arguments["enroll"] != null || arguments["e"] != null)
                {
                    if (bcid == null)
                    {
                        Usage(); return;
                    }
                    var flags = EnrollmentFlags.None;
                    if (livedetection)
                    {
                        flags |= EnrollmentFlags.LiveFaceDetection;
                    }
                    Console.WriteLine("Enrollment of class {0}/{1}/{2} with {3} samples (Flags: {4}) ...", bcid.Storage, bcid.Partition, bcid.ClassID, samples.Length, flags);
                    string messages;
                    bool   success = client.Enroll(bcid, samples, flags, out messages);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(messages);
                }
                // - Verification
                else if (arguments["verify"] != null || arguments["v"] != null)
                {
                    if (bcid == null || samples.Length == 0)
                    {
                        Usage(); return;
                    }
                    var flags = ClassificationFlags.None;
                    if (livedetection)
                    {
                        flags |= ClassificationFlags.LiveFaceDetection;
                    }
                    if (autoenrollment)
                    {
                        flags |= ClassificationFlags.AutoEnrollment;
                    }
                    Console.WriteLine("Verification of class {0}/{1}/{2} with {3} samples (Flags: {4}) ...", bcid.Storage, bcid.Partition, bcid.ClassID, samples.Length, flags);
                    string messages;
                    bool   success = client.Verify(bcid, samples, flags, out messages);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(messages);
                }
                // - Identification
                else if (arguments["identify"] != null || arguments["i"] != null)
                {
                    if (bcid == null || samples.Length == 0)
                    {
                        Usage(); return;
                    }
                    var flags = ClassificationFlags.None;
                    if (livedetection)
                    {
                        flags |= ClassificationFlags.LiveFaceDetection;
                    }
                    Console.WriteLine("Identification on partition {0}/{1} with {2} samples (Flags: {3}) ...", bcid.Storage, bcid.Partition, samples.Length, flags);
                    string        messages;
                    ScoredClass[] matches;
                    bool          success = client.Identify(bcid, samples, flags, 20, out matches, out messages);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(messages);
                    Console.WriteLine("Identification Results (BCID: Score):");
                    if (matches != null)
                    {
                        foreach (ScoredClass score in matches.Where(score => score != null))
                        {
                            Console.WriteLine("    {0}/{1}/{2}: {3}", score.Storage, score.Partition, score.ClassID, score.Score);
                        }
                    }
                }
                // - QualityCheck
                else if (arguments["check"] != null || arguments["c"] != null)
                {
                    if (samples.Length == 0)
                    {
                        Usage(); return;
                    }
                    var flags = TestFlags.ExtractTokenData;
                    if (icao)
                    {
                        flags = TestFlags.ICAOChecks;
                    }
                    Console.WriteLine("QualityCheck of {0} samples (Flags: {1}, Issuer: {2}) ...", samples.Length, flags, "BioID");
                    string   messages;
                    Sample[] processedSamples;
                    bool     success = client.QualityCheck(samples, flags, "BioID", out processedSamples, out messages);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(messages);
                }
                // - Delete
                else if (arguments["delete"] != null || arguments["d"] != null)
                {
                    if (bcid == null)
                    {
                        Usage(); return;
                    }
                    Console.WriteLine("Deleting class {0}/{1}/{2} ...", bcid.Storage, bcid.Partition, bcid.ClassID);
                    bool success = client.DeleteClass(bcid);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                }
                // - Status
                else
                {
                    Console.WriteLine("Fetching Status ...");
                    string status;
                    bool   success = client.Status(out status);
                    Console.WriteLine(success ? "... SUCCEEDED." : "... FAILED!!!");
                    Console.WriteLine(status);
                }
            }
            catch (System.ServiceModel.FaultException <BioIDWebServiceFault> bioidFault)
            {
                Console.WriteLine("BioIDWebServiceFault {0}:", bioidFault.Detail.Code);
                Console.WriteLine(bioidFault.Detail.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught:");
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (null != client)
                {
                    client.Close();
                }
            }
        }