Ejemplo n.º 1
0
        private void buttonReadLib_Click(object sender, EventArgs e)
        {
            textBoxOutput.Clear();
            textBoxOutput.AppendText("请稍等。" + Environment.NewLine);

            fs.Group_DeleteByName(Env.GroupName);
            GroupBasicInfo tempGroupBasicInfo = fs.Group_CreateByIdList(Env.GroupName);
            string         libPath            = System.Environment.CurrentDirectory + Path.DirectorySeparatorChar + Env.libFolder + Path.DirectorySeparatorChar;

            if (!Directory.Exists(libPath))
            {
                MessageBox.Show("没有找到数据库 !", "错误");
                return;
            }
            string[] folders = Directory.GetFileSystemEntries(libPath);
            TrainCount = 0;

            //Every name in folder
            foreach (string singleFolder in folders)
            {
                TrainCount++;
                string[] spiltString = new string[1]
                {
                    Path.DirectorySeparatorChar.ToString()
                };
                string[] items = singleFolder.Split(spiltString, StringSplitOptions.RemoveEmptyEntries);
                string   Name  = items[items.Count() - 1];
                fs.Person_DeleteByName(Name);
                PersonBasicInfo tempPersonBasicInfo = fs.Person_Create(Name);
                long            i         = 0;
                bool            faceExist = false;
                while (File.Exists(libPath + Name + Path.DirectorySeparatorChar + i.ToString() + Env.libExtName))
                {
                    faceExist = true;
                    DetectResult res = fs.Detection_DetectImg(libPath + Name + Path.DirectorySeparatorChar + i.ToString() + Env.libExtName);
                    if (res.face.Count != 1)
                    {
                        MessageBox.Show("路径" + libPath + Name + Path.DirectorySeparatorChar + i.ToString() + Env.libExtName + "中不存在人脸!已经自动删除", "警告");
                        File.Delete(libPath + Name + Path.DirectorySeparatorChar + i.ToString() + Env.libExtName);
                        buttonReadLib_Click(sender, e);
                        return;
                    }
                    ManageResult AddFaceResult = fs.Person_AddFaceById(tempPersonBasicInfo.person_id, res.face[0].face_id);
                    if (!AddFaceResult.success)
                    {
                        MessageBox.Show("为用户添加脸部信息失败!", "错误");
                        return;
                    }
                    i++;
                }
                if (!faceExist)
                {
                    MessageBox.Show(Name + "中没有脸部数据!", "警告");
                    continue;
                }
                ManageResult tempAddPersonResult = fs.Group_AddPerson("", Env.GroupName, "", Name);
                if (!tempAddPersonResult.success)
                {
                    MessageBox.Show("添加用户信息失败!", "错误");
                    return;
                }
                AsyncResult tempAsyncResult            = fs.Train_VerifyByName(Name);
                ParameterizedThreadStart CheckFinished = new ParameterizedThreadStart(ProcessCheckAsyncVerifyByName);
                Thread CheckFinishedProcess            = new Thread(CheckFinished);
                CheckFinishedProcess.IsBackground = true;
                string[] arguementStrings = new string[] { tempAsyncResult.session_id, Name };
                CheckFinishedProcess.Start(arguementStrings);
            }


            MessageBox.Show("数据库建立完成!请等待为每一个人的人脸学习过程完成。", "信息");
        }