Exemple #1
0
    void Update()
    {
        // rawImage 使用照相机返回贴图的尺寸
        this.RawImage_moniter.SetNativeSize();

        // rawImage 旋转角修正
        var t = this.RawImage_moniter.texture as WebCamTexture;
        var v = new Vector3();

        v.z = -t.videoRotationAngle;
        this.RawImage_moniter.rectTransform.localEulerAngles = v;

        // rawImage 需要缩放以铺满屏幕
        var rawImageFinalSize = new Vector2(t.height, t.width);
        var canvas            = UIEngine.Canvas;
        var canvasTransform   = canvas.GetComponent <RectTransform>();
        var canvasSize        = canvasTransform.sizeDelta;
        var scale             = ImitateUtil.GetScaleLetRectACoverRectB(rawImageFinalSize, canvasSize);

        this.RawImage_moniter.rectTransform.localScale = new Vector2(scale, scale);

        // 镜像修正
        if (!this.isFronCamera)
        {
            var s = this.RawImage_moniter.rectTransform.localScale;
            this.RawImage_moniter.rectTransform.localScale = new Vector2(s.x, -s.y);
        }

        // 安卓修正
        if (Application.platform == RuntimePlatform.Android)
        {
            var s = this.RawImage_moniter.rectTransform.localScale;
            this.RawImage_moniter.rectTransform.localScale = new Vector2(s.x, -s.y);
        }
    }
Exemple #2
0
    public void DebugCom()
    {
        if (Application.isEditor)
        {
            //var t = m_local_tex;
            //var texture = ImitateUtil.OrientQuick(t, t.videoRotationAngle);
            ////Debug.Log("原图大小" + texture.height + " " + texture.width);
            // texture = ImitateUtil.CompassPic(texture,2);
            ////Debug.Log("压图大小" + texture.height + " " + texture.width);
            ///
            // 预览修正后的贴图
            // moniter.texture = m_local_tex;
            var texture = ImitateUtil.OrientQuickDebug(m_local_tex);
            texture.Apply();
            moniter_ref.texture = texture;
            //CheckFace(texture);
        }

        else
        {
            var t = moniter.texture as WebCamTexture;
            Debug.Log("原图大小" + t.height + " " + t.width);
            var texture = ImitateUtil.OrientQuick(t, t.videoRotationAngle);
            Debug.Log("压图大小" + texture.height + " " + texture.width);
            ////Debug.Log("压图大小" + texture.height + " " + texture.width);
            // 预览修正后的贴图
            CheckFace(texture);
            texture.Apply();
            if (moniter_ref.texture == null)
            {
                moniter_ref.texture = texture;
            }
        }
    }
Exemple #3
0
    private async void SavePhotoAsync()
    {
        var texture = RawImage_preview.texture as Texture2D;
        var base64  = ImitateUtil.TextureToBase64(texture);
        await Photo.SaveAsync(base64);

        ImitateUIService.Dialog("已保存");
    }
Exemple #4
0
    private async void UseAlbumAsync()
    {
        var base64 = await Photo.SelectAsync();

        var texture = ImitateUtil.Base64ToTexture(base64);

        ImitateManager.input = texture;
        var page = UIEngine.Forward <ImitateResultPage>();

        page.SetImage(texture);
        page.PlayFlash();
    }
Exemple #5
0
    public void SetImage(Texture2D texture)
    {
        RawImage_preview.texture = texture;
        RawImage_preview.SetNativeSize();

        // 计算 rawImage 需要缩放的尺寸
        var textureSize = new Vector2(texture.width, texture.height);
        var holderSize  = PlaceHolder.sizeDelta;
        var scale       = ImitateUtil.GetScaleLetRectACoverRectB(textureSize, holderSize);

        RawImage_preview.rectTransform.localScale = new Vector2(scale, scale);
    }
