Log() публичный Метод

public Log ( string message ) : void
message string
Результат void
        private async Task <Emotion[]> UploadAndDetectEmotions(string url)
        {
            MainWindow window          = (MainWindow)Application.Current.MainWindow;
            string     subscriptionKey = window.ScenarioControl.SubscriptionKey;

            // -----------------------------------------------------------------------
            // Parte 2
            // -----------------------------------------------------------------------

            window.Log("EmotionServiceClient iniciado");

            //
            // Crie uma chamada para Project Oxford Emotion API Service client
            //


            window.Log("Iniciando EmotionServiceClient.RecognizeAsync()...");
            try
            {
                //
                // Crie URL para detectar Emotions
                //
            }
            catch (Exception exception)
            {
                window.Log("Analise falhou. Por favor verifique a sua assinatura ou o log");
                window.Log(exception.ToString());
                return(null);
            }
            // -----------------------------------------------------------------------
            // Parte 2
            // -----------------------------------------------------------------------
        }
        private async void LoadImageButton_Click(object sender, RoutedEventArgs e)
        {
            string     urlString       = URLTextBox.Text;
            Uri        uri             = new Uri(urlString, UriKind.Absolute);
            MainWindow window          = (MainWindow)Application.Current.MainWindow;
            string     subscriptionKey = window.ScenarioControl.SubscriptionKey;

            window.ScenarioControl.ClearLog();

            //
            // Load image from URL for information purpose. This is not used in emotion detection
            //
            var bitmapSource = new BitmapImage();

            bitmapSource.BeginInit();
            bitmapSource.UriSource = uri;
            bitmapSource.EndInit();

            _emotionDetectionUserControl.ImageUri = uri;
            _emotionDetectionUserControl.Image    = bitmapSource;

            _detectionStatus.Text = "Detecting...";

            Emotion[] emotionResult = await UploadAndDetectEmotions(urlString);

            _detectionStatus.Text = "Detection Done";
            //
            // Log detection result in the log window
            //
            window.Log("");
            window.Log("Detection Result:");
            window.LogEmotionResult(emotionResult);

            _emotionDetectionUserControl.Emotions = emotionResult;
        }
        private void LogVideoFragments()
        {
            MainWindow window = (MainWindow)Application.Current.MainWindow;

            window.Log("Emotion recognition results:");
            window.Log(Newtonsoft.Json.JsonConvert.SerializeObject(_videoResult));
        }
Пример #4
0
        private async Task <Emotion[]> UploadAndDetectEmotions(string imageFilePath)
        {
            MainWindow window          = (MainWindow)Application.Current.MainWindow;
            string     subscriptionKey = window.ScenarioControl.SubscriptionKey;

            window.Log("EmotionServiceClient iniciado");

            // -----------------------------------------------------------------------
            // Parte 3
            // -----------------------------------------------------------------------

            //
            // Crie o cliente service
            //


            window.Log("Calling EmotionServiceClient.RecognizeAsync()...");
            try
            {
                //Crie Load da imagem
            }
            catch (Exception exception)
            {
                window.Log(exception.ToString());
                return(null);
            }
            // -----------------------------------------------------------------------
            // Parte 3
            // -----------------------------------------------------------------------
        }
