예제 #1
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);
        }
예제 #2
0
        /// <summary>
        /// 人脸搜索
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static FaceSearch SearchDemo(string image)
        {
            FaceSearch Result = null;

            try
            {
                //  var image = "取决于image_type参数,传入BASE64字符串或URL字符串或FACE_TOKEN字符串";

                var imageType = "BASE64";
                var groupList = JsonConvert.DeserializeObject <List <string> >(GetGroupList()["result"]["group_id_list"].ToString());

                var groupIdList = String.Join(",", groupList);

                var options = new Dictionary <string, object> {
                    { "quality_control", "NORMAL" },
                    { "liveness_control", "LOW" },
                };
                // 带参数调用人脸搜索
                var jresult = _faceClient.Search(image, imageType, groupIdList, options);

                if (jresult["error_code"].ToString() != "0" && !String.IsNullOrEmpty(jresult["error_msg"].ToString()))
                {
                    SpeechHelper.Tts(jresult["error_msg"].ToString(), null);
                    return(null);
                }

                var searchResult = jresult["result"]["user_list"].ToString();
                Result = JsonConvert.DeserializeObject <List <FaceSearch> >(searchResult).FirstOrDefault();
            }
            catch (AipException exp)
            {
                MessageBox.Show(exp.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (WebException exp)
            {
                MessageBox.Show(exp.Message, "网络错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(Result);
        }