Пример #1
0
        /// <summary>
        /// 根据数据库Match人脸
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public string NetFaceMatchData(Image image)
        {
            try
            {
                RecognitionProvider recognitionProvider = new RecognitionProvider();

                //Task<JObject> @object = new Task<JObject>(baiduRecognitionProvider.NetFaceMatch(image) );
                JObject jsonData = recognitionProvider.NetFaceMatch(image);
                jsonData.TryGetValue("result", out JToken value);
                JToken infoArry  = value["user_list"];
                string faceToken = value["face_token"].ToString();
                string id        = infoArry[0]["user_id"].ToString();
                string group     = infoArry[0]["group_id"].ToString();
                string info      = infoArry[0]["user_info"].ToString();
                //info解析
                JObject faceInfo = (JObject)JsonConvert.DeserializeObject(info);
                //string[] faceInfo = info.Split('`');

                string name   = faceInfo["UserName"].ToString();
                string text   = faceInfo["value"].ToString();
                string score  = infoArry[0]["score"].ToString();
                int    so     = (int)double.Parse(score);
                string result = $"姓名:{name}\r\nID:{id}\r\n信息:{text}\r\n匹配度:{so}\r\n人脸标识:{faceToken}\r\n";
                return(result);
            }
            catch (Exception ex)
            {
                string result = "识别出错:" + ex.ToString();
                return(result);
            }
        }
Пример #2
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public bool Login(Image image)
        {
            RecognitionProvider recognitionProvider = new RecognitionProvider();
            bool loc = false;
            //Task<JObject> @object = new Task<JObject>(baiduRecognitionProvider.NetFaceMatch(image) );
            JObject jsonData = recognitionProvider.NetFaceMatch(image);

            jsonData.TryGetValue("result", out JToken value);
            JToken infoArry = value["user_list"];
            string info     = infoArry[0]["user_info"].ToString();
            //info解析
            JObject faceInfo = (JObject)JsonConvert.DeserializeObject(info);
            string  name     = faceInfo["UserName"].ToString();
            string  score    = infoArry[0]["score"].ToString().Substring(0, 5);
            double  ss       = double.Parse(score);

            if (name == "王宁" && ss >= 70)
            {
                loc = true;
            }
            return(loc);
        }