Emotion APIによって返された結果を表示するのに問題があります。結果はEmotion []の形式で返されます。コードは次のとおりですProject OxfordのEmotion APIの結果をC#で表示する
private async void button2_Click(object sender, EventArgs e)
{
try
{
pictureBox2.Image = (Bitmap)pictureBox1.Image.Clone();
String s = System.Windows.Forms.Application.StartupPath + "\\" + "emotion.jpg";
pictureBox2.Image.Save(s);
string imageFilePath = s;// System.Windows.Forms.Application.StartupPath + "\\" + "testing.jpg";
Uri fileUri = new Uri(imageFilePath);
BitmapImage bitmapSource = new BitmapImage();
bitmapSource.BeginInit();
bitmapSource.CacheOption = BitmapCacheOption.None;
bitmapSource.UriSource = fileUri;
bitmapSource.EndInit();
// _emotionDetectionUserControl.ImageUri = fileUri;
// _emotionDetectionUserControl.Image = bitmapSource;
System.Windows.MessageBox.Show("Detecting...");
***Emotion[] emotionResult*** = await UploadAndDetectEmotions(imageFilePath);
System.Windows.MessageBox.Show("Detection Done");
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString());
}
}
と私は、さまざまな感情の結果から最も支配的な感情を見つける必要があります。
Emotion APIのサンプルファイル内でこれらのクラス定義を見つけましたが、問題をDictionaryまたはinbuiltコマンドでもリストに変換できませんでした。私は、Microsoft.ProjectOxford.Emotion.Contractファイルのクラス定義と矛盾することなく回避する必要があると思います。 –
Scottの提案はかなり良いですが、すでにクライアントSDKを使用している場合は、Emotion []を文字列にシリアル化して_other_ Emotion []に戻します。別のオプションは次のようなものです: '' var top = emotions.Select(感情=> { var dict = new Dictionary(); foreach(typeof(スコア)の.GetProperties() ) {dict.Add(property.Name、(フロート)property.GetValue(emotion.Scores));} リターンdict.OrderByDescending(KV => kv.Value).ThenBy(KV => kv.Key ).First(); }); '' –
cthrash
@ScottHannen私のプロジェクトは助けてくれてありがとうございます:) –