Exemplo n.º 1
0
    // display results
    private void SetResultText(Face[] faces)
    {
        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);
        }
    }
    void OnGUI()
    {
        // set gui font
        GUI.skin.font = hintText ? hintText.GetComponent <GUIText>().font : GUI.skin.font;

        if (faces != null && faces.Length > 0)
        {
            Rect guiResultRect = new Rect(Screen.width / 2, 20, Screen.width / 2, Screen.height - 20);
            GUILayout.BeginArea(guiResultRect);
            scroll = GUILayout.BeginScrollView(scroll);

            Color[]  faceColors     = FaceDetectionUtils.FaceColors;
            string[] faceColorNames = FaceDetectionUtils.FaceColorNames;

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

                Color  faceColor     = faceColors[i % faceColors.Length];
                string faceColorName = faceColorNames[i % faceColors.Length];

                Color guiColor = GUI.color;
                GUI.color = faceColor;

                string sRes = FaceDetectionUtils.FaceToString(face, faceColorName);

                GUILayout.Label(sRes);

                GUI.color = guiColor;
            }

            GUILayout.EndScrollView();
            GUILayout.EndArea();
        }
    }
Exemplo n.º 3
0
    // Imports image and displays it on the camera-shot object
    private bool DoImageImport()
    {
        Texture2D tex = FaceDetectionUtils.ImportImage();

        if (!tex)
        {
            return(false);
        }

        SetShotImageTexture(tex);

        return(true);
    }
    // imports image and displays it on the camera-shot object
    private bool DoImageImport()
    {
        Texture2D tex = FaceDetectionUtils.ImportImage();

        if (tex && cameraShot)
        {
            cameraShot.GetComponent <Renderer>().material.mainTexture = tex;

            Vector3 localScale = cameraShot.transform.localScale;
            localScale.x = (float)tex.width / (float)tex.height * Mathf.Sign(localScale.x);
            cameraShot.transform.localScale = localScale;

            return(true);
        }

        return(false);
    }
Exemplo n.º 5
0
    // display results
    private void SetResultText(Face[] faces)
    {
        StringBuilder sbResult = new StringBuilder();
        int           maxWidth = 0;
        Face          closer   = null;
        int           closerId = 0;
        string        c        = "";

        if (faces != null && faces.Length > 0)
        {
            for (int i = 0; i < faces.Length; i++)
            {
                Face face = faces[i];
                if (face.faceRectangle.width > maxWidth)
                {
                    closer   = faces [i];
                    maxWidth = face.faceRectangle.width;
                    closerId = 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));
            }
            if (faces[closerId] != null)
            {
                Face   face          = faces [closerId];
                string faceColorName = FaceDetectionUtils.FaceColorNames[closerId];
                string res           = FaceDetectionUtils.FaceToString(face, faceColorName)[0];
                c = FaceDetectionUtils.FaceToString(face, faceColorName) [1];

                sbResult.Append(string.Format("<color={0}>{1}</color>", faceColorName, res));
            }
        }

        string result = sbResult.ToString();



        Debug.Log(c);
        string[] separators = new string[1];
        separators[0] = "-";
        string[] categoryString = c.Split(separators, System.StringSplitOptions.None);
        int      category       = 35;

        //Debug.Log (categoryString[0]);
        if (connection)
        {
            category = CSVreader.GetComponent <CsvTest>().categoryToColumn(categoryString [0]);
        }
        bool isage = false;
        //Debug.Log (categoryString.Length);
        //Debug.Log (categoryString[1]);


        string message = CSVreader.GetComponent <CsvTest> ().getMessage(category);

        if (categoryString.Length > 1)
        {
            //Debug.Log ("is age");
            isage   = true;
            message = message.Replace("(age)", categoryString [1]);
        }
        //message = message.ToLower();
        GameObject dummy = GameObject.Find("fortuneText");

        if (dummy != null)
        {
            dummy.GetComponent <Text> ().text = message;

            //dummy.GetComponent<Text> ().text = "You’re looking good and feeling young on Wednesday even though you're in late 50s. That new shirt will earn you some free drinks and envious glares from everyone in the office.";
        }
        if (resultText)
        {
            resultText.text = result;
            //resultText.text = faces[0].ToString();
            if (closer != null)
            {
                //resultText.text = "Closer face is: "+ closer.faceAttributes.gender;
            }
        }
        else
        {
            Debug.Log(result);
        }
    }