Beispiel #1
0
        private void doEnroll()
        {
            this.enrolledTemplate = this.template;

            ProgramMode mode = ProgramMode.Verify;

            setMode(mode);
            setModeRadioButtons(mode);

            this.BeginInvoke(new MethodInvoker(delegate() { startCapturing(); }));
        }
Beispiel #2
0
        private int GetImageQuality(NGrayscaleImage image, Label lb)
        {
            NGrayscaleImage resultImage = (NGrayscaleImage)image.Clone();

            try
            {
                NfeExtractionStatus extractionStatus;
                template = Data.NFExtractor.Extract(resultImage, NFPosition.Unknown, NFImpressionType.LiveScanPlain, out extractionStatus);
                if (extractionStatus != NfeExtractionStatus.TemplateCreated)
                {
                    lb.Text      = string.Format("Q: {0:P0}", 0);
                    lb.ForeColor = Color.Red;
                    return(0);
                }
            }
            catch (Exception)
            {
                lb.Text      = string.Format("Q: {0:P0}", 0);
                lb.ForeColor = Color.Red;
                return(0);
            }

            this.template = (NFRecord)template.Clone();
            int i = 0;

            if (template != null)
            {
                i       = Helpers.QualityToPercent(template.Quality);
                lb.Text = string.Format("Q: {0:P0}", i / 100.0);
                if (i > 80)
                {
                    lb.ForeColor = Color.GreenYellow;
                }
                else if (i > 50)
                {
                    lb.ForeColor = Color.Orange;
                }
                else
                {
                    lb.ForeColor = Color.Red;
                }
            }
            else
            {
                lb.Text      = string.Format("Q: {0:P0}", 0);
                lb.ForeColor = Color.Red;
            }

            return(i);
        }
Beispiel #3
0
        private void clear()
        {
            ShowStatusMessage("");
            clearView();
            clearLog();

            this.template         = null;
            this.enrolledTemplate = null;
            if (_fingersCollection != null)
            {
                _fingersCollection.Clear();
            }
            //LogWait();
        }
Beispiel #4
0
        /// <summary>
        /// This method is solely responsible for creating a single template from a set of 3 or more templates.
        /// It uses the Neuro SDK to create a "better" template from the set provided.
        /// </summary>
        /// <param name="Templates"></param>
        /// <returns>IdentityStream.BioAPI.Template</returns>
        /// <exception cref="IdentityStream.BioAPI.GeneralizationException" />
        private Template Generalize(List<Template> Templates)
        {
            NFRecord[] records = new NFRecord[Templates.Count];
            for (int i = 0; i < Templates.Count; i++)
            {
                records[i] = new NFRecord(Templates[i].Data);
            }

            int baseTemplateIndex;
            try
            {
                NFExtractor extractor = new NFExtractor();
                NFRecord record = extractor.Generalize(records, out baseTemplateIndex);
                extractor.Dispose();
                return new Template(record.Save(), record.Minutiae.Count);
            }
            catch (Exception ex)
            {
                throw new GeneralizationException(Templates.Count, "Unable to generalize templates.", ex);
            }
        }
Beispiel #5
0
        private void ScannerPreview(object sender, NFScannerPreviewEventArgs e)
        {
            if (_nfView.Finger.Image != null)
            {
                var oldImage = _nfView.Finger.Image;
                _nfView.Finger.Image = null;
                oldImage.Dispose();
            }
            if (_nfView.Finger.Objects[0].Template != null)
            {
                NFRecord template = _nfView.Finger.Objects[0].Template;
                _nfView.Finger.Objects[0].Template = null;
                template.Dispose();
            }

            //lblQuality.Text = e.Status.ToString();
            if (e.Image != null)
            {
                _nfView.Finger.Image = e.Image;
            }
        }
