Esempio n. 1
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);
    }
Esempio n. 2
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);
    }
    // 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);
    }
    // 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);
    }