Provides means to keeping a fingerprint database. A fingerprint gallery is needed for fingerprint identification. Fingerprints can be loaded from byte arrays or enrollment results.
Inheritance: IDisposable
Esempio n. 1
0
        /// <summary>
        /// Verifies the fingerprint.
        /// </summary>
        /// <param name="galleryKey">The gallery key.</param>
        /// <param name="gallery">The gallery.</param>
        /// <param name="pgmFilePath">The PGM file path.</param>
        /// <returns></returns>
        public bool VerifyFingerprint(string galleryKey, FingerprintGallery gallery, string pgmFilePath)
        {
            // Make sure the device is open
            if (IsOpen == false)
            {
                this.Open();
            }

            // Acquire the pointer to the stored fingerprint
            var fingerprintPtr = gallery.GetFingerprintPointer(galleryKey);

            if (fingerprintPtr == IntPtr.Zero)
            {
                return(false);
            }

            var printImagePtr = IntPtr.Zero;

            // Perform verification
            var resultCode = Interop.fp_verify_finger_img(this.RealDevicePtr, fingerprintPtr, out printImagePtr);

            // Save the PGM file if required by the user
            SaveImageToDisk(printImagePtr, pgmFilePath, true);

            if (resultCode == (int)Interop.fp_verify_result.FP_VERIFY_MATCH)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Verifies the fingerprint.
        /// </summary>
        /// <param name="enrollResult">The enroll result.</param>
        /// <param name="pgmFilePath">The PGM file path.</param>
        /// <returns></returns>
        public bool VerifyFingerprint(EnrollStageResult enrollResult, string pgmFilePath)
        {
            const string galleryKey = "dummy";

            using var gallery = new FingerprintGallery();
            gallery.Add(galleryKey, enrollResult);
            return(VerifyFingerprint(galleryKey, gallery, pgmFilePath));
        }
Esempio n. 3
0
        /// <summary>
        /// Identifies the fingerprint.
        /// </summary>
        /// <param name="gallery">The gallery.</param>
        /// <param name="pgmFilePath">The PGM file path.</param>
        /// <returns></returns>
        public string IdentifyFingerprint(FingerprintGallery gallery, string pgmFilePath)
        {
            // Make sure the device is open
            if (IsOpen == false)
            {
                Open();
            }

            var matchResult = Interop.fp_identify_finger_img(RealDevicePtr, gallery.PointerArray, out var matchOffset,
                                                             out var printImagePtr);

            // Save the PGM file if required by the user
            SaveImageToDisk(printImagePtr, pgmFilePath, true);

            // Return the key string based on the offset
            return(matchResult == 1 ? gallery[Convert.ToInt32(matchOffset)] : null);
        }
Esempio n. 4
0
 /// <summary>
 /// Identifies the fingerprint.
 /// </summary>
 /// <param name="gallery">The gallery.</param>
 /// <returns></returns>
 public string IdentifyFingerprint(FingerprintGallery gallery) => IdentifyFingerprint(gallery, null);
Esempio n. 5
0
 /// <summary>
 /// Verifies the fingerprint.
 /// </summary>
 /// <param name="galleryKey">The gallery key.</param>
 /// <param name="gallery">The gallery.</param>
 /// <returns></returns>
 public bool VerifyFingerprint(string galleryKey, FingerprintGallery gallery) =>
 VerifyFingerprint(galleryKey, gallery, null);
Esempio n. 6
0
 /// <summary>
 /// Identifies the fingerprint.
 /// </summary>
 /// <param name="gallery">The gallery.</param>
 /// <returns></returns>
 public string IdentifyFingerprint(FingerprintGallery gallery)
 {
     return(IdentifyFingerprint(gallery, null));
 }
Esempio n. 7
0
 /// <summary>
 /// Verifies the fingerprint.
 /// </summary>
 /// <param name="galleryKey">The gallery key.</param>
 /// <param name="gallery">The gallery.</param>
 /// <returns></returns>
 public bool VerifyFingerprint(string galleryKey, FingerprintGallery gallery)
 {
     return(this.VerifyFingerprint(galleryKey, gallery, null));
 }
Esempio n. 8
0
 /// <summary>
 /// Identifies the fingerprint.
 /// </summary>
 /// <param name="gallery">The gallery.</param>
 /// <returns></returns>
 public string IdentifyFingerprint(FingerprintGallery gallery)
 {
     return IdentifyFingerprint(gallery, null);
 }
Esempio n. 9
0
        /// <summary>
        /// Identifies the fingerprint.
        /// </summary>
        /// <param name="gallery">The gallery.</param>
        /// <param name="pgmFilePath">The PGM file path.</param>
        /// <returns></returns>
        public string IdentifyFingerprint(FingerprintGallery gallery, string pgmFilePath)
        {
            // Make sure the device is open
            if (IsOpen == false)
                this.Open();

            uint matchOffset = 0;
            var printImagePtr = IntPtr.Zero;

            var matchResult = Interop.fp_identify_finger_img(this.RealDevicePtr, gallery.PointerArray, out matchOffset, out printImagePtr);

            // Save the PGM file if required by the user
            SaveImageToDisk(printImagePtr, pgmFilePath, true);

            // Return the key string based on the offset
            if (matchResult == 1)
            {
                return gallery[Convert.ToInt32(matchOffset)];
            }

            return null;

        }
Esempio n. 10
0
 /// <summary>
 /// Verifies the fingerprint.
 /// </summary>
 /// <param name="enrollResult">The enroll result.</param>
 /// <param name="pgmFilePath">The PGM file path.</param>
 /// <returns></returns>
 public bool VerifyFingerprint(EnrollStageResult enrollResult, string pgmFilePath)
 {
     const string galleryKey = "dummy";
     using (var gallery = new FingerprintGallery())
     {
         gallery.Add(galleryKey, enrollResult);
         return VerifyFingerprint(galleryKey, gallery, pgmFilePath);
     }
 }
Esempio n. 11
0
 /// <summary>
 /// Verifies the fingerprint.
 /// </summary>
 /// <param name="galleryKey">The gallery key.</param>
 /// <param name="gallery">The gallery.</param>
 /// <returns></returns>
 public bool VerifyFingerprint(string galleryKey, FingerprintGallery gallery)
 {
     return this.VerifyFingerprint(galleryKey, gallery, null);
 }
Esempio n. 12
0
        /// <summary>
        /// Verifies the fingerprint.
        /// </summary>
        /// <param name="galleryKey">The gallery key.</param>
        /// <param name="gallery">The gallery.</param>
        /// <param name="pgmFilePath">The PGM file path.</param>
        /// <returns></returns>
        public bool VerifyFingerprint(string galleryKey, FingerprintGallery gallery, string pgmFilePath)
        {
            // Make sure the device is open
            if (IsOpen == false)
                this.Open();

            // Acquire the pointer to the stored fingerprint
            var fingerprintPtr = gallery.GetFingerprintPointer(galleryKey);
            if (fingerprintPtr == IntPtr.Zero) return false;

            var printImagePtr = IntPtr.Zero;

            // Perform verification
            var resultCode = Interop.fp_verify_finger_img(this.RealDevicePtr, fingerprintPtr, out printImagePtr);

            // Save the PGM file if required by the user
            SaveImageToDisk(printImagePtr, pgmFilePath, true);

            if (resultCode == (int)Interop.fp_verify_result.FP_VERIFY_MATCH)
                return true;

            return false;
        }
Esempio n. 13
0
        public static void Main(string[] args)
        {
            // The device manager discovers devices. It's a singleton and is used to detect connected devices
            // it also create references to the fingerprint scanners
            using (var manager = FingerprintDeviceManager.Instance)
            {
                // We always need to call this method to make sure the library is initialized
                manager.Initialize();
                Console.WriteLine("Initialized Device Manager.");

                // Now we call the device discovery method
                var devices = manager.DiscoverDevices();

                // Let's do stuff with each of the discovered devices (typically only 1)
                foreach (var device in devices)
                {
                    var thread = new Thread(() =>
                    {

                        // Before we do anything, we need to open the device.
                        device.Open();

                        // Now we print some info about the device.
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine();
                        Console.WriteLine("Device {0} - {1}", device.DriverName, device.DriverFullName);
                        Console.WriteLine("    Enroll Stages:      {0}", device.EnrollStagesCount);
                        Console.WriteLine("    Supports Imaging:   {0}", device.SupportsImaging);
                        Console.WriteLine("    Supports Ident:     {0}", device.SupportsIdentification);
                        Console.WriteLine("    Imaging Dimensions: {0}x{1}", device.ImageWidth, device.ImageHeight);

                        // We will enroll a few fingerprints into the gallery.
                        using (var gallery = new FingerprintGallery())
                        {
                            var enrollCount = 0;
                            while (enrollCount < 5)
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine(" >> ENROLL: Enroll count: {0}. Enroll a new finger now . . .", enrollCount);

                                // Call the enrollment method
                                var enrollResult = device.EnrollFingerprint("enroll.pgm");
                                if (enrollResult.IsEnrollComplete)
                                {

                                    Console.ForegroundColor = ConsoleColor.Green;
                                    Console.WriteLine(" >> VERIFY: Now, verify your scan just to make sure . . .");

                                    // Although not necessary, we are adding verification just to make sure
                                    var isVerified = device.VerifyFingerprint(enrollResult, "verify.pgm");
                                    if (isVerified)
                                    {
                                        enrollCount++;
                                        var printName = "The print " + enrollCount.ToString();
                                        gallery.Add(printName, enrollResult);
                                    }
                                    else
                                    {
                                        Console.ForegroundColor = ConsoleColor.Red;
                                        Console.WriteLine("Could not verify. Try again!");
                                        Console.WriteLine();
                                    }
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine("Try Again -- Error Code {0} - {1}", enrollResult.ResultCode, enrollResult.Result);
                                    Console.WriteLine();
                                    // HACK: for some reason we needed the Reset method to be called. Otherwise the reader would blink rapidly and get stuck
                                    device.Reset();
                                }
                            }

                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine();

                            // Now, let's try some identification in the gallery we created earlier
                            // with enrollment and verification operations
                            while (true)
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine(" >> IDENTIFY: Press finger against scanner to identify . . .");

                                // Let's try to identify a fingerprint and getting it's key back.
                                // a null key means the FP was not identified.
                                var identified = device.IdentifyFingerprint(gallery, "identify.pgm");
                                if (identified == null)
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine("Could not identify.");
                                    Console.WriteLine();
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.Blue;
                                    Console.WriteLine("Fingerprint was identified: {0}.", identified);
                                    Console.WriteLine();
                                }
                            }

                        }

                    }) { IsBackground = true };

                    
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("Press A to abort the thread . . .");
                    
                    thread.Start();

                    while (true)
                    {
                        if (Console.ReadKey(true).Key == ConsoleKey.A)
                        {
                            thread.Abort();
                            var terminationTimeout = DateTime.Now.AddSeconds(10);
                            while (thread.IsAlive)
                            {
                                Console.ForegroundColor = ConsoleColor.DarkYellow;
                                Console.WriteLine("Waiting for thread termination. {0.00} seconds to terminate forcefully.", terminationTimeout.Subtract(DateTime.Now).TotalSeconds);
                                thread.Abort();

                                if (DateTime.Now > terminationTimeout)
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine("Termination timeout reached. Forcefully disposing the device.");
                                }

                                Thread.Sleep(1000);
                            }

                            break;
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Press A to abort the thread . . .");
                        }
                    }


                    // We realease unmanaged resources for the device.
                    device.Dispose();
                }

            }


        }