Beispiel #6
0
 public student(string _firstName, string _lastname, string _idNumber, string _studentNumber, string _cardNumber,
     NFRecord _leftPinkie, NFRecord _leftRing, NFRecord _leftMiddle, NFRecord _leftIndex, NFRecord _leftThumb,
     NFRecord _rightThumb, NFRecord _rightIndex, NFRecord _rightMiddle, NFRecord _rightRing, NFRecord _rightPinkie, bool _enrolled)
 {
     FirstName = _firstName;
     LastName = _lastname;
     IDNumber = _idNumber;
     StudentNumber = _studentNumber;
     CardNumber = _cardNumber;
     LeftPinkie = _leftPinkie;
     LeftRing = _leftRing;
     LeftMiddle = _leftMiddle;
     LeftIndex = _leftIndex;
     LeftThumb = _leftThumb;
     RightThumb = _rightThumb;
     RightIndex = _rightIndex;
     RightMiddle = _rightIndex;
     RightRing = _rightRing;
     RightPinkie = _rightPinkie;
     Enrolled = _enrolled;
 }
Beispiel #7
0
        //public void processRawData(byte[][] serializedWSQArray, out ArrayList fingersCollection)
        //{
        //    //if (Data.NFExtractor == null)
        //    //{
        //    //    Data.NFExtractor = new NFExtractor();
        //    //    Data.UpdateNfe();
        //    //    //Data.UpdateNfeSettings();
        //    //}
        //    //if (Data.NMatcher == null)
        //    //{
        //    //    Data.NMatcher = new NMatcher();
        //    //    Data.UpdateNM();
        //    //    //Data.UpdateNMSettings();
        //    //}
        //    DeserializeWSQArray(serializedWSQArray[0], out fingersCollection);
        //}
        public void processEnrolledData(byte[][] serializedWSQArray, out ArrayList fingersCollection)
        {
            //if (Data.NFExtractor == null)
            //{
            //    Data.NFExtractor = new NFExtractor();
            //    Data.UpdateNfe();
            //    //Data.UpdateNfeSettings();
            //}

            //if (Data.NMatcher == null)
            //{
            //    Data.NMatcher = new NMatcher();
            //    Data.UpdateNM();
            //    //Data.UpdateNMSettings();
            //}

            DeserializeWSQArray(serializedWSQArray[0], out fingersCollection);
            if (fingersCollection == null)
                return;

            //byte[] buff = null;
            //System.Object theLock = new System.Object();

            //int bestQuality = 0;
            WsqImage wsqImage = null;
            //bool rbChecked = false;
            //, pbChecked = false;
            //int j = 0;
            //throw new Exception((fingersCollection[4] as WsqImage == null).ToString());

            //int bestQuality = 0;
            //int bestQualityImage = 0;
            int pct = 0;
            for (int i = 0; i < fingersCollection.Count; i++)
            {
                if (fingersCollection[i] != null)
                {
                    wsqImage = fingersCollection[i] as WsqImage;
                    try
                    {
                        NImage nImage = NImage.FromMemory(wsqImage.Content, NImageFormat.Wsq);
                        if (serializedWSQArray[i + 1].Length != 0)
                        {
                            NFRecord record = new NFRecord(serializedWSQArray[i + 1]);
                            pct = record.Quality;
                            if (pct == 254)
                                pct = 0;
                        }
                        else
                            pct = 0;

                        //verify(nImage);

                        string label = ""; Brush brush = Brushes.Transparent;

                        if (pct > 0) {
                            label = string.Format("Q: {0:P0}", pct / 100.0);
                            if (pct > 79)
                                brush = Brushes.Green;
                            else if (pct > 39)
                                brush = Brushes.Orange;
                            else
                                brush = Brushes.Red;
                        } else {
                            label = string.Format("q: {0:P0}", 0);
                            brush = Brushes.Red;
                        }

                        //Bitmap bmp = new Bitmap(nImage.ToBitmap(), new Size(65, 95));
                        Bitmap bmp = new Bitmap(nImage.ToBitmap(), new Size(100, 120));
                        //RectangleF rectf = new RectangleF(0.0f, 2.0f, 65.0f, 40.0f);
                        RectangleF rectf = new RectangleF(0.0f, 2.0f, 90.0f, 60.0f);
                        Graphics g = Graphics.FromImage(bmp);
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        g.PixelOffsetMode = PixelOffsetMode.HighQuality;

                        g.DrawString(label, new Font("Areal", 13), brush, rectf);
                        g.Flush();

                        using(var ms = new MemoryStream())
                        {
                            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                            fingersCollection[i] = ms.ToArray();
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message == "Operation is not activated")
                            throw new Exception(ex.Message);

                        fingersCollection[i] = getEmptyBitmap();
                        continue;
                    }
                }
                else
                {
                    fingersCollection[i] = getEmptyBitmap();
                }
            }

            //Data.NFExtractor.Dispose();
            //Data.NFExtractor = null;
            //Data.NMatcher.Dispose();
            //Data.NMatcher = null;

            //throw new Exception(j.ToString());

            //rb = this.Controls.Find("radioButton" + (bestQualityRadioButton + 1).ToString(), true)[0] as RadioButton;
            //this.BeginInvoke(new MethodInvoker(delegate() { checkRadioButton(rb.Name); }));

            //System.Threading.Thread.Sleep(5000);
            //stopProgressBar();                           //     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            //buttonScan.Enabled = true;

            //pictureBox2.Image = Properties.Resources.redcross;
        }
