Example #1
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");
        }
Example #2
0
        /// <summary>
        /// 在收到相机通知可以读取图像时进行图像处理
        /// </summary>
        private void handleImageDetecting()
        {
            Bitmap bitmap = vspIdentify.GetCurrentVideoFrame();//识别

            if (bitmap == null)
            {
                return;
            }

            // 控制一次只能处理一张图片
            isDetecting = true;

            // 图像识别耗时且走网络,应该考虑放到子线程执行
            new Thread(new ParameterizedThreadStart(t =>
            {
                string[] result = FaceSearch.search(bitmap);
                bitmap.Dispose();
                double score = Convert.ToDouble(result[2]);
                if (score > 80)
                {
                    // 从timer线程切换到主线程刷新UI
                    this.BeginInvoke(new MethodInvoker(delegate
                    {
                        this.Close();
                        if (FaceDetectCallback != null)
                        {
                            FaceDetectCallback(this, result[1]);
                            DataAccess.Components identity = new DataAccess.Components();
                            DataSet ds = new DataSet();
                            string pwd = "";
                            int num, num1, num2;
                            ds   = identity.stuIdentity(Convert.ToInt32(result[1]));
                            num  = ds.Tables["studentlist"].Rows.Count;
                            ds   = identity.teaIdentity(Convert.ToInt32(result[1]));
                            num1 = ds.Tables["teacherlist"].Rows.Count;
                            ds   = identity.admIdentity(Convert.ToInt32(result[1]));
                            num2 = ds.Tables["adminilist"].Rows.Count;
                            if (num > 0)
                            {
                                Liuyingjie.Student_Frm stu = new Liuyingjie.Student_Frm();
                                stu.Show();
                            }
                            else if (num1 > 0)
                            {
                                Liaobingquan.FormTeacher tea = new Liaobingquan.FormTeacher();
                                tea.Show();
                            }
                            else if (num2 > 0)
                            {
                                Lijianhua.Admin adm = new Lijianhua.Admin(result[1], pwd);
                                adm.Show();
                            }
                        }
                    }));
                }
                else
                {
                    isDetecting = false;
                }
            })).Start("tryToDetectFace");
        }