Ejemplo n.º 1
0
        private void UpdateFaceFrame()
        {
            var emotionDet = this.SenseManager.QueryEmotion();
            if (emotionDet != null)
            {
                //SenceManagerモジュールの顔のデータを更新する
                this.FaceData.Update();

                //それぞれの顔ごとに情報取得および描画処理を行う
                for (int index = 0; index <= this.FaceData.QueryNumberOfDetectedFaces() - 1; index++)
                {
                    var face = this.FaceData.QueryFaceByIndex(index);
                    if (face != null)
                    {
                        //追加:ここからが表情(Emotion)認識
                        //追加:感情のデータを得る
                        PXCMEmotion.EmotionData[] datas;
                        emotionDet.QueryAllEmotionData(index, out datas);
                        //追加:表情(PRIMARY)を推定する
                        if (datas != null)
                        {
                            int primaryDataInxex = int.MinValue;
                            float maxscoreI = 0;
                            for (var emotionIndex = 0; emotionIndex <= NUM_PRIMARY_EMOTIONS - 1; emotionIndex++)
                            {
                                if (datas[emotionIndex].intensity > maxscoreI)
                                {
                                    maxscoreI = datas[emotionIndex].intensity;
                                    primaryDataInxex = emotionIndex;
                                }
                            }
                            if (primaryDataInxex >=0)
                            {
                                this.Result = new TResult
                                {
                                    Face = primaryDataInxex,
                                    Score = (int)Math.Truncate((maxscoreI * 100))
                                };
                            }
                        }

                        //表情の強さが取得できていたら感情値も設定する
                        if (Result != null)
                        {
                            //追加:感情(Sentiment)を推定する
                            //表情(PRIMARY)の推定と同様なので、コメントは省略
                            int primaryDataInxex = int.MinValue;
                            float maxscoreI = 0;
                            for (var sentimentIndex = NUM_PRIMARY_EMOTIONS;
                                sentimentIndex <= NUM_PRIMARY_EMOTIONS + NUM_SENTIMENT_EMOTIONS - 1;
                                sentimentIndex++)
                            {
                                if (datas[sentimentIndex].intensity > maxscoreI)
                                {
                                    maxscoreI = datas[sentimentIndex].intensity;
                                    primaryDataInxex = sentimentIndex - NUM_PRIMARY_EMOTIONS;
                                }
                            }
                            if (primaryDataInxex >= 0)
                            {
                                this.Result.Sentiment = primaryDataInxex;
                                this.Result.SScore = (int)Math.Truncate((maxscoreI * 100));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void RSStop()
 {
     this.Timer.Stop();
     this.SenseManager.Dispose();
     this.Result = null;
     this.ColorImageElement = null;
 }