Exemplo n.º 1
0
        private void btnEnroll_Click(object sender, EventArgs e)
        {
            UFScanner  Scanner;
            UFS_STATUS ufs_res;
            int        EnrollQuality;
            int        EnrollMode;
            int        template_enrolled = 0;
            bool       fingeron;

            if (!GetGetCurrentScanner(out Scanner))
            {
                return;
            }

            switch (this.cbScanTemplateType.SelectedIndex)
            {
            case 0:
                Scanner.nTemplateType = 2001;
                break;

            case 1:
                Scanner.nTemplateType = 2002;
                break;

            case 2:
                Scanner.nTemplateType = 2003;
                break;
            }

            EnrollMode = rbtnOneTemplateAdvanced.Checked ? 1 : 2;

            UFE30_UserInfo udlg = new UFE30_UserInfo();

            tbxMessage.AppendText("Input user data\r\n");

            if (udlg.ShowDialog(this) != DialogResult.OK)
            {
                tbxMessage.AppendText("User data input is cancelled by user\r\n");
                return;
            }

            Refresh();

            //Enroll Template with Non-Advanced-Extraction
            if (rbtnOneTemplateNormal.Checked == true || rbtnOneTemplateNormal2.Checked == true)
            {
                Scanner.ClearCaptureImageBuffer();
                tbxMessage.AppendText("Place Finger\r\n");

                while (true)
                {
                    ufs_res = Scanner.CaptureSingleImage();
                    if (ufs_res != UFS_STATUS.OK)
                    {
                        UFScanner.GetErrorString(ufs_res, out m_strError);
                        tbxMessage.AppendText("UFScanner CaptureSingleImage: " + m_strError + "\r\n");
                        return;
                    }

                    if (m_template_num + 1 == MAX_TEMPLATE_NUM)
                    {
                        tbxMessage.AppendText("Template memory is full\r\n");
                        return;
                    }

                    if (template_enrolled == 0)
                    {
                        ufs_res = Scanner.ExtractEx(MAX_TEMPLATE_SIZE, m_template1[m_template_num], out m_template_size1[m_template_num], out EnrollQuality);
                    }
                    else
                    {
                        ufs_res = Scanner.ExtractEx(MAX_TEMPLATE_SIZE, m_template2[m_template_num], out m_template_size2[m_template_num], out EnrollQuality);
                    }

                    DrawCapturedImage(Scanner);

                    if (ufs_res == UFS_STATUS.OK)
                    {
                        if (EnrollQuality < m_quality)
                        {
                            tbxMessage.AppendText("Too low quality [Q:" + EnrollQuality + "]\r\n");
                        }
                        else
                        {
                            m_UserID[m_template_num] = udlg.UserID;
                            template_enrolled++;
                            tbxMessage.AppendText("Enrollment success (No." + m_template_num + ") [Q:" + EnrollQuality + "]\r\n");

                            if (rbtnOneTemplateNormal.Checked == true)
                            {
                                m_template_num++;
                                UpdateFingerDataList();
                                break;
                            }
                            else if (rbtnOneTemplateNormal2.Checked == true && template_enrolled == 2)
                            {
                                m_template_num++;
                                UpdateFingerDataList();
                                break;
                            }
                            else
                            {
                                tbxMessage.AppendText("Remove finger\r\n");
                                while (true)
                                {
                                    fingeron = Scanner.IsFingerOn;
                                    if (fingeron == false)
                                    {
                                        tbxMessage.AppendText("Place a finger\r\n");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        UFScanner.GetErrorString(ufs_res, out m_strError);
                        tbxMessage.AppendText("UFScanner Extract: " + m_strError + "\r\n");
                    }
                }
            }
            //Enroll with Advanced-Extraction
            else
            {
                UFE30_Enroll dlg = new UFE30_Enroll();

                dlg.hScanner  = Scanner;
                dlg.UserID    = udlg.UserID;
                dlg.OutputNum = EnrollMode;
                dlg.Quality   = m_quality;

                if (dlg.ShowDialog(this) != DialogResult.OK)
                {
                    tbxMessage.AppendText("Fingerprint enrollment is cancelled by user\r\n");
                    return;
                }

                if (dlg.EnrollTemplateOutputSize[0] != 0)
                {
                    if (m_template_num + 1 == MAX_TEMPLATE_NUM)
                    {
                        tbxMessage.AppendText("Template memory is full\r\n");
                    }
                    else
                    {
                        //Enroll 1-Template
                        if (EnrollMode == 1)
                        {
                            System.Array.Copy(dlg.EnrollTemplateOutput[0], 0, m_template1[m_template_num], 0, dlg.EnrollTemplateOutputSize[0]);
                            m_template_size1[m_template_num] = dlg.EnrollTemplateOutputSize[0];
                            m_UserID[m_template_num]         = udlg.UserID;
                        }
                        //Enroll 2-Template
                        else
                        {
                            System.Array.Copy(dlg.EnrollTemplateOutput[0], 0, m_template1[m_template_num], 0, dlg.EnrollTemplateOutputSize[0]);
                            m_template_size1[m_template_num] = dlg.EnrollTemplateOutputSize[0];
                            System.Array.Copy(dlg.EnrollTemplateOutput[1], 0, m_template2[m_template_num], 0, dlg.EnrollTemplateOutputSize[1]);
                            m_template_size2[m_template_num] = dlg.EnrollTemplateOutputSize[1];
                            m_UserID[m_template_num]         = udlg.UserID;
                        }

                        tbxMessage.AppendText("Enrollment is succeed (No." + m_template_num + ")\r\n");
                        m_template_num++;
                    }
                    UpdateFingerDataList();
                }
                else
                {
                    tbxMessage.AppendText("Enrollment is failed\r\n");
                }

                Scanner.Timeout = cbTimeout.SelectedIndex * 1000;
            }
        }
Exemplo n.º 2
0
        private void btnUpdateTemplate_Click(object sender, EventArgs e)
        {
            UFScanner  Scanner;
            UFS_STATUS ufs_res;

            byte[] Template = new byte[MAX_TEMPLATE_SIZE];
            int    TemplateSize;
            int    EnrollQuality;
            int    EnrollMode;
            int    Serial;
            int    template_enrolled = 0;
            bool   fingeron;

            if (lvFingerDataList.SelectedIndices.Count == 0)
            {
                tbxMessage.AppendText("Select data\r\n");
                return;
            }
            else
            {
                Serial = Convert.ToInt32(lvFingerDataList.SelectedItems[0].SubItems[FINGERDATA_COL_SERIAL].Text);
            }

            if (!GetGetCurrentScanner(out Scanner))
            {
                return;
            }

            switch (this.cbScanTemplateType.SelectedIndex)
            {
            case 0:
                Scanner.nTemplateType = 2001;
                break;

            case 1:
                Scanner.nTemplateType = 2002;
                break;

            case 2:
                Scanner.nTemplateType = 2003;
                break;
            }

            EnrollMode = rbtnOneTemplateAdvanced.Checked ? 1 : 2;

            //Update Template with Non-Advanced-Extraction
            if (rbtnOneTemplateNormal.Checked == true || rbtnOneTemplateNormal2.Checked == true)
            {
                Scanner.ClearCaptureImageBuffer();
                tbxMessage.AppendText("Place Finger\r\n");

                while (true)
                {
                    ufs_res = Scanner.CaptureSingleImage();
                    if (ufs_res != UFS_STATUS.OK)
                    {
                        UFScanner.GetErrorString(ufs_res, out m_strError);
                        tbxMessage.AppendText("UFScanner CaptureSingleImage: " + m_strError + "\r\n");
                        return;
                    }

                    ufs_res = Scanner.ExtractEx(MAX_TEMPLATE_SIZE, Template, out TemplateSize, out EnrollQuality);
                    DrawCapturedImage(Scanner);

                    if (ufs_res == UFS_STATUS.OK)
                    {
                        if (EnrollQuality < m_quality)
                        {
                            tbxMessage.AppendText("Too low quality [Q:" + EnrollQuality + "]\r\n");
                        }
                        else
                        {
                            if (rbtnOneTemplateNormal.Checked == true)
                            {
                                System.Array.Clear(m_template2[Serial], 0, MAX_TEMPLATE_SIZE);
                                m_template_size2[Serial] = 0;

                                System.Array.Clear(m_template1[Serial], 0, MAX_TEMPLATE_SIZE);
                                System.Array.Copy(Template, 0, m_template1[Serial], 0, TemplateSize);
                                m_template_size1[Serial] = TemplateSize;

                                tbxMessage.AppendText("Update success (Serial." + Serial + ") [Q:" + EnrollQuality + "]\r\n");

                                UpdateFingerDataList();
                                break;
                            }
                            else if (rbtnOneTemplateNormal2.Checked == true && template_enrolled == 1)
                            {
                                System.Array.Clear(m_template2[Serial], 0, MAX_TEMPLATE_SIZE);
                                System.Array.Copy(Template, 0, m_template2[Serial], 0, TemplateSize);
                                m_template_size2[Serial] = TemplateSize;
                                tbxMessage.AppendText("Second template update success (Serial." + Serial + ") [Q:" + EnrollQuality + "]\r\n");

                                UpdateFingerDataList();
                                break;
                            }
                            else
                            {
                                template_enrolled++;
                                System.Array.Clear(m_template1[Serial], 0, MAX_TEMPLATE_SIZE);
                                System.Array.Copy(Template, 0, m_template1[Serial], 0, TemplateSize);
                                m_template_size1[Serial] = TemplateSize;
                                tbxMessage.AppendText("First template update success (Serial." + Serial + ") [Q:" + EnrollQuality + "]\r\n");

                                tbxMessage.AppendText("Remove finger\r\n");
                                while (true)
                                {
                                    fingeron = Scanner.IsFingerOn;
                                    if (fingeron == false)
                                    {
                                        tbxMessage.AppendText("Place a finger\r\n");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        UFScanner.GetErrorString(ufs_res, out m_strError);
                        tbxMessage.AppendText("UFScanner Extract: " + m_strError + "\r\n");
                    }
                }
            }
            //Update with Advanced-Extraction
            else
            {
                UFE30_Enroll dlg = new UFE30_Enroll();

                dlg.hScanner  = Scanner;
                dlg.UserID    = m_UserID[Serial];
                dlg.OutputNum = EnrollMode;
                dlg.Quality   = m_quality;

                if (dlg.ShowDialog(this) != DialogResult.OK)
                {
                    tbxMessage.AppendText("Fingerprint update is cancelled by user\r\n");
                    return;
                }

                if (dlg.EnrollTemplateOutputSize[0] != 0)
                {
                    //Update 1-Template
                    if (EnrollMode == 1)
                    {
                        System.Array.Clear(m_template2[Serial], 0, MAX_TEMPLATE_SIZE);
                        m_template_size2[Serial] = 0;

                        System.Array.Clear(m_template1[Serial], 0, MAX_TEMPLATE_SIZE);
                        System.Array.Copy(dlg.EnrollTemplateOutput[0], 0, m_template1[Serial], 0, dlg.EnrollTemplateOutputSize[0]);
                        m_template_size1[Serial] = dlg.EnrollTemplateOutputSize[0];
                    }
                    //Update 2-Template
                    else
                    {
                        System.Array.Clear(m_template1[Serial], 0, MAX_TEMPLATE_SIZE);
                        System.Array.Copy(dlg.EnrollTemplateOutput[0], 0, m_template1[Serial], 0, dlg.EnrollTemplateOutputSize[0]);
                        m_template_size1[Serial] = dlg.EnrollTemplateOutputSize[0];
                        System.Array.Clear(m_template2[Serial], 0, MAX_TEMPLATE_SIZE);
                        System.Array.Copy(dlg.EnrollTemplateOutput[1], 0, m_template2[Serial], 0, dlg.EnrollTemplateOutputSize[1]);
                        m_template_size2[Serial] = dlg.EnrollTemplateOutputSize[1];
                    }

                    tbxMessage.AppendText("Fingerprint update is succeed (Serial." + Serial + ")\r\n");
                    UpdateFingerDataList();
                }
                else
                {
                    tbxMessage.AppendText("Fingerprint update is failed\r\n");
                }

                Scanner.Timeout = cbTimeout.SelectedIndex * 1000;
            }
        }