コード例 #1
0
    public IEnumerator ILogin(float time, float okScore, Action <string> onProgress, Action <string> onComplete)
    {
        yield return(new WaitForSeconds(0.1f));

        //Dictionary<string, int> userIdCounts = new Dictionary<string, int>();
        //int crtCheckCount = 0;
        while (isCheck && isLoginCheck)
        {
            if (!isLoginSuccess && trackFaceInfo.score >= 0.999f && Mathf.Abs(trackFaceInfo.box.mCenter_x - xcenter) <= 30 && Mathf.Abs(trackFaceInfo.box.mCenter_y - ycenter) <= 30)//首先必须是人脸
            {
                string           result = faceCompare.IdentifyWithAllDB(image.ToBytes());
                FaceIdentifyInfo info   = JsonUtility.FromJson <FaceIdentifyInfo>(result);
                if (onProgress != null)
                {
                    onProgress.Invoke(result);
                }
                //是否找到相似脸
                if (info.errno == 0)
                {
                    float score = float.Parse(info.data.result[0].score);
                    //相似脸分数是否达标
                    if (score > okScore)
                    {
                        //crtCheckCount++;
                        //if (!userIdCounts.ContainsKey(info.data.result[0].user_id))
                        //{
                        //    userIdCounts.Add(info.data.result[0].user_id, 1);
                        //}
                        //else
                        //{
                        //    userIdCounts[info.data.result[0].user_id] += 1;
                        //}
                        //if (crtCheckCount>= ConfigReader.Instance.fConfig.loginCheckCount)
                        //{
                        //    int max = 0;
                        //    string key = "";
                        //    foreach (var item in userIdCounts)
                        //    {
                        //        if (item.Value > max)
                        //        {
                        //            max = item.Value;
                        //            key = item.Key;
                        //        }
                        //    }
                        Debug.Log(info.data.result[0].group_id + ";" + info.data.result[0].user_id + ";" + info.data.result[0].score);
                        isLoginSuccess = true;
                        isLoginCheck   = false;
                        if (onComplete != null)
                        {
                            //正常应该是得到一个Json字符串,内含groupid和userid,传入callback参数
                            onComplete.Invoke(info.data.result[0].user_id /*key*/);
                        }
                        yield break;
                        //}
                    }
                }
            }
            yield return(new WaitForSeconds(time));
        }
    }
コード例 #2
0
    public IEnumerator IRegister(string userid, string groupid, float time, Action <string> onProgress, Action <string, string> onComplete)
    {
        yield return(new WaitForSeconds(0.1f));

        while (isCheck && isRegisterCheck)
        {
            //必须是人脸,且人脸位置必须在正中央偏移不超过30像素
            if (!isRegisterSuccess && trackFaceInfo.score >= 0.999f && Mathf.Abs(trackFaceInfo.box.mCenter_x - xcenter) <= 30 && Mathf.Abs(trackFaceInfo.box.mCenter_y - ycenter) <= 30)
            {
                string           result = faceManager.FaceRegister(userid, groupid, image.ToBytes());
                FaceIdentifyInfo info   = JsonUtility.FromJson <FaceIdentifyInfo>(result);
                if (onProgress != null)
                {
                    onProgress.Invoke(result);
                }
                //是否注册成功
                if (info.errno == 0)
                {
                    Debug.Log(info.data.face_token);
                    isRegisterSuccess = true;
                    isRegisterCheck   = false;
                    if (onComplete != null)
                    {
                        onComplete.Invoke(userid, groupid);
                    }
                    yield break;
                }
            }
            yield return(new WaitForSeconds(time));
        }
    }