Exemple #1
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);
        }
        //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;
        }
Exemple #3
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();
        }