Exemple #6
0
    void Update()
    {
        if (Application.isEditor)
        {
            return;
        }
        // rawImage 使用照相机返回贴图的尺寸
        moniter.SetNativeSize();

        // rawImage 旋转角修正
        var t = moniter.texture as WebCamTexture;
        var v = new Vector3();

        v.z = -t.videoRotationAngle;
        moniter.rectTransform.localEulerAngles = v;

        // rawImage 需要缩放以铺满屏幕
        var rawImageFinalSize = new Vector2(t.height, t.width);
        var canvas            = UIEngine.Canvas;
        var canvasTransform   = canvas.GetComponent <RectTransform>();
        var canvasSize        = canvasTransform.sizeDelta;
        var scale             = ImitateUtil.GetScaleLetRectACoverRectB(rawImageFinalSize, canvasSize);

        moniter.rectTransform.localScale = new Vector2(scale, scale);

        // 安卓修正
        if (Application.platform == RuntimePlatform.Android)
        {
            var s = moniter.rectTransform.localScale;
            moniter.rectTransform.localScale = new Vector2(s.x, -s.y);
        }

        //return;

        if (m_need_adjust)
        {
            m_down_time -= Time.deltaTime;
            if (m_down_time <= 0.0f)
            {
                m_down_time = -1.0f;
                button_go.SetActive(true);
            }
            m_indev_tick -= Time.deltaTime;
            if (m_indev_tick <= 0.0f)
            {
                m_indev_tick = 2.0f;
                //Shot();
            }
        }
    }
    private async void SavePhotoAsync()
    {
        // get image on result page
        var resultPage = UIEngine.FindInStack <ImitateResultPage>();

        if (resultPage == null)
        {
            return;
        }
        var texture = resultPage.GetImage();
        var base64  = ImitateUtil.TextureToBase64(texture);
        await Photo.SaveAsync(base64);

        ImitateUIService.Dialog("已保存");
    }
    public async void OnShoot()
    {
        for (int i = 0; i < UIObjects.Length; i++)
        {
            UIObjects[i].SetActive(false);
        }
        SmileProject.Instance.PlaySe("flash");

        Texture2D tex = null;


        if (camAvailable)
        {
            tex = ImitateUtil.Orient(backCam, backCam.videoRotationAngle, m_is_front);
            //tex = WebCamUtil.TakePictureFromCamera (SmileProject.Instance.Camera);
        }
        else
        {
            tex = DefaultPic;
        }

        m_loading             = true;
        loading_tiper.enabled = true;

        if (backCam != null)
        {
            backCam.Pause();
        }
        //SmileProject.Instance.LutifyComp.Blend = 0;


        var result = await HandleBase64Image(WebCamUtil.TextureToBase64(tex), tex);


        var resultPage = SimplePageManager.Instance.Show("SmileResultPage") as SmileResultPage;

        resultPage.SetInfo(MakeScore(result[0].emotion), tex, result[0].emotion);

        //logBuilder.Clear ();
        //for (int i = 0; i < result[0].emotion.Count; i++) {
        //    logBuilder.Append (EmotionSDK.GetEmotionTypeNameByIndex (i));
        //    logBuilder.Append ( ": " );
        //    logBuilder.AppendLine (result[0].emotion[i].ToString ());
        //}
        //Debug.Log (logBuilder.ToString ());
    }
Exemple #9
0
    public void SetImage(Texture2D texture)
    {
        // 设置按原始尺寸显示
        RawImage_preview.texture = texture;
        RawImage_preview.SetNativeSize();

        // 计算 rawImage 需要缩放的尺寸
        var textureSize = new Vector2(texture.width, texture.height);
        var holderSize  = PreviewRectHolder.sizeDelta;
        var scale       = ImitateUtil.GetScaleLetRectACoverRectB(textureSize, holderSize);

        RawImage_preview.rectTransform.localScale = new Vector2(scale, scale);

        // 对齐显示区域
        var pos = PreviewRectHolder.position;

        RawImage_preview.rectTransform.position = pos;
    }
Exemple #10
0
    public void CheckFace(Texture2D input)
    {
        m_check_lock = true;
        var inputBase64 = ImitateUtil.TextureToBase64(input);

        EmotionSDK.CheckAsync(inputBase64).ContinueWith(task => {
            m_check_lock = false;
            if (task.Result.Count <= 0)
            {
                return;
            }
            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);
            HotDotData.MinOffset = Mathf.Min(_offset, HotDotData.MinOffset);
            HotDotData.MaxOffset = Mathf.Max(_offset, HotDotData.MaxOffset);
            Debug.Log("Min:" + HotDotData.MinOffset + " Max:" + HotDotData.MaxOffset);
        });
    }
Exemple #11
0
 public void Shot()
 {
     if (Application.platform != RuntimePlatform.OSXEditor)
     {
         if (m_check_lock)
         {
             Debug.Log("AI LOCKING");
             return;
         }
         var t       = moniter.texture as WebCamTexture;
         var texture = ImitateUtil.OrientQuick(t, t.videoRotationAngle);
         CheckFace(texture);
     }
     else
     {
         return;
         // 如果是测试模式,使用源图片作为输入图片
         // input = ImitateManager.origin;
     }
 }
Exemple #12
0
    private void Shot()
    {
        Texture2D input;

        if (Application.platform != RuntimePlatform.OSXEditor)
        {
            var t       = this.RawImage_moniter.texture as WebCamTexture;
            var texture = ImitateUtil.Orient(t, t.videoRotationAngle, this.isFronCamera);
            // 预览修正后的贴图
            RawImage_fixed.texture = texture;
            input = texture;
        }
        else
        {
            // 如果是测试模式,使用源图片作为输入图片
            input = ImitateManager.origin;
        }
        ImitateManager.input = input;
        var page = UIEngine.Forward <ImitateResultPage>();

        page.SetImage(input);
        page.PlayFlash();
    }
Exemple #13
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);
    }
Exemple #14
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);
        });
    }