Example #1
0
    private void Start()
    {
        FaceAppData faceAppData = new FaceAppData("11253066", "WwnwTfmq9ulkzknDBOv9tr6s", "7DNbqdtYvhVr0nR8YMtbIUeFfwyCBVgc");

        _faceDetect = new FaceDetect(faceAppData);

        _faceSearch = new FaceSearch("FaceRec", faceAppData);
    }
Example #2
0
        void match_img(string a)
        {
            byte[] bytes = File.ReadAllBytes(a);
            //二进制转字符串
            string base64String = Convert.ToBase64String(bytes);
            string json         = Newtonsoft.Json.JsonConvert.SerializeObject(base64String);

            TestJson(FaceSearch.search(json));
            //Console.WriteLine("Finesh");
        }
Example #3
0
        /// <summary>
        /// 人脸识别按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnIdentify_Click(object sender, EventArgs e)
        {
            if (videoSource == null)
            {
                return;
            }

            Bitmap bitmap = vspIdentify.GetCurrentVideoFrame();

            string[] result = FaceSearch.search(bitmap);
            bitmap.Dispose();
            txtGroup.Text         = result[0];
            txtUid.Text           = result[1];
            txtMatchingScore.Text = result[2];
        }
        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("采集未成功", "提示信息");
                }
            }
        }
Example #5
0
        private void checkFace(string image)
        {
            //识别
            SearchResult searchResult = FaceSearch.faceSearch(image);

            if (searchResult.error_msg.Equals("SUCCESS"))
            {
                string score = searchResult.result.user_list[0].score;
                //  MessageBox.Show(score);
                if (Double.Parse(score) > 85.0)
                {
                    this.EmployeeID = searchResult.result.user_list[0].user_id;
                    MessageBox.Show("验证成功");
                }
                else
                {
                    MessageBox.Show("未成功,请确认已采集人脸后再试!", "验证失败");
                }
            }
            else
            {
                MessageBox.Show("未成功,请确认已采集人脸后再试!", "验证失败");
            }
        }
Example #6
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");
        }