Пример #1
0
    private void OnUserLoginClick(Face f, GameObject panelInstance)
    {
        CloudUserData userData = CloudUserData.Instance;

        if (userData)
        {
            userData.selectedUser = f;
        }

        // SetHintText("Selected: " + (userData ? userData.selectedUser.candidate.person.name : "-"));

        CloudUserManager userManager      = CloudUserManager.Instance;
        CloudFaceManager cloudFaceManager = CloudFaceManager.Instance;
        Person           person           = userData.selectedUser.candidate.person;
        StringBuilder    sbPerson         = new StringBuilder();
        CultureInfo      culture          = new CultureInfo("en-US");

        string groupId = userManager ? userManager.userGroupId : "";
        string checkIn = System.DateTime.Now.ToString("g", culture);         // Timestamp on "Check In" Press

        person.userData += string.Format("|CheckIn={0}", checkIn);
        cloudFaceManager.UpdatePersonData(groupId, person);

        sbPerson.Append(person.name).AppendLine()
        .AppendLine(person.userData).AppendLine()
        .AppendLine("Person Updated in Cloud").AppendLine();

        Debug.Log(sbPerson.ToString());
        panelInstance.gameObject.SetActive(false);
        SetHintText(string.Format("{0} Checked In", person.name));

        // load the main scene
        // SceneManager.LoadScene(1);
    }
Пример #2
0
    // display identity results
    private void ShowIdentityResult()
    {
        // Clear current list
        ClearIdentityResult();

        // Create the new list
        if (faces != null)
        {
            // Get face images
            CloudFaceManager.MatchFaceImages(texCamShot, ref faces);

            // Show recognized persons
            for (int i = 0; i < faces.Length; i++)
            {
                Face face = faces[i];

                if (face.candidate != null && face.candidate.person != null)
                {
                    InstantiateUserItem(i, face, face.candidate.person);
                }
            }

            // Show unrecognized faces
            for (int i = 0; i < faces.Length; i++)
            {
                Face face = faces[i];

                if (face.candidate == null || face.candidate.person == null)
                {
                    InstantiateUserItem(i, face, null);
                }
            }
        }
    }
    // display identity results
    private void ShowIdentityResult()
    {
//        StringBuilder sbResult = new StringBuilder();
//
//        if (faces != null && faces.Length > 0)
//        {
//            for (int i = 0; i < faces.Length; i++)
//            {
//                Face face = faces[i];
//                string faceColorName = FaceDetectionUtils.FaceColorNames[i % FaceDetectionUtils.FaceColors.Length];
//
//                string res = FaceDetectionUtils.FaceToString(face, faceColorName);
//
//                sbResult.Append(string.Format("<color={0}>{1}</color>", faceColorName, res));
//            }
//        }
//
//        string result = sbResult.ToString();
//
//        if (resultText)
//        {
//            resultText.text = result;
//        }
//        else
//        {
//            Debug.Log(result);
//        }

        // clear current list
        ClearIdentityResult();

        // create the new list
        if (faces != null)
        {
            // get face images
            CloudFaceManager.MatchFaceImages(texCamShot, ref faces);

            // show recognized persons
            for (int i = 0; i < faces.Length; i++)
            {
                Face face = faces[i];

                if (face.candidate != null && face.candidate.person != null)
                {
                    InstantiateUserItem(i, face, face.candidate.person);
                }
            }

            // show unrecognized faces
            for (int i = 0; i < faces.Length; i++)
            {
                Face face = faces[i];

                if (face.candidate == null || face.candidate.person == null)
                {
                    InstantiateUserItem(i, face, null);
                }
            }
        }
    }
