コード例 #1
0
        void Play(object sender, RoutedEventArgs args)
        {
            ToggleButton tb = (ToggleButton)sender;

            Console.WriteLine((bool)tb.IsChecked);
            if ((bool)tb.IsChecked)
            {
                if (m_firstPlay)
                {
                    m_firstPlay = false;
                    DetectedResult emotion = getBestValue(m_averageEmotion);
                    Mood           mood    = emotion.toMood();
                    m_currentMood = mood;
                    ResetPlaylist(mood);
                    Track  track = m_songQueue.Dequeue();
                    String uri   = m_videoPath + track.id + ".mp3";
                    Log("First song: " + uri);
                    m_player.URL = uri;
                    m_player.controls.play();
                    m_songQueue.Enqueue(track);
                }
                m_player.controls.play();
            }
            else
            {
                m_player.controls.pause();
            }
        }
コード例 #2
0
        // Called every 5 seconds
        private void Timer_handle(object sender, EventArgs e)
        {
            IWMPControls controls = m_player.controls;

            WebcamCtrl.TakeSnapshot();
            m_imagePath = m_picturesDefaultPath;
            scan();

            // We need to check if the mood needs to be switched
            if (controls.currentItem != null &&
                controls.currentItem.duration - controls.currentPosition < 10.0)
            {
                DetectedResult emotion = getBestValue(m_averageEmotion);
                Mood           mood    = emotion.toMood();

                if (mood != m_currentMood)
                {
                    m_currentMood = mood;
                    ResetPlaylist(mood);
                }
            }

            if (controls.currentItem != null &&
                controls.currentItem.duration - controls.currentPosition < 2.0)
            {
                Track  track = m_songQueue.Dequeue();
                String uri   = m_videoPath + track.id + ".mp3";
                Log("Playing song: " + uri);
                m_player.URL = uri;
                controls.play();
                m_songQueue.Enqueue(track);
                // Box with artist and title track.artist and track.sonh
            }
        }
コード例 #3
0
        private DetectedResult getBestValue(Scores faceResult, bool printInfo = false)
        {
            List <float> values = new List <float>(8);

            values.Add(faceResult.Anger);
            values.Add(faceResult.Contempt);
            values.Add(faceResult.Disgust);
            values.Add(faceResult.Fear);
            values.Add(faceResult.Happiness);
            values.Add(faceResult.Neutral);
            values.Add(faceResult.Sadness);
            values.Add(faceResult.Surprise);

            List <DetectedResult> emotionResults = new List <DetectedResult>(values.Count);

            for (int i = 0; i < values.Count; ++i)
            {
                emotionResults.Add(new DetectedResult((EmotionEnum)(i + 1), values[i]));
            }
            emotionResults.Sort();


            int j = emotionResults.Count - 1;

            if (printInfo)
            {
                analysisResult.Content = "Detected emotion: " + emotionResults[j].emotion.ToString() +
                                         "\nValue: " + emotionResults[j].value.ToString();
                Log("Detected emotion: " + emotionResults[j].emotion.ToString());
            }

            DetectedResult res   = new DetectedResult();
            bool           found = false;

            while (!found && j >= emotionResults.Count - 3)
            {
                res = emotionResults[j];
                if (res.emotion != EmotionEnum.CONTEMPT && res.emotion != EmotionEnum.DISGUST &&
                    res.emotion != EmotionEnum.FEAR)
                {
                    found = true;
                }
                --j;
            }

            return(res);
        }