Пример #1
0
    void detectface(byte[] inArray)
    {
        showlog("数组长度 " + inArray.Length);

        string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
        string        methodName = "youtu/api/detectface";
        StringBuilder postData   = new StringBuilder();
        string        pars       = "\"app_id\":\"" + Conf.Instance().APPID +
                                   "\",\"image\":\"" + Convert.ToBase64String(inArray.ToArray()) +
                                   "\",\"mode\":1";

//        pars = string.Format(pars, Conf.Instance().APPID, Utility.ImgBase64(path));
        postData.Append("{");
        postData.Append(pars);
        postData.Append("}");
        string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

        showlog("http 请求完成" + " 长度" + result.Length);

        print(result);
        YouTuResponseData tData = YouTuResponseData.fromJson(result);

        showlog(JsonUtility.ToJson(tData));
        if (tData != null && tData.errorcode == 0)
        {
            try
            {
                jumpToStep2();
                txtPoints.text = tData.face[0].beauty.ToString();
                txtAge.text    = tData.face[0].age.ToString();
                string strMotion = "";
                int    exp       = tData.face[0].expression;
                if (exp < 30)
                {
                    strMotion = "黯然伤神";
                }
                else if (exp > 30 && exp < 70)
                {
                    strMotion = "微微一笑";
                }
                else
                {
                    strMotion = "开怀大笑";
                }
                txtMotion.text = strMotion;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
    }
    void faceDetectedHandler(string result)
    {
        YouTuResponseData tData = YouTuResponseData.fromJson(result);

        showlog(JsonUtility.ToJson(tData));
        if (tData != null && tData.errorcode == 0)
        {
            try
            {
                //测试
                //tData.face[0].beauty = 71;
                if (tData.face[0].beauty > 98)
                {
                    tData.face[0].beauty = 98;
                }

                txtPoints.text = tData.face[0].beauty.ToString();
                txtAge.text    = tData.face[0].age.ToString();
                string strMotion = "";
                int    exp       = tData.face[0].expression;
                if (exp < 30)
                {
                    strMotion = "黯然伤神";
                }
                else if (exp > 30 && exp < 70)
                {
                    strMotion = "微微一笑";
                }
                else
                {
                    strMotion = "开怀大笑";
                }
                txtMotion.text = strMotion;

                //评语
                txtComments.text = commentCon.GetCommentText(tData.face[0].beauty);
                //播放对应的声音
                commentCon.PlayCommentSound(tData.face[0].beauty);

                ShowRewards(tData.face[0].beauty);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }