Пример #1
0
        private void HomeForm_Load(object sender, EventArgs e)
        {
            // Get user info
            Userinfolist = FaceDectectHelper.GetAllUserList();
            //refresh token per 5s
            //var _timer = new System.Timers.Timer(5 * 1000);
            //_timer.Elapsed += delegate
            //{
            //    Userinfolist = FaceDectectHelper.GetAllUserList();
            //};

            //_timer.Start();
            Thread objThread = new Thread(new ThreadStart(delegate
            {
                while (true)
                {
                    var result = FaceDectectHelper.GetAllUserList();
                    if (result.Count > 0)
                    {
                        Userinfolist = result;
                    }
                }
            }));

            objThread.Start();
            //实例化委托 没作用
            //UserCheck = new UserCheckInDelegate(UserCheckInMethod);
        }
Пример #2
0
        private bool UserCheckIn(byte[] imageBytes)
        {
            bool       flag   = false;
            var        image  = Convert.ToBase64String(imageBytes);
            FaceSearch result = FaceDectectHelper.SearchDemo(image);
            // 可选参数
            var option = new Dictionary <string, object>()
            {
                { "spd", 5 },   // 语速
                { "vol", 7 },   // 音量
                { "per", 4 }    // 发音人,4:情感度丫丫童声
            };

            if (result != null && result.score > 50)
            {
                flag = true;
                var time = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss");
                CheckResult_rtb.AppendText(String.Format("{0}\t 签到时间:{1}\n", result.user_info, time));
                //签到信息入库
                MysqlUtil.addInfor(result.user_info, time);
                SpeechHelper.Tts(String.Format("签到成功,欢迎{0}", result.user_info), option);
            }
            else
            {
                SpeechHelper.Tts(String.Format("没有该用户的信息,请先注册该用户"), option);
            }

            return(flag);
        }
Пример #3
0
        private void signIn_btn_Click(object sender, EventArgs e)
        {
            string groupId  = groupId_tb.Text;
            string userId   = userId_tb.Text;
            string userName = UserName_tb.Text;

            if (String.IsNullOrEmpty(groupId))
            {
                groupId_tb.Focus();
                return;
            }
            if (String.IsNullOrEmpty(userId))
            {
                userId_tb.Focus();
                return;
            }
            if (String.IsNullOrEmpty(userName))
            {
                UserName_tb.Focus();
                return;
            }

            // 如果有可选参数
            var options = new Dictionary <string, object> {
                { "user_info", userName },
                { "quality_control", "NORMAL" },
                { "liveness_control", "NORMAL" }
            };
            var count = imageLists.Images.Count;

            for (int i = 0; i < count; i++)
            {
                var imageBytes = File.ReadAllBytes(FaceList[i]);

                var image   = Convert.ToBase64String(imageBytes);
                var jresult = FaceDectectHelper.UserAddDemo(image, groupId, userId, options);

                if (jresult != null && !String.IsNullOrEmpty(jresult.face_token))
                {
                    Userinfolist.Add(new FaceSearch()
                    {
                        group_id = groupId, user_id = userId, user_info = userName
                    });
                }
            }
            MessageBox.Show("注册成功!");
        }
Пример #4
0
        private string AddFace(string filePath)
        {
            if (FaceList.Contains(filePath))
            {
                return("该人脸已注册");
            }

            //检测图像质量
            var imageBytes = File.ReadAllBytes(filePath);
            var image      = Convert.ToBase64String(imageBytes);
            var result     = FaceDectectHelper.DetectDemo(image);

            if (String.IsNullOrEmpty(result))
            {
                FaceList.Add(filePath);
                return("");
            }
            return(result);
        }
Пример #5
0
        private void delete_btn_Click(object sender, EventArgs e)
        {
            var flag = false;
            List <FaceSearch> list = new List <FaceSearch>();

            list.AddRange(Userinfolist.Select(x => new FaceSearch(x)));
            foreach (DataGridViewRow row in users_dataGridView.SelectedRows)
            {
                var deleteUser = row.DataBoundItem as FaceSearch;

                var jresult = FaceDectectHelper.DeleteUser(deleteUser.group_id, deleteUser.user_id);
                if (jresult["error_code"].ToString() == "0")
                {
                    flag = true;
                    list.Remove(deleteUser);
                }
            }

            if (flag)
            {
                users_dataGridView.DataSource = list;
            }
        }
Пример #6
0
        public static List <FaceSearch> GetAllUserList()
        {
            List <FaceSearch> userinfolist = new List <FaceSearch>();

            bool flag = true;

            try
            {
                var jresult = FaceDectectHelper.GetGroupList();

                if (flag && jresult["error_code"].ToString() == "0")
                {
                    var groupList = JsonConvert.DeserializeObject <List <string> >(jresult["result"]["group_id_list"].ToString());

                    foreach (var groupId in groupList)
                    {
                        var groupResult = GroupGetusersDemo(groupId.ToString());

                        if (flag && groupResult["error_code"].ToString() == "0")
                        {
                            var users = groupResult["result"]["user_id_list"];

                            var userList = JsonConvert.DeserializeObject <List <string> >(users.ToString());

                            foreach (var userId in userList)
                            {
                                Thread.Sleep(1000);
                                var userResult = GetUser(groupId.ToString(), userId.ToString());

                                if (flag && userResult["error_code"].ToString() == "0")
                                {
                                    var userInfos = JsonConvert.DeserializeObject <List <FaceSearch> >(userResult["result"]["user_list"].ToString());

                                    userInfos.ForEach(user =>
                                    {
                                        user.user_id = userId;
                                    });

                                    userinfolist.AddRange(userInfos);
                                }
                                else
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            flag = false;
                            break;
                        }
                    }
                }
            }
            catch (AipException exp)
            {
                MessageBox.Show(exp.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (WebException exp)
            {
                MessageBox.Show(exp.Message, "网络错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(userinfolist);
        }