コード例 #1
0
ファイル: Form1.cs プロジェクト: walBou/BiometricalSolutions
        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);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: walBou/BiometricalSolutions
        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();
        }