private List <DetailRow> ResultToDetailRowList(ImitateResult result) { var ret = new List <DetailRow>(); foreach (var item in result.itemList) { var title = ImitateTranslateService.GetTextByIndex(item.index); Debug.Log($"title: {item.index} -> {title}"); var likely = ImitateManager.RateSignleItem01(item.target, item.input); Debug.Log($"likely: {item.target} : {item.input} -> {likely}"); var row = new DetailRow(); row.title = title; row.percent = likely; ret.Add(row); } return(ret); }
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); }