async Task <List <Face> > HandleBase64Image(string base64, Texture2D tex) { EmotionSDK.SetEmotionCheck(true); EmotionSDK.SetDirectionCheck(true); // 检测表情 var task = await EmotionSDK.CheckAsync(base64); return(task); }
void HandleBase64Image(string base64) { EmotionSDK.SetEmotionCheck(true); EmotionSDK.SetDirectionCheck(true); // 检测表情 EmotionSDK.CheckAsync(base64).ContinueWith(task => { // 任务返回一个字典, 使用 task.Result 访问 Debug.Log($"[C#] complete"); var faceList = task.Result; var faceCount = faceList.Count; Debug.Log($"face count: {faceCount}"); }); }
void HandleBase64Image(string base64) { EmotionSDK.SetEmotionCheck(true); EmotionSDK.SetDirectionCheck(true); // 检测表情 EmotionSDK.CheckAsync(base64).ContinueWith(task => { // 任务返回一个字典, 使用 task.Result 访问 // 字典包含 EmotionType.cs 中每一项表情 // 对应值为各表情的权重 // * 识别失败时返回 null Debug.Log($"[C#] complete"); // Debug.Log($"Love: {task.Result?["Love"]}"); var json = CustomLitJson.JsonMapper.Instance.ToJson(task.Result); Debug.Log(json); }); }
void Start() { // 获得图片的 base64 数据 var imageBase64Data = GameManifestManager.Get("image"); EmotionSDK.SetEmotionCheck(true); EmotionSDK.SetDirectionCheck(true); // 检测表情 EmotionSDK.CheckAsync(imageBase64Data).ContinueWith(task => { // 任务返回一个字典, 使用 task.Result 访问 // 字典包含 EmotionType.cs 中每一项表情 // 对应值为各表情的权重 // * 识别失败时返回 null Debug.Log($"[C#] complete"); // Debug.Log($"Love: {task.Result?["Love"]}"); var json = CustomLitJson.JsonMapper.Instance.ToJson(task.Result); Debug.Log(json); }); }
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); }); }
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); }
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); }); }