private void btnMatch_Click(object sender, EventArgs e)
        {
            Stopwatch st = new Stopwatch();

            st.Start();

            if (qImage == null)
            {
                MessageBox.Show("Unable to match fingerprints: Unassigned query fingerprint!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (tImage == null)
            {
                MessageBox.Show("Unable to match fingerprints: Unassigned template fingerprint!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Matching features
            List <MinutiaPair> matchingMtiae = null;
            double             score;
            IMinutiaMatcher    minutiaMatcher = matcher as IMinutiaMatcher;

            if (minutiaMatcher != null)
            {
                score = minutiaMatcher.Match(qFeatures, tFeatures, out matchingMtiae);

                st.Stop();
                tm3 = st.Elapsed;

                if (qFeatures is List <Minutia> && tFeatures is List <Minutia> )
                {
                    pbxQueryImg.Image = qImage.Clone() as Bitmap;
                    Graphics g1 = Graphics.FromImage(pbxQueryImg.Image);
                    ShowBlueMinutiae(qFeatures as List <Minutia>, g1);
                    //pbxQueryImg.Invalidate();

                    pbxTemplateImg.Image = tImage.Clone() as Bitmap;
                    Graphics g2 = Graphics.FromImage(pbxTemplateImg.Image);
                    ShowBlueMinutiae(tFeatures as List <Minutia>, g2);
                    //pbxTemplateImg.Invalidate();

                    if (score == 0 || matchingMtiae == null)
                    {
                        MessageBox.Show(string.Format("Similarity: {0}.", score));
                    }
                    else
                    {
                        List <Minutia> qMtiae = new List <Minutia>();
                        List <Minutia> tMtiae = new List <Minutia>();
                        foreach (MinutiaPair mPair in matchingMtiae)
                        {
                            qMtiae.Add(mPair.QueryMtia);
                            tMtiae.Add(mPair.TemplateMtia);
                        }
                        IFeatureDisplay <List <Minutia> > display = new MinutiaeDisplay();

                        display.Show(qMtiae, g1);
                        pbxQueryImg.Invalidate();

                        display.Show(tMtiae, g2);
                        pbxTemplateImg.Invalidate();

                        MessageBox.Show(string.Format("Similarity: {0}. Matching minutiae: {1}.", score, matchingMtiae.Count), "Results", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    ShowResults(score, matchingMtiae);
                }
            }
            else
            {
                score = matcher.Match(qFeatures, tFeatures);
            }

            ShowTime();
        }
Example #2
0
        private void btnMatchInDatabase_Click(object sender, EventArgs e)
        {
            if (qImage == null)
            {
                MessageBox.Show("Unable to match fingerprints: Unassigned query fingerprint!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Stopwatch stDetect = new Stopwatch();
            Stopwatch stFinish = new Stopwatch();

            stDetect.Start();
            stFinish.Start();

            IMinutiaMatcher minutiaMatcher = matcher as IMinutiaMatcher;

            if (minutiaMatcher != null)
            {
                List <MinutiaPair> matchingMtiae = null;

                string filename, shortFileName;
                double score = 0.0, maxScore = 0.0;
                int    idIndex = -1;

                for (int i = 0; i < sizerow; i++)
                {
                    filename      = FingerData.Rows[i][4].ToString();
                    shortFileName = Path.GetFileNameWithoutExtension(filename);
                    try
                    {
                        tFeatures = provider.GetResource(shortFileName, repository);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unable to load features " + provider.GetSignature() + ". Try using different parameters.", "Feature Loading Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    //-----------------------------

                    matchingMtiae = null;
                    try
                    {
                        score = minutiaMatcher.Match(qFeatures, tFeatures, out matchingMtiae);
                    }
                    catch (Exception superE)
                    {
                        //Phat hien van tay giong 100%
                        maxScore = 100.0;
                        idIndex  = i;
                        try
                        {
                            stDetect.Stop();
                            TimeDetect = stDetect.Elapsed;
                        }
                        catch
                        {
                            //For second time
                        }
                        //break;
                    }

                    if (score > maxScore)
                    {
                        try
                        {
                            stDetect.Stop();
                            TimeDetect = stDetect.Elapsed;
                        }
                        catch
                        {
                            //For second time
                        }
                        maxScore = score;
                        idIndex  = i;
                    }
                }

                stFinish.Stop();
                TimeFinish = stFinish.Elapsed;

                //Print output
                tbxRecordID.Text         = FingerData.Rows[idIndex][0].ToString();
                tbxFullname.Text         = FingerData.Rows[idIndex][1].ToString();
                tbxInformation.Text      = FingerData.Rows[idIndex][2].ToString();
                tbxFingerprintImage.Text = FingerData.Rows[idIndex][3].ToString();

                filename      = FingerData.Rows[idIndex][4].ToString();
                shortFileName = Path.GetFileNameWithoutExtension(filename);

                tFeatures            = provider.GetResource(shortFileName, repository);
                tImage               = ImageLoader.LoadImage(filename);
                pbxTemplateImg.Image = tImage;

                matchingMtiae = null;
                double score2 = minutiaMatcher.Match(qFeatures, tFeatures, out matchingMtiae);
                stScore = score2.ToString();

                if (qFeatures is List <Minutia> && tFeatures is List <Minutia> )
                {
                    pbxQueryImg.Image = qImage.Clone() as Bitmap;
                    Graphics g1 = Graphics.FromImage(pbxQueryImg.Image);
                    ShowBlueMinutiae(qFeatures as List <Minutia>, g1);
                    //pbxQueryImg.Invalidate();

                    pbxTemplateImg.Image = tImage.Clone() as Bitmap;
                    Graphics g2 = Graphics.FromImage(pbxTemplateImg.Image);
                    ShowBlueMinutiae(tFeatures as List <Minutia>, g2);
                    //pbxTemplateImg.Invalidate();

                    if (score2 == 0 || matchingMtiae == null)
                    {
                        MessageBox.Show(string.Format("Similarity: {0}.", score2));
                    }
                    else
                    {
                        List <Minutia> qMtiae = new List <Minutia>();
                        List <Minutia> tMtiae = new List <Minutia>();
                        foreach (MinutiaPair mPair in matchingMtiae)
                        {
                            qMtiae.Add(mPair.QueryMtia);
                            tMtiae.Add(mPair.TemplateMtia);
                        }
                        IFeatureDisplay <List <Minutia> > display = new MinutiaeDisplay();

                        display.Show(qMtiae, g1);
                        pbxQueryImg.Invalidate();

                        display.Show(tMtiae, g2);
                        pbxTemplateImg.Invalidate();

                        MessageBox.Show(string.Format("Full name: {0}\nInformation: {1}\nSimilarity: {2}. Matching minutiae: {3}.", tbxFullname.Text.ToString(), tbxInformation.Text.ToString(), score2, matchingMtiae.Count), "Results", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("Full name: {0}\nInformation: {1}\nSimilarity: {2}. Matching minutiae: {3}.", tbxFullname.Text.ToString(), tbxInformation.Text.ToString(), score2, matchingMtiae.Count), "Results", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ShowResults(score2, matchingMtiae);
                }
            }
            else
            {
                double score = matcher.Match(qFeatures, tFeatures);
            }
            ShowTime();
        }