Пример #5
0
        private async void LoadImageButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow window = (MainWindow)Application.Current.MainWindow;

            Microsoft.Win32.OpenFileDialog openDlg = new Microsoft.Win32.OpenFileDialog();
            openDlg.Filter = "JPEG Image(*.jpg)|*.jpg";
            bool?result = openDlg.ShowDialog(window);

            if (!(bool)result)
            {
                return;
            }

            string imageFilePath = openDlg.FileName;
            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;

            //
            // Enviando a imagem
            //
            window.ScenarioControl.ClearLog();
            _detectionStatus.Text = "Detectando...";

            //Crie envio da imagem


            _detectionStatus.Text = "Finalizada...";

            //
            // Log
            //
            window.Log("");
            window.Log("Detection Result:");
            window.LogEmotionResult(emotionResult);

            _emotionDetectionUserControl.Emotions = emotionResult;
        }
        private async void LoadImageButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow window = (MainWindow)Application.Current.MainWindow;

            Microsoft.Win32.OpenFileDialog openDlg = new Microsoft.Win32.OpenFileDialog();
            openDlg.Filter = "JPEG Image(*.jpg)|*.jpg";
            bool?result = openDlg.ShowDialog(window);

            if (!(bool)result)
            {
                return;
            }

            string imageFilePath = openDlg.FileName;
            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;

            //
            // Create EmotionServiceClient and detect the emotion with URL
            //
            window.ScenarioControl.ClearLog();
            _detectionStatus.Text = "Detecting...";

            Emotion[] emotionResult = await UploadAndDetectEmotions(imageFilePath);

            _detectionStatus.Text = "Detection Done";

            //
            // Log detection result in the log window
            //
            window.Log("");
            window.Log("Detection Result:");
            window.LogEmotionResult(emotionResult);

            _emotionDetectionUserControl.Emotions = emotionResult;
        }
        /// <summary>
        /// Uploads the image to Project Oxford and detect emotions.
        /// </summary>
        /// <param name="imageFilePath">The image file path.</param>
        /// <returns></returns>
        private async Task <Emotion[]> UploadAndDetectEmotions(string imageFilePath)
        {
            MainWindow window          = (MainWindow)Application.Current.MainWindow;
            string     subscriptionKey = window.ScenarioControl.SubscriptionKey;

            window.Log("EmotionServiceClient is created");

            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE STARTS HERE
            // -----------------------------------------------------------------------

            //
            // Create Project Oxford Emotion API Service client
            //
            EmotionServiceClient emotionServiceClient = new EmotionServiceClient(subscriptionKey);

            window.Log("Calling EmotionServiceClient.RecognizeAsync()...");
            try
            {
                Emotion[] emotionResult;
                using (Stream imageFileStream = File.OpenRead(imageFilePath))
                {
                    //
                    // Detect the emotions in the URL
                    //
                    emotionResult = await emotionServiceClient.RecognizeAsync(imageFileStream);

                    return(emotionResult);
                }
            }
            catch (Exception exception)
            {
                window.Log(exception.ToString());
                return(null);
            }
            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE ENDS HERE
            // -----------------------------------------------------------------------
        }
        /// <summary>
        /// Uploads the image to Project Oxford and detect emotions.
        /// </summary>
        /// <param name="imageFilePath">The image file path.</param>
        /// <returns></returns>
        private async Task <Emotion[]> UploadAndDetectEmotions(string url)
        {
            MainWindow window          = (MainWindow)Application.Current.MainWindow;
            string     subscriptionKey = window.ScenarioControl.SubscriptionKey;

            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE STARTS HERE
            // -----------------------------------------------------------------------

            window.Log("EmotionServiceClient is created");

            //
            // Create Project Oxford Emotion API Service client
            //
            EmotionServiceClient emotionServiceClient = new EmotionServiceClient(subscriptionKey);

            window.Log("Calling EmotionServiceClient.RecognizeAsync()...");
            try
            {
                //
                // Detect the emotions in the URL
                //
                Emotion[] emotionResult = await emotionServiceClient.RecognizeAsync(url);

                return(emotionResult);
            }
            catch (Exception exception)
            {
                window.Log("Dection failed. Please make sure that you have the right subscription key and proper URL to detect.");
                window.Log(exception.ToString());
                return(null);
            }
            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE ENDS HERE
            // -----------------------------------------------------------------------
        }
        /// <summary>
        /// Uploads the video to Project Oxford and detects emotions.
        /// </summary>
        /// <param name="videoFilePath">The video file path.</param>
        /// <returns></returns>
        private async Task <VideoAggregateRecognitionResult> UploadAndDetectEmotions(string videoFilePath)
        {
            MainWindow window          = (MainWindow)Application.Current.MainWindow;
            string     subscriptionKey = window.ScenarioControl.SubscriptionKey;

            window.Log("EmotionServiceClient is created");

            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE STARTS HERE
            // -----------------------------------------------------------------------

            //
            // Create Project Oxford Emotion API Service client
            //
            EmotionServiceClient emotionServiceClient = new EmotionServiceClient(subscriptionKey);

            window.Log("Calling EmotionServiceClient.RecognizeInVideoAsync()...");
            try
            {
                using (Stream videoFileStream = File.OpenRead(videoFilePath))
                {
                    //
                    // Upload the video, and tell the server to start recognizing emotions
                    //
                    window.Log("Start uploading video");
                    VideoEmotionRecognitionOperation videoOperation = await emotionServiceClient.RecognizeInVideoAsync(videoFileStream);

                    window.Log("Finished uploading video");


                    //
                    // Starts querying service status
                    //
                    VideoOperationResult result;
                    while (true)
                    {
                        result = await emotionServiceClient.GetOperationResultAsync(videoOperation);

                        if (result.Status == VideoOperationStatus.Succeeded || result.Status == VideoOperationStatus.Failed)
                        {
                            break;
                        }

                        window.Log(string.Format("Server status: {0}, wait {1} seconds...", result.Status, QueryWaitTime.TotalSeconds));
                        await Task.Delay(QueryWaitTime);
                    }

                    window.Log("Finish processing with server status: " + result.Status);

                    //
                    // Processing finished, checks result
                    //
                    if (result.Status == VideoOperationStatus.Succeeded)
                    {
                        //
                        // Get the processing result by casting to the actual operation result
                        //
                        VideoAggregateRecognitionResult aggregateResult = ((VideoOperationInfoResult <VideoAggregateRecognitionResult>)result).ProcessingResult;
                        return(aggregateResult);
                    }
                    else
                    {
                        // Failed
                        window.Log("Fail reason: " + result.Message);
                    }

                    return(null);
                }
            }
            catch (Exception exception)
            {
                window.Log(exception.ToString());
                return(null);
            }
            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE ENDS HERE
            // -----------------------------------------------------------------------
        }
        private async void LoadImageButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow window = (MainWindow)Application.Current.MainWindow;

            Microsoft.Win32.OpenFileDialog openDlg = new Microsoft.Win32.OpenFileDialog();
            openDlg.Filter = "JPEG Image(*.jpg)|*.jpg";
            bool?result = openDlg.ShowDialog(window);

            if (!(bool)result)
            {
                return;
            }

            string imageFilePath = openDlg.FileName;
            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;

            //
            // Create EmotionServiceClient and detect the emotion with URL
            //
            window.ScenarioControl.ClearLog();
            _detectionStatus.Text = "Detecting...";

            Emotion[] emotionResult = await UploadAndDetectEmotions(imageFilePath);

            _detectionStatus.Text = "Detection Done";

            //
            // Log detection result in the log window
            //
            window.Log("");
            window.Log("Detection Result:");
            window.LogEmotionResult(emotionResult);

            _emotionDetectionUserControl.Emotions = emotionResult;
            //            var success = await System.Windows.Launcher.LaunchUriAsync(uri);

            //resultDisplay[0] = new EmotionResultDisplay { EmotionString = "Anger", Score = emotion.Scores.Anger };
            //resultDisplay[1] = new EmotionResultDisplay { EmotionString = "Contempt", Score = emotion.Scores.Contempt };
            //resultDisplay[2] = new EmotionResultDisplay { EmotionString = "Disgust", Score = emotion.Scores.Disgust };
            //resultDisplay[3] = new EmotionResultDisplay { EmotionString = "Fear", Score = emotion.Scores.Fear };
            //resultDisplay[4] = new EmotionResultDisplay { EmotionString = "Happiness", Score = emotion.Scores.Happiness };
            //resultDisplay[5] = new EmotionResultDisplay { EmotionString = "Neutral", Score = emotion.Scores.Neutral };
            //resultDisplay[6] = new EmotionResultDisplay { EmotionString = "Sadness", Score = emotion.Scores.Sadness };
            //resultDisplay[7] = new EmotionResultDisplay { EmotionString = "Surprise", Score = emotion.Scores.Surprise };

            float  fAnger     = emotionResult[0].Scores.Anger;
            float  fSadness   = emotionResult[0].Scores.Sadness;
            float  fHappiness = emotionResult[0].Scores.Happiness;
            string sSongURL   = "";

            if (fAnger > 0.5)
            {
                // 許如芸 生氣
                sSongURL = "kkbox://play_song_849314";
            }
            if (fSadness > 0.5)
            {
                // 陳珊妮 如同悲傷被下載了兩次
                sSongURL = "kkbox://play_song_77706479";
            }
            if (fHappiness > 0.5)
            {
                // Happy Birthday	寶兒 (BoA)	千顏兒語 (THE FACE)
                sSongURL = "kkbox://play_song_1601466";
            }
            //            var uri = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
            var uri = "D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";

            System.Diagnostics.Process.Start(uri, sSongURL);
        }