public void WriteInfo(PersonInfo info)
        {
            XDocument xDoc = XDocument.Load(FileName);

            if (xDoc.Root.Nodes().Count() > 4)
            {
                xDoc.Root.FirstNode.Remove();
            }

            xDoc.Root.Add(new XElement("person",
                new XAttribute("id", info.ID),
                new XAttribute("name", info.Name),
                new XAttribute("sex", info.Sex),
                new XAttribute("age", info.Age),
                new XAttribute("card", info.CardId),
                new XAttribute("filename", info.FileName),
                new XAttribute("similarity", info.Similarity)));
            xDoc.Save(FileName);
        }
        private static void loadInternal(Dictionary<string, PersonInfo> repo)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Properties.Settings.Default.SuspectsConfigurationFileName);

            XmlNodeList nodes = doc.SelectNodes("//person");

            foreach (XmlNode n in nodes)
            {
                PersonInfo p = new PersonInfo();
                p.ID = n.Attributes["id"].Value.ToString();
                p.Name = n.Attributes["name"].Value.ToString();
                p.Sex = n.Attributes["sex"].Value.ToString();
                p.Age = Convert.ToInt32(n.Attributes["age"].Value.ToString());
                p.CardId = n.Attributes["card"].Value.ToString();
                p.FileName = n.Attributes["filename"].Value.ToString();
                p.Similarity = Convert.ToInt32(n.Attributes["similarity"].Value);

                repo[p.FileName] = p;
            }
        }
 public ImportantPersonDetail(PersonInfo suspect, FaceRecognition.RecognizeResult result)
 {
     this.Info = suspect;
     this.Similarity = result;
 }
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.picTargetPerson.Image == null)
            {
                MessageBox.Show("请选定一张人脸图片");
                return;
            }

            if (drawRectangle == Rectangle.Empty)
            {
                MessageBox.Show("请定位人脸");
                return;
            }

            String oldFileName = this.picTargetPerson.Image.Tag as string;

            String fileName = System.Guid.NewGuid().ToString().ToUpper() + System.IO.Path.GetExtension(oldFileName);

            //搜索人脸
            OpenCvSharp.IplImage iplFace = BitmapConverter.ToIplImage((Bitmap)this.picTargetPerson.Image);

            string savePath = Path.Combine(FileSavePath, fileName);
            iplFace.SaveImage(savePath);

            //归一化
            OpenCvSharp.CvRect rect = new OpenCvSharp.CvRect(
                this.drawRectangle.X,
                this.drawRectangle.Y,
                this.drawRectangle.Width,
                this.drawRectangle.Height);

            OpenCvSharp.IplImage[] normalizedImages =
                Program.searcher.NormalizeImageForTraining(iplFace, rect);

            for (int i = 0; i < normalizedImages.Length; ++i)
            {
                string normalizedFaceName = string.Format("{0}_{1:d4}.jpg",
                    System.IO.Path.GetFileNameWithoutExtension(fileName), i);

                string fullPath = System.IO.Path.Combine(faceFeatureImagePath,
                    normalizedFaceName);

                normalizedImages[i].SaveImage(fullPath);
            }

            string id = txtId.Text.ToString();
            string name = txtName.Text.ToString();
            string sex = rabMan.Checked ? "男" : "女";
            int age = 0;

            int.TryParse(txtAge.Text, out age);

            string card = txtCard.Text.ToString();

            PersonInfo info = new PersonInfo();
            info.ID = id;
            info.Name = name;
            info.Sex = sex;
            info.Age = age;
            info.CardId = card;
            info.FileName = fileName;
            info.Similarity = 0;

            perinfo.WriteInfo(info);

            MessageBox.Show("添加成功");

            Array.ForEach(normalizedImages, ipl => ipl.Dispose());
        }