zoukankan      html  css  js  c++  java
  • Neurotec Biometrics 人脸、检测、采集、识别、匹配、对比

       private void MatchFaces()
            {
                try
                {
                    using (NImage frame = _camera.GetFrame())
                    {
                        if (frame == null)
                        {
                            return;
                        }
                        using (NGrayscaleImage grayscaleImage = frame.ToGrayscale())
                        {
                            NleFace[] faces = _extractor.DetectFaces(grayscaleImage);
                            if (faces.Length <= 0)
                                return;
                            NleFace face = faces[0];
                            NleDetectionDetails detectionDetails = _extractor.DetectFacialFeatures(grayscaleImage, face);
                            NleExtractionStatus extractionStatus;
                            NLTemplate template = _extractor.ExtractUsingDetails(grayscaleImage, detectionDetails, out extractionStatus);
                            if (extractionStatus == NleExtractionStatus.TemplateCreated)
                            {
                                _template = template.Save();
                            }
                        }
                    }

                    if (_template != null && _templates.Length > 0)
                    {
                        try
                        {
                            DataTable dt = new DataTable("tblScore");
                            dt.Columns.Add("colTemplate", System.Type.GetType("System.String"));
                            dt.Columns.Add("colScore", System.Type.GetType("System.Int32"));
                            _matcher.IdentifyStart(_template);
                            for (int i = 0; i < _templates.Length; ++i)
                            {
                                int score = _matcher.IdentifyNext(_templates[i]);
                                DataRow dr = dt.NewRow();
                                dr["colTemplate"] = _templatesNames[i];
                                dr["colScore"] = score;
                                dt.Rows.Add(dr);
                            }

                            dt.DefaultView.Sort = "colScore DESC";
                            DataTable dtTemp = dt.DefaultView.ToTable();
                            listViewEx1.Items.Clear();
                            listViewEx1.Sorting = SortOrder.None;
                            for (int row = 0; row < 10; row++)
                            {
                                listViewEx1.Items.Add(new ListViewItem(new string[] { dtTemp.Rows[row][0].ToString().Replace(".dat", ""), dtTemp.Rows[row][1].ToString() }));
                            }
                            PictureBox pic = new PictureBox();
                            pic.Image = NImage.FromFile(Application.StartupPath + "\\Pictures\\" + dtTemp.Rows[0][0].ToString().Replace(".dat", "") + ".jpg").ToBitmap();
                            pic.Width = pic.Image.Width;
                            pic.Height = pic.Image.Height;
                            faceHistory.Add(pic);
                            UpdatePanel(null, null, NleExtractionStatus.None);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            _matcher.IdentifyEnd();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            private void BuildTemplates()
            {
                try
                {
                    using (NImage frame = _camera.GetFrame())
                    {
                        if (frame == null)
                        {
                            return;
                        }
                        using (NGrayscaleImage grayscale = frame.ToGrayscale())
                        {
                            strDate = DateTime.Now.Date.ToShortDateString().Replace("/", "");
                            NleFace[] faces = _extractor.DetectFaces(grayscale);
                            Rectangle imgRect = new Rectangle();
                            for (int ii = 0; ii < faces.Length; ii++)
                            {
                                NleFace face = faces[ii];
                                NleDetectionDetails detectionDetails = _extractor.DetectFacialFeatures(grayscale, face);
                                NleExtractionStatus extractionStatus;
                                NLTemplate template = _extractor.ExtractUsingDetails(grayscale, detectionDetails, out extractionStatus);

                                if (extractionStatus == NleExtractionStatus.TemplateCreated)
                                {
                                    i = i + 1;
                                    string FileName = Application.StartupPath + "\\Pictures\\" + strDate + i.ToString() + ".jpg";
                                    imgRect.X = detectionDetails.Face.Rectangle.X; //detectionDetails.Face.Confidence
                                    imgRect.Y = detectionDetails.Face.Rectangle.Y;
                                    imgRect.Width = detectionDetails.Face.Rectangle.Width;
                                    imgRect.Height = detectionDetails.Face.Rectangle.Height;
                                    Bitmap img = frame.ToBitmap().Clone(imgRect, System.Drawing.Imaging.PixelFormat.DontCare); //截取人脸图像
                                    img.Save(FileName);

                                    string strFileName = Path.GetFileNameWithoutExtension(FileName);
                                    string strTemplate = Application.StartupPath + "\\Templates\\" + strFileName + ".dat";
                                    listViewEx1.Items.Add(new ListViewItem(new string[] { strFileName, "0" }));
                                    File.WriteAllBytes(strTemplate, template.Save().ToByteArray());

                                    PictureBox pic = new PictureBox();
                                    pic.Image = img;
                                    pic.Width = pic.Image.Width;
                                    pic.Height = pic.Image.Height;
                                    faceHistory.Add(pic);
                                }
                            }

                            UpdatePanel();
                        }
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

  • 相关阅读:
    Eclipse
    JAVA
    .Net Core下使用WCF—— Consuming WCF Services in .NET Core – Best Practices
    xml转class ——xsd实现
    从已有container中生成新的image&打标签——Creating a Docker Image from an Existing Container
    How to install xfs and create xfs file system on Debian/Ubuntu Linux
    Ubuntu系统安装软件包(其他软件包的安装 思路类似)—— Steps to Install XFS Package in Ubuntu
    postgresql——SQL update fields of one table from fields of another one(列的批量更新)
    skype邮件撤回——步骤
    单元测试 _ Unit testing best practices with .NET Core and .NET Standard
  • 原文地址:https://www.cnblogs.com/fang8206/p/2631820.html
Copyright © 2011-2022 走看看