Beispiel #8
0
        //public bool match(byte[] galleryTemplate)
        public bool match(ArrayList fingerList, byte[][] galleryTemplate)
        {
            //bool retcode = false;

            bool matched = true;
            bool matchMethod1 = false;
            if (matchMethod1)
            {
                _biometricClient.MatchingWithDetails = true;
                _biometricClient.FingersMatchingSpeed = NMatchingSpeed.High;
                _biometricClient.FingersQualityThreshold = 48;
                int threshold = 48;
                var template = new NFTemplate();

                foreach (string finger in fingerList)
                {
                    FingerListEnum f = (FingerListEnum)Enum.Parse(typeof(FingerListEnum), finger);
                    if (galleryTemplate[(int)f] != null && (galleryTemplate[(int)f]).Length != 0)
                    {
                        var record = new NFRecord(galleryTemplate[(int)f]);
                        if (record.Position == NFPosition.Unknown)
                            record.Position = getFingerPositionByTag(f.ToString());

                        template.Records.Add((NFRecord)record.Clone());
                    }
                }

                if (template == null)
                    throw new Exception("Gallery template is null");

                using (var gallerySubject = NSubject.FromMemory(template.Save().ToArray()))
                {
                    if (gallerySubject == null)
                        throw new Exception("Gallery template is null");

                    var status = _biometricClient.Verify(_probeSubject, gallerySubject);
                    if (status == NBiometricStatus.Ok)
                    {
                        foreach (var matchingResult in _probeSubject.MatchingResults)
                        {
                            //int fsc = matchingResult.MatchingDetails.FingersScore;
                            foreach (var finger in matchingResult.MatchingDetails.Fingers)
                            {
                                if (threshold > finger.Score)
                                {
                                    matched = false;
                                    break;
                                }
                            }

                            if (!matched)
                                break;
                        }
                    } else
                        matched = false;
                }
            }
            else
            {
                var template = new NFTemplate();
                foreach (string finger in fingerList)
                {
                    FingerListEnum f = (FingerListEnum)Enum.Parse(typeof(FingerListEnum), finger);
                    if (galleryTemplate[(int)f] != null && (galleryTemplate[(int)f]).Length != 0)
                    {
                        var record = new NFRecord(galleryTemplate[(int)f]);
                        if (record.Position == NFPosition.Unknown)
                            record.Position = getFingerPositionByTag(f.ToString());

                        template.Records.Add((NFRecord)record.Clone());

                        using (var subject = NSubject.FromMemory(template.Save().ToArray()))
                        {
                            var status = _biometricClient.Verify(_probeSubject, subject);
                            if (status != NBiometricStatus.Ok)
                            {
                                matched = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        matched = false;
                        break;
                    }
                }
            }

            //var template = new NFTemplate();

            //foreach (string finger in _fingerList)
            //{
            //    FingerListEnum f = (FingerListEnum)Enum.Parse(typeof(FingerListEnum), finger);
            //    if (galleryTemplate[(int)f] != null && (galleryTemplate[(int)f]).Length != 0)
            //    {
            //        var record = new NFRecord(galleryTemplate[(int)f]);
            //        if (record.Position == NFPosition.Unknown)
            //            record.Position = getFingerPositionByTag(f.ToString());
            //        template.Records.Add((NFRecord)record.Clone());

            //        //matched = matcher.match(buffer[(int)f]);
            //        //if (matched)
            //        //{
            //        //    numOfMatches++;
            //        //}
            //    }

            //}

            //if (template == null)
            //    throw new Exception("Gallery template is null");

            //NSubject gallerySubject = NSubject.FromMemory(template.Save().ToArray());
            //if (gallerySubject == null)
            //    throw new Exception("Gallery template is null");

            //var status = _biometricClient.Verify(_probeSubject, gallerySubject);
            //if (status == NBiometricStatus.Ok)
            //     retcode = true;

            return matched;
        }
Beispiel #9
0
 public int getImageQuality(byte[] wsqImage)
 {
     NFRecord record = new NFRecord(wsqImage);
     if (record.Quality == 254)
         return 0;
     else
         return record.Quality;
 }
Beispiel #10
0
        private void bckScanFinger_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bck = (BackgroundWorker)sender;
            try
            {
                int i;
                NDeviceManager devMan = new NDeviceManager(NDeviceType.FingerScanner, true, false);
                int count = devMan.Devices.Count;

                //See if a fingerprint scanner is connected
                if (count > 0)
                {
                    //What if there is more than one scanner
                }
                else
                {
                    GlobalScanStatus = ScanStatus.NoScanner;
                }

                if (count > 1)
                    //What if there is more than one scanner.  We will use the first detected scanner.
                    for (i = 0; i < count; i++)
                    {
                        NDevice device = devMan.Devices[i];
                    }
                i = 0;
                NFScanner fingerScanner = (NFScanner)devMan.Devices[i];
                NFExtractor extractor = new NFExtractor();
                NFRecord record;
                extractor.ReturnedImage = NfeReturnedImage.Binarized;

                NImage image = null;
                while (image == null && !bckScanFinger.CancellationPending)
                {
                    if (bck.CancellationPending)
                    {
                        e.Cancel = true;
                    }
                    else
                    {
                        using ( image = fingerScanner.Capture(5000))
                        {
                            if (image == null)
                            {
                                GlobalScanStatus = ScanStatus.NoTemplateCreated;
                            }
                            else
                            {
                                NfeExtractionStatus extractionStatus;
                                using (NGrayscaleImage grayscaleImage = image.ToGrayscale())
                                {
                                    if (grayscaleImage.ResolutionIsAspectRatio
                                        || grayscaleImage.HorzResolution < 250
                                        || grayscaleImage.VertResolution < 250)
                                    {
                                        grayscaleImage.HorzResolution = 500;
                                        grayscaleImage.VertResolution = 500;
                                        grayscaleImage.ResolutionIsAspectRatio = false;
                                    }

                                    record = extractor.Extract(grayscaleImage, NFPosition.Unknown, NFImpressionType.LiveScanPlain, out extractionStatus);
                                    fingerprintImage = (NImage)image.Clone();
                                    fingerprintImage = NImages.GetGrayscaleColorWrapper(fingerprintImage, resultImageMinColor, resultImageMaxColor);

                                }

                                if (extractionStatus == NfeExtractionStatus.TemplateCreated)
                                {
                                    GlobalScanStatus = ScanStatus.TemplateCreated;
                                    fingerprintTemplate = record;
                                    ScannedTemplated = true;
                                    bck.ReportProgress(1);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ScanError = ex.Message;
            }

            GlobalScanStatus = ScanStatus.Cancelled;
        }
Beispiel #11
0
        private bool VerifyFingerprint(student originalStudent, NFRecord template2)
        {
            const string Components = "Biometrics.FingerExtraction,Biometrics.FingerMatching";
            bool matched = false;
            NFExtractor extractor = null;
            NMatcher matcher = null;
            try
            {
                // obtain license
                if (!NLicense.ObtainComponents("/local", 5000, Components))
                {
                    Console.WriteLine(@"Could not obtain licenses for components: {0}", Components);
                    matched = false;
                }

                // create an extractor
                extractor = new NFExtractor();

                // extract reference template
                NBuffer referenceTemplate = template2.Save();

                //For each finger in the NFRecord

                // extract candidate template
                NBuffer leftPinkie;
                NBuffer leftRing;
                NBuffer leftMiddle;
                NBuffer leftIndex;
                NBuffer leftThumb;
                NBuffer rightThumb;
                NBuffer rightIndex;
                NBuffer rightMiddle;
                NBuffer rightRing;
                NBuffer rightPinkie;
                int scoreLeftPinkie = 0;
                int scoreLeftRing = 0;
                int scoreLeftMiddle = 0;
                int scoreLeftIndex = 0;
                int scoreLeftThumb = 0;
                int scoreRightPinkie = 0;
                int scoreRightRing = 0;
                int scoreRightMiddle = 0;
                int scoreRightIndex = 0;
                int scoreRightThumb = 0;

                // create a matcher
                matcher = new NMatcher();
                if (originalStudent.LeftPinkie != null)
                {
                    leftPinkie = originalStudent.LeftPinkie.Save();
                    scoreLeftPinkie = matcher.Verify(referenceTemplate, leftPinkie);
                }

                if (originalStudent.LeftRing != null)
                {
                    leftRing = originalStudent.LeftRing.Save();
                    scoreLeftRing= matcher.Verify(referenceTemplate, leftRing);
                }

                if (originalStudent.LeftMiddle != null)
                {
                    leftMiddle = originalStudent.LeftMiddle.Save();
                    scoreLeftMiddle= matcher.Verify(referenceTemplate, leftMiddle);
                }
                if (originalStudent.LeftIndex != null)
                {
                    leftIndex = originalStudent.LeftIndex.Save();
                    scoreLeftIndex= matcher.Verify(referenceTemplate, leftIndex);
                }
                if (originalStudent.LeftThumb != null)
                {
                    leftThumb = originalStudent.LeftThumb.Save();
                    scoreLeftThumb = matcher.Verify(referenceTemplate, leftThumb);
                }
                if (originalStudent.RightThumb != null)
                {
                    rightThumb = originalStudent.RightThumb.Save();
                    scoreRightThumb = matcher.Verify(referenceTemplate, rightThumb);
                }

                if (originalStudent.RightIndex !=null)
                {
                    rightIndex = originalStudent.RightIndex.Save();
                    scoreRightIndex = matcher.Verify(referenceTemplate, rightIndex);
                }
                if (originalStudent.RightMiddle != null)
                {
                    rightMiddle = originalStudent.RightMiddle.Save();
                    scoreRightMiddle = matcher.Verify(referenceTemplate, rightMiddle);
                }
                if (originalStudent.RightRing != null)
                {
                    rightRing = originalStudent.RightRing.Save();
                    scoreRightRing = matcher.Verify(referenceTemplate, rightRing);
                }
                if (originalStudent.RightPinkie != null)
                {
                    rightPinkie = originalStudent.RightPinkie.Save();
                    scoreRightPinkie = matcher.Verify(referenceTemplate, rightPinkie);
                }

                if (scoreLeftPinkie > 0)
                {
                    matched = true;
                    matchedFingerID = 1;
                }
                if (scoreLeftRing > 0)
                {
                    matched = true;
                    matchedFingerID = 2;
                }

                if (scoreLeftMiddle > 0)
                {
                    matched = true;
                    matchedFingerID = 3;
                }
                if (scoreLeftIndex > 0)
                {
                    matched = true;
                    matchedFingerID = 4;
                }
                if (scoreLeftThumb > 0)
                {
                    matched = true;
                    matchedFingerID = 5;
                }
                if (scoreRightPinkie > 0)
                {
                    matched = true;
                    matchedFingerID = 6;
                }
                if (scoreRightRing > 0)
                {
                    matched = true;
                    matchedFingerID = 7;
                }
                if (scoreRightMiddle > 0)
                {
                    matched = true;
                    matchedFingerID = 8;
                }
                if (scoreRightIndex > 0)
                {
                    matched = true;
                    matchedFingerID = 9;
                }
                if (scoreRightThumb > 0)
                {
                    matched = true;
                    matchedFingerID = 10;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //INeurotecException neurotecException = ex as INeurotecException;
                //if (neurotecException != null)
                //{
                //    return neurotecException.Code;
                //}
                matched = false;
            }
            finally
            {
                NLicense.ReleaseComponents(Components);

                if (extractor != null)
                {
                    extractor.Dispose();
                }
                if (matcher != null)
                {
                    matcher.Dispose();
                }

            }
            return matched;
        }
Beispiel #12
0
 private void MisMatch(NFRecord template)
 {
     lblMatchResult.Text = "Please type studentnumber";
     txtStudentNumber.Visible = true;
     btnMatchConfirm.Visible = true;
     btnMatchConfirm.Text = "Continue";
     btnMatchRetry.Visible = true;
 }
Beispiel #13
0
        private string MatchStudents(NFRecord template, BindingList<student> StudentsInCourse)
        {
            const string Components = "Biometrics.FingerExtraction,Biometrics.FingerMatching";

            matchedFingerID = 0;
            matchedScore = 0;
            string highestStudent = "";
            int highestMatch = 0;

            NFExtractor extractor = null;
            NMatcher matcher = null;
            try
            {
                lblStatus.Text = "Getting License!";
                Application.DoEvents();
                // Obtain license.
                if (!NLicense.ObtainComponents(licServer, 5000, Components))
                {
                    Console.WriteLine(@"Could not obtain licenses for components: {0}", Components);
                    //return -1;
                }
                lblStatus.Text = "Got License!";
                Application.DoEvents();
                // create an extractor
                //extractor = new NFExtractor();

                // extract probe template

                NBuffer probeTemplate = template.Save();

                lblStatus.Text = "Exctracting templates";
                // extract gallery templates
                int args = StudentsInCourse.Count * 10;
                NBuffer[] galleryTemplates = new NBuffer[args - 1];
                string[] students = new string[args - 1];
                int n = 0;
                foreach (student currentStudent in StudentsInCourse)
                {
                    for (int count = 0; count < 10; count++)
                    {
                        try
                        {
                            galleryTemplates[n+count] = new NBuffer(currentStudent.template[count]);
                            students[n + count] = currentStudent.StudentNumber;

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Could not load template for student" + currentStudent.StudentNumber + " - " + ex.Message);
                        }
                    }

                    n = n + 10;
                }

                // create a matcher
                matcher = new NMatcher();
                // identify reference template by comparing to each template from arguments
                Console.WriteLine(@"=== identification started ===");
                matcher.IdentifyStart(probeTemplate);

                lblStatus.Text = "Identifying start";
                try
                {
                    for (int i = 1; i < args; i++)
                    {
                        if (galleryTemplates[i - 1].Size != 0)
                        {
                            int score = matcher.IdentifyNext(galleryTemplates[i - 1]);
                            if (score > highestMatch)
                            {
                                Console.WriteLine(@"template[{0}] scored {1} {2}", i - 1, score, score > 0 ? "(Matched)" : "");
                                Console.WriteLine("student number matched: " + students[i-1]);
                                highestMatch = score;
                                highestStudent = students[i - 1];
                                matchedFingerID = i % 10;
                                matchedScore = score;
                            }

                        }

                    }
                }
                finally
                {
                    matcher.IdentifyEnd();
                }
                Console.WriteLine(@"=== identification finished ===");

                //return 0;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

            }
            finally
            {
                lblStatus.Text = "Releasing License";
                Application.DoEvents();
                NLicense.ReleaseComponents(Components);

                if (extractor != null)
                {
                    extractor.Dispose();
                }
                if (matcher != null)
                {
                    matcher.Dispose();
                }
                lblStatus.Text = "License Released";
                Application.DoEvents();
            }

            return highestStudent;
        }
Beispiel #14
0
        private void OnImage(NGrayscaleImage image)
        {
            clearView();
            if (nfView1.Image == null)
            {
                nfView1.Image = image.ToBitmap();
            }

            NGrayscaleImage resultImage = (NGrayscaleImage)image.Clone();

            try
            {
                NfeExtractionStatus extractionStatus;
                template = Data.NFExtractor.Extract(resultImage, NFPosition.Unknown, NFImpressionType.LiveScanPlain, out extractionStatus);
                if (extractionStatus != NfeExtractionStatus.TemplateCreated)
                {
                    string text = string.Format("Extraction failed: {0}", extractionStatus.ToString());
                    ShowErrorMessage(text);

                    LogLine(text, true);
                    //LogLine("Waiting for image...", true);

                    pictureBox2.Image = Properties.Resources.redcross;

                    //      MessageBox.Show(text, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //    sw.Stop();
                    //stopProgressBar();
                    //UseWaitCursor = false;

                    return;
                }
            }
            catch (Exception e)
            {
                string text = string.Format("Extraction error: {0}", e.Message);
                ShowErrorMessage(text);

                LogLine(text, true);

                pictureBox2.Image = Properties.Resources.redcross;

                return;
            }
            finally
            {
                //WaitingForImageToScan();
                //stopProgressBar();                !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            }

            Bitmap bitmap;

            using (NImage ri = NImages.GetGrayscaleColorWrapper(resultImage, resultImageMinColor, resultImageMaxColor))
            {
                bitmap = ri.ToBitmap();
            }

            this.template       = (NFRecord)template.Clone();
            nfView2.ResultImage = bitmap;
            if (nfView2.Template != null)
            {
                nfView2.Template.Dispose();
            }
            nfView2.Template = this.template;

            if (template == null)
            {
                ResourceManager rm   = new ResourceManager("PSCBioVerification.Form1", this.GetType().Assembly);
                string          text = rm.GetString("msgFingerprintImageIsOfLowQuality"); // "Fingerprint image is of low quality"
                ShowErrorMessage(text);
                LogLine(text, true);

                pictureBox2.Image = Properties.Resources.redcross;

                //MessageBox.Show(text, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            LogLine("Template extracted{0}. G: {1}. Size: {2}", true,
                    Data.NFExtractor.UseQuality ? string.Format(". Quality: {0:P0}", Helpers.QualityToPercent(template.Quality) / 100.0) : null,
                    template.G, Data.SizeToString(template.Save().Length));

            ShowStatusMessage(String.Format("Template extracted{0}. G: {1}. Size: {2}", true,
                                            Data.NFExtractor.UseQuality ? string.Format(". Quality: {0:P0}", Helpers.QualityToPercent(template.Quality) / 100.0) : null,
                                            template.G, Data.SizeToString(template.Save().Length)));

            switch (mode)
            {
            case ProgramMode.Enroll:
                doEnroll();
                nfView2.Zoom = 1F;
                break;

            case ProgramMode.Verify:
                doVerify();
                nfView2.Zoom = 0.5F;
                break;
            }

            WaitingForImageToScan();
        }