Ejemplo n.º 1
0
 public string AddFace(FaceAdd face)
 {
     try
     {
         Sobytie sobytie = new Sobytie()
         {
             Messages = null
         };
         using (var con = new SqlConnection(_parametrService.ConnectionString))
         {
             con.InfoMessage += sobytie.Con_InfoMessage;
             using (var cmd = new SqlCommand(SqlLibaryIfns.SqlSelect.SqlFaceMergin.FaceSelectError.AddFace, con))
             {
                 cmd.Parameters.Add("@Old", SqlDbType.Int).Value = Convert.ToInt32(face.N1Old);
                 cmd.Parameters.Add("@New", SqlDbType.Int).Value = Convert.ToInt32(face.N1New);
                 cmd.Connection.Open();
                 cmd.ExecuteNonQuery();
                 return(sobytie.Messages);
             }
         }
     }
     catch (SqlException e)
     {
         return(e.Message);
     }
 }
        private void TiJiao_button_Click(object sender, EventArgs e)
        {
            if (videoSource == null)
            {
                MessageBox.Show("请先打开摄像头");
                return;
            }
            //videoSourcePlayer继承Control父类,定义 GetCurrentVideoFrame能输出bitmap
            Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();

            pictureBox1.Image = bitmap;
            this.videoSourcePlayer1.Visible = false;
            this.pictureBox1.Visible        = true;
            //这里停止摄像头继续工作 当然videoSourcePlayer里也定义了 Stop();用哪个都行

            //    string imagestr = this.pictureBox1.Image.ToString();
            //
            bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
            String imagestr = Util.ImgToBase64String(bitmap);

            //   MessageBox.Show("01", imagestr.Substring(1, 10));

            videoSourcePlayer1.Stop();

            //检索人脸是否存在
            SearchResult searchResult = FaceSearch.faceSearch(imagestr);

            if (searchResult.error_msg.Equals("SUCCESS") && searchResult.result.user_list[0].user_id.Equals(this.EmployeeID))
            {
                MessageBox.Show("已采集,不可重复采集", "提示信息");
            }
            else
            {
                AddResult result = FaceAdd.add(imagestr, this.EmployeeID);
                if (result.error_msg.Equals("SUCCESS"))
                {
                    MessageBox.Show("采集成功", "提示信息");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("采集未成功", "提示信息");
                }
            }
        }
Ejemplo n.º 3
0
        //录入按钮
        private void btnInput_Click(object sender, EventArgs e)
        {
            if (isDetecting)
            {
                return;
            }

            string name = txtUid.Text;

            if (name == "")
            {
                MessageBox.Show("请输入用户名!");
                return;
            }
            if (Check.IsChinese(name))
            {
                MessageBox.Show("请输入数字");
                return;
            }
            if (videoSource == null)
            {
                MessageBox.Show("请先连接摄像头 !");
                return;
            }
            Bitmap bitmap = vspInput.GetCurrentVideoFrame();

            if (bitmap == null)
            {
                return;
            }

            isDetecting = true;
            // 图像识别耗时且走网络,应该考虑放到子线程执行
            new Thread(new ParameterizedThreadStart(t =>
            {
                string TF  = "是";
                int result = FaceAdd.add(bitmap, name);
                DataAccess.Components fInput = new DataAccess.Components();
                bitmap.Dispose();
                // 从timer线程切换到主线程刷新UI
                this.BeginInvoke(new MethodInvoker(delegate
                {
                    // MessageBox.Show((result > 0 ? "录入失败!" : "录入成功!") + result);
                    if (result > 0)
                    {
                        isDetecting = false;
                    }
                    else if (fInput.stuInputFace(TF, Convert.ToInt32(name)) > 0)
                    {
                        MessageBox.Show("student");
                        this.Close();
                    }
                    else if (fInput.teaInputFace(TF, Convert.ToInt32(name)) > 0)
                    {
                        MessageBox.Show("teacher");
                        this.Close();
                    }
                    else if (fInput.admiInputFace(TF, Convert.ToInt32(name)) > 0)
                    {
                        MessageBox.Show("admin");
                        this.Close();
                    }
                }));
            })).Start("tryToDetectFace");
        }