Пример #1
0
    public override void OnNavigatedTo()
    {
        m_need_adjust = true;
        if (Application.isEditor)
        {
            button_go.SetActive(true);
        }
        else
        {
            button_go.SetActive(false);
            CreateCameraTextureForRawImage(moniter);
            EmotionSDK.SetDirectionCheck(false);
            EmotionSDK.SetEmotionCheck(false);
            m_down_time = 3.0f;
        }



        //button_go.SetActive(true);
    }
Пример #2
0
 public override void OnNavigatedTo()
 {
     base.OnNavigatedTo();
     EmotionSDK.InitDetection();
     EmotionSDK.OpenDetection();
 }
Пример #3
0
 public override void OnNavigatedFrom()
 {
     EmotionSDK.CloseDetection();
 }
Пример #4
0
    public static async Task <ImitateResult> RateAsync()
    {
        EmotionSDK.SetDirectionCheck(false);
        EmotionSDK.SetEmotionCheck(true);
        var originBase64 = ImitateUtil.TextureToBase64(origin);
        var inputBase64  = ImitateUtil.TextureToBase64(input);
        // 检查原图片
        List <float> emotionOrigin;
        {
            List <Face> result = null;
            // var t = new Thread(async()=>{
            //     result = await EmotionSDK.CheckAsync(originBase64);
            // });
            // t.Start();
            // while(result == null)
            // {
            //     await Task.Delay(1);
            // }
            result = await EmotionSDK.CheckAsync(originBase64);

            if (result.Count == 0)
            {
                throw new Exception("face not found in origin image");
            }
            emotionOrigin = result[0].emotion;
        }
        // 检查输入图片
        List <float> emotionInput;
        {
            List <Face> result = null;
            // var t = new Thread(async()=>{
            //     result = await EmotionSDK.CheckAsync(inputBase64);
            // });
            // t.Start();
            // while(result == null)
            // {
            //     await Task.Delay(1);
            // }
            result = await EmotionSDK.CheckAsync(inputBase64);

            if (result.Count == 0)
            {
                throw new Exception("face not found in input image");
            }
            emotionInput = result[0].emotion;
        }
        // 选取前5项数值
        var indexList   = FindBigestIndex(emotionOrigin, 2);
        var pickedListA = PickByIndex(emotionOrigin, indexList);
        var pickedListB = PickByIndex(emotionInput, indexList);

        // log
        LogList(pickedListA);
        LogList(pickedListB);

        // make score
        var score = CalcuScoreV3(pickedListA, pickedListB);

        // return
        var ret = new ImitateResult();

        ret.score    = score;
        ret.itemList = new List <ImitateItem>();
        for (int i = 0; i < indexList.Count; i++)
        {
            var index  = indexList[i];
            var target = pickedListA[i];
            var input  = pickedListB[i];
            var item   = new ImitateItem();
            item.index  = index;
            item.target = target;
            item.input  = input;
            ret.itemList.Add(item);
        }

        return(ret);
    }
Пример #5
0
    public void CheckFace()
    {
        //m_eat_num++;

        // return;
        //Debug.Log("Time1:"+Time.time);

        var input = ImitateUtil.OrientQuick(m_texture, m_texture.videoRotationAngle);

        //moniter_ref.texture = input;
        //Debug.Log("Time2:" + Time.time);
        // input = ImitateUtil.CompassPic(input,3);
        //Debug.Log("Time3:" + Time.time);

        // Debug.Log("hereB");
        var inputBase64 = ImitateUtil.TextureToBase64(input);

        //Debug.Log("Time4:" + Time.time);

        EmotionSDK.CheckAsync(inputBase64).ContinueWith(task => {
            //Debug.Log("Time5:" + Time.time);

            //Debug.Log("hereC");

            // string _log = "CheckFace " + Time.time;



            float x_dis = task.Result[0].rightMouthCornerPos.x - task.Result[0].leftMouthCornerPos.x;
            float y_dis = task.Result[0].leftMouthCornerPos.y - task.Result[0].leftEyesPos.y;



            float _offset     = Mathf.Abs(y_dis - x_dis);
            float _raw_offset = _offset;


            HotDotData.MinOffset = Mathf.Min(_offset, HotDotData.MinOffset);
            HotDotData.MaxOffset = Mathf.Max(_offset, HotDotData.MaxOffset);

            //_log += _ofsset + "(" + m_offset_min + "," + m_offset_max + ")";


            //Debug.Log("hereD");

            float _value_dis = Mathf.Abs(HotDotData.MaxOffset - _offset) - Mathf.Abs(_offset - HotDotData.MinOffset);


            if (_value_dis > 5)
            {
                // _log += "闭嘴检测 ";
                Debug.Log("闭嘴检测 Raw:" + _raw_offset + " Dis:" + _value_dis + " OffsetMin:" + HotDotData.MinOffset + " OffsetMax:" + HotDotData.MaxOffset + " " + m_open_mouth);
                if (m_open_mouth)
                {
                    m_open_mouth = false;
                    m_eat_num++;
                }
            }
            else if (_value_dis < -5)
            {
                // _log += "张嘴检测 ";
                Debug.Log("张嘴检测 Raw:" + _raw_offset + " Dis:" + _value_dis + " OffsetMin:" + HotDotData.MinOffset + " OffsetMax:" + HotDotData.MaxOffset + " " + m_open_mouth);
                if (!m_open_mouth)
                {
                    m_open_mouth = true;
                    //m_sicong_ani.Play("hot_ani_open");
                    //m_sicong_ani.PlayQueued("hot_ani_open_idle");
                }
            }
            float _new_max = HotDotData.MaxOffset - Mathf.Max(Mathf.Abs(HotDotData.MaxOffset * 0.1f), 1.0f);
            if (_new_max > HotDotData.MinOffset)
            {
                HotDotData.MaxOffset = _new_max;
            }
            float _new_min = HotDotData.MinOffset + Mathf.Max(Mathf.Abs(HotDotData.MaxOffset * 0.1f), 1.0f);
            if (_new_min < HotDotData.MaxOffset)
            {
                HotDotData.MinOffset = _new_min;
            }

            // Debug.Log(_log);
        });
    }