Пример #4
0
    void Start()
    {
        try
        {
            instance = this;

            if (string.IsNullOrEmpty(userGroupId))
            {
                throw new Exception("Please set the user-group name.");
            }

            faceManager = CloudFaceManager.Instance;
            if (faceManager != null)
            {
                if (string.IsNullOrEmpty(faceManager.faceSubscriptionKey))
                {
                    throw new Exception("Please set your face-subscription key.");
                }
            }
            else
            {
                throw new Exception("FaceManager-component not found.");
            }

            // get the user group info
            if (checkGroupAtStart)
            {
                AsyncTask <bool> task = new AsyncTask <bool>(() => {
                    GetOrGreateUserGroup();
                    return(userGroupId == initedGroupId);
                });

                task.Start();

                int waitounter = threadWaitLoops;
                while (task.State == TaskState.Running && waitounter > 0)
                {
                    Thread.Sleep(threadWaitMs);
                    waitounter--;
                }

                if (!string.IsNullOrEmpty(task.ErrorMessage))
                {
                    throw new Exception(task.ErrorMessage);
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.Message + '\n' + ex.StackTrace);

            if (debugText != null)
            {
                debugText.text = ex.Message;
            }
        }
    }
Пример #5
0
    void Awake()
    {
        instance = this;

        if (string.IsNullOrEmpty(faceSubscriptionKey))
        {
            throw new Exception("Please set your face-subscription key.");
        }

        isInitialized = true;
    }
Пример #6
0
    void Start()
    {
        instance = this;

        if (string.IsNullOrEmpty(faceSubscriptionKey))
        {
            throw new Exception("Please set your face-subscription key.");
        }

        StartCoroutine(CreateList());

        isInitialized = true;
    }
Пример #7
0
    /*private IEnumerator GetPersonFromImageAsync(Texture2D imageBytes)
     * {
     *  var personGroups =  PersonGroup.GetGroupListAsync();
     *  for (var i = 0; i < personGroups.Length; i++)
     *  {
     *      labelText.text = "Searching Group: " + personGroups[i].name;
     *
     *      // try to detect the faces in the image.
     *      FaceInfo[] faces =  Face.DetectAsync(imageBytes);
     *
     *      if (faces != null)
     *      {
     *          if (faces.Length == 0)
     *          {
     *              yield return new WaitForUpdate();
     *              labelText.text = "No Faces Found!";
     *              return;
     *          }
     *
     *          // if faces are found, assign a GUID
     *          var faceIds = new string[faces.Length];
     *          for (int j = 0; j < faces.Length; j++)
     *          {
     *              faceIds[j] = faces[j].faceId;
     *          }
     *
     *          // try to identify the face found in the image by
     *          // retrieving a series of candidates form the queried group.
     *          var idResults =  Face.IdentifyAsync(faceIds, personGroups[i].personGroupId);
     *
     *          for (var j = 0; j < idResults.Length; j++)
     *          {
     *              double bestConfidence = 0f;
     *              string personId = null;
     *
     *              // try to match the candidate to the face found
     *              // in the image using a confidence value.
     *              for (var k = 0; k < idResults[j].candidates.Length; k++)
     *              {
     *                  var candidate = idResults[j].candidates[k];
     *
     *                  if (bestConfidence > candidate.confidence) { continue; }
     *
     *                  bestConfidence = candidate.confidence;
     *                  personId = candidate.personId;
     *              }
     *
     *              if (string.IsNullOrEmpty(personId))
     *              {
     *                  yield return new WaitForUpdate();
     *                  labelText.text = "No Faces Found!";
     *                  continue;
     *              }
     *
     *              // display the candidate with the highest confidence
     *              var person =  Person.GetPersonAsync(personGroups[i].personGroupId, personId);
     *              labelText.text = person.name;
     *              return;
     *          }
     *      }
     *  }
     *
     *  yield return new WaitForUpdate();
     *  labelText.text = "No Faces Found!";
     * }*/

    // performs face detection
    private IEnumerator DoFaceDetection(Texture2D texImage)
    {
        // get the face manager instance
        CloudFaceManager faceManager = CloudFaceManager.Instance;

        if (texImage && faceManager)
        {
            Texture2D texFlipped = FlipTextureV(texImage);
            yield return(faceManager.DetectFaces(texFlipped));

            if (faceManager.faces != null && faceManager.faces.Length > 0)
            {
                Face face = faceManager.faces[0];

                // set user data
                userGender = face.faceAttributes.gender;
                userAge    = face.faceAttributes.age;
                userSmile  = face.faceAttributes.smile;
                userTempID = face.faceId;

                string sMessage = string.Format("{0}, Age: {1:F1}", userGender.ToUpper(), userAge);
                Debug.Log(string.Format("CloudFaceDetector found " + sMessage));
                Debug.Log("@@@@ GAILE FACE ID: " + userTempID);
                if (infoText != null)
                {
                    infoText.text = sMessage;
                }

                // convert to gender enum
                UserGender gender = userGender.ToLower() == "male" ? UserGender.Male : UserGender.Female;

                // invoke UserDataDetected() of the category selector(s) related to the same user
                MonoBehaviour[] monoScripts = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[];
                foreach (MonoBehaviour monoScript in monoScripts)
                {
                    if ((monoScript is CloudFaceListenerInterface) && monoScript.enabled)
                    {
                        CloudFaceListenerInterface userFaceListener = (CloudFaceListenerInterface)monoScript;
                        userFaceListener.UserFaceDetected(playerIndex, gender, userAge, userSmile);
                    }
                }
            }
        }

        yield return(null);
    }
Пример #8
0
    // performs face detection
    private IEnumerator DoFaceDetection()
    {
        // get the image to detect
        faces = null;
        Texture2D texCamShot = null;

        if (cameraShot)
        {
            texCamShot = (Texture2D)cameraShot.GetComponent <Renderer>().material.mainTexture;

            //SetHintText("Wait...");
        }

        // get the face manager instance
        CloudFaceManager faceManager = CloudFaceManager.Instance;

        if (texCamShot && faceManager)
        {
            if (faces != null && faces.Length > 0)
            {
                //if(displayFaceRectangles)
                {
                    //faceManager.DrawFaceRects(texCamShot, faces, FaceDetectionUtils.FaceColors, this.displayHeadDirection);
                    faceManager.AddFaceToList(texCamShot, faces);
                }
                //Add most promininent face to faceList.

                //SetHintText("Click on the camera image to make a shot");
            }
            else
            {
                //SetHintText("No faces detected.");
            }

            yield return(faceManager.DetectFaces(texCamShot));

            faces = faceManager.faces;
        }
        else
        {
            //SetHintText("Check if the FaceManager component exists in the scene.");
        }

        yield return(null);
    }
Пример #9
0
    // performs face detection
    private IEnumerator DoFaceDetection()
    {
        // get the image to detect
        Face[]    faces      = null;
        Texture2D texCamShot = null;

        if (cameraShot)
        {
            texCamShot = (Texture2D)cameraShot.material.mainTexture;
            SetHintText("Wait...");
        }

        // get the face manager instance
        CloudFaceManager faceManager = CloudFaceManager.Instance;

        if (!faceManager)
        {
            SetHintText("Check if the FaceManager component exists in the scene.");
        }
        else if (texCamShot)
        {
            yield return(faceManager.DetectFaces(texCamShot));

            faces = faceManager.faces;

            if (faces != null && faces.Length > 0)
            {
                //if(displayFaceRectangles)
                {
                    faceManager.DrawFaceRects(texCamShot, faces, FaceDetectionUtils.FaceColors, displayHeadDirection);
                    faceManager.AddFaceToList(texCamShot, faces);
                }

                SetHintText(hintMessage);
                SetResultText(faces);
            }
            else
            {
                SetHintText("No face(s) detected.");
            }
        }

        yield return(null);
    }
    // performs face detection
    private IEnumerator DoFaceDetection()
    {
        // get the image to detect
        faces = null;
        Texture2D texCamShot = null;

        if (cameraShot)
        {
            texCamShot = (Texture2D)cameraShot.GetComponent <Renderer>().material.mainTexture;
            SetHintText("Wait...");
        }

        // get the face manager instance
        CloudFaceManager faceManager = CloudFaceManager.Instance;

        if (texCamShot && faceManager)
        {
            yield return(faceManager.DetectFaces(texCamShot));

            faces = faceManager.faces;
            // Debug.Log("Zeroth FaceID: " + faces[0].faceId);
            //yield return faceManager.matchingFace(faces[0].faceId);

            if (faces != null && faces.Length > 0)
            {
                //if(displayFaceRectangles)
                {
                    faceManager.DrawFaceRects(texCamShot, faces, FaceDetectionUtils.FaceColors, this.displayHeadDirection);
                    StartCoroutine(isTarget());
                }
                SetHintText("Click on the camera image to make a shot");
            }
            else
            {
                SetHintText("No faces detected.");
            }
        }
        else
        {
            SetHintText("Check if the FaceManager component exists in the scene.");
        }

        yield return(null);
    }
Пример #11
0
    // Performs user recognition
    private IEnumerator DoUserRecognition()
    {
        // Get the image to detect
        faces      = null;
        texCamShot = null;

        if (cameraShot)
        {
            texCamShot = (Texture2D)cameraShot.texture;
            SetHintText("Wait...");
        }

        // Get the user manager instance
        CloudUserManager userManager = CloudUserManager.Instance;

        if (!userManager)
        {
            if (hintText)
            {
                hintText.text = "Check if the CloudFaceManager and CloudUserManager components exist in the scene.";
            }
        }
        else if (texCamShot)
        {
            byte[] imageBytes = texCamShot.EncodeToJPG();
            yield return(null);

            AsyncTask <bool> taskIdentify = new AsyncTask <bool>(() => {
                bool bSuccess = userManager.IdentifyUsers(imageBytes, ref faces, ref results);
                return(bSuccess);
            });

            taskIdentify.Start();
            yield return(null);

            while (taskIdentify.State == TaskState.Running)
            {
                yield return(null);
            }

            if (string.IsNullOrEmpty(taskIdentify.ErrorMessage))
            {
                if (taskIdentify.Result)
                {
                    CloudFaceManager.DrawFaceRects(texCamShot, faces, FaceDetectionUtils.FaceColors);
                    yield return(null);

                    SetHintText("Select user to login:"******"No users detected.");
                }

                // show the identified users
                ShowIdentityResult();
            }
            else
            {
                SetHintText(taskIdentify.ErrorMessage);
            }
        }

        yield return(null);
    }
 void Awake()
 {
     instance = this;
 }
Пример #13
0
    // performs face detection
    private IEnumerator DoFaceDetection()
    {
        // get the image to detect
        Face[]    faces      = null;
        Texture2D texCamShot = null;

        if (cameraShot)
        {
            texCamShot = (Texture2D)cameraShot.texture;
            SetHintText("Wait...");
        }

        // get the face manager instance
        CloudFaceManager faceManager = CloudFaceManager.Instance;

        if (!faceManager)
        {
            SetHintText("Check if the FaceManager component exists in the scene.");
        }
        else if (texCamShot)
        {
            byte[] imageBytes = texCamShot.EncodeToJPG();
            yield return(null);

            //faces = faceManager.DetectFaces(texCamShot);
            AsyncTask <Face[]> taskFace = new AsyncTask <Face[]>(() => {
                return(faceManager.DetectFaces(imageBytes));
            });

            taskFace.Start();
            yield return(null);

            while (taskFace.State == TaskState.Running)
            {
                yield return(null);
            }

            if (string.IsNullOrEmpty(taskFace.ErrorMessage))
            {
                faces = taskFace.Result;

                if (faces != null && faces.Length > 0)
                {
                    // stick to detected face rectangles
                    FaceRectangle[] faceRects = new FaceRectangle[faces.Length];

                    for (int i = 0; i < faces.Length; i++)
                    {
                        faceRects[i] = faces[i].faceRectangle;
                    }

                    yield return(null);

                    // get the emotions of the faces
                    if (recognizeEmotions)
                    {
                        //Emotion[] emotions = faceManager.RecognizeEmotions(texCamShot, faceRects);
                        AsyncTask <Emotion[]> taskEmot = new AsyncTask <Emotion[]>(() => {
                            return(faceManager.RecognizeEmotions(imageBytes, faceRects));
                        });

                        taskEmot.Start();
                        yield return(null);

                        while (taskEmot.State == TaskState.Running)
                        {
                            yield return(null);
                        }

                        if (string.IsNullOrEmpty(taskEmot.ErrorMessage))
                        {
                            Emotion[] emotions = taskEmot.Result;
                            int       matched  = faceManager.MatchEmotionsToFaces(ref faces, ref emotions);

                            if (matched != faces.Length)
                            {
                                Debug.Log(string.Format("Matched {0}/{1} emotions to {2} faces.", matched, emotions.Length, faces.Length));
                            }
                        }
                        else
                        {
                            SetHintText(taskEmot.ErrorMessage);
                        }
                    }

                    CloudFaceManager.DrawFaceRects(texCamShot, faces, FaceDetectionUtils.FaceColors);
                    //SetHintText("Click on the camera image to make a shot");
                    SetHintText(hintMessage);
                    SetResultText(faces);
                }
                else
                {
                    SetHintText("No face(s) detected.");
                }
            }
            else
            {
                SetHintText(taskFace.ErrorMessage);
            }
        }

        yield return(null);
    }