private async void ButtonAnalyze_ClickedAsync(object sender, EventArgs e)
        {
            // Don't Working
            var level = await EmotionService.GetAverageHappinessScoreAsync(this.speaker.Avatar);

            await DisplayAlert("Happiness Level", EmotionService.GetHappinessMessage(level), "OK");
        }
        public async Task <string> AnalyzeImageAsync(string imageUrl)
        {
            var result = string.Empty;

            try
            {
                using (var client = new HttpClient())
                {
                    var stream = await client.GetStreamAsync(imageUrl);

                    var emotion = await EmotionService.GetAverageHappinessScoreAsync(stream);

                    result = EmotionService.GetHappinessMessage(emotion);
                }
            }
            catch (Exception ex)
            {
                result = "Unable to analyze image";
            }

            //await UserDialogs.Instance.AlertAsync(result);

            //Return the percentage
            return(result);
        }
Exemplo n.º 3
0
 private async void ButtonAnalyze_Clicked(object sender, EventArgs e)
 {
     try
     {
         var level = await EmotionService.GetAverageHappinessScoreAsync(this.speaker.Avatar);
         await DisplayAlert("Happiness Level", EmotionService.GetHappinessMessage(level), "OK");
     }
     catch (Exception ex)
     {
         await Application.Current.MainPage.DisplayAlert("Error!", ex.Message, "OK");
     }
 }
Exemplo n.º 4
0
        public async Task TakePhoto()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                Message = ":(No camera avaialble.";
                IsBusy  = false;
                return;
            }
            try
            {
                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory   = "Sample",
                    Name        = "EmotionCheckPic.jpg",
                    SaveToAlbum = true
                });

                if (file == null)
                {
                    return;
                }

                SelectedImage = ImageSource.FromStream(() =>
                {
                    return(file.GetStream());
                });
                selectedPicStream = file.GetStream();
                var emotion = await EmotionService.GetAverageHappinessScoreAsync(selectedPicStream);

                Message = EmotionService.GetHappinessMessage(emotion);
                file.Dispose();
            }
            catch (Exception ex)
            {
                Message = "Uh oh :( Something went wrong \n " + ex.Message;
                IsBusy  = false;
            }
            finally
            {
                IsBusy = false;
            }
        }
        public async Task <double> TakePhotoAndAnalyzeAsync(bool useCamera = true)
        {
            string          result  = "Error";
            double          emotion = 100.0;
            MediaFile       file    = null;
            IProgressDialog progress;

            try
            {
                await CrossMedia.Current.Initialize();

                if (useCamera)
                {
                    file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        Directory = "Sample",
                        Name      = "face.jpg",
                        PhotoSize = PhotoSize.Medium
                    });
                }
                else
                {
                    file = await CrossMedia.Current.PickPhotoAsync();
                }


                if (file == null)
                {
                    result = "No photo taken.";
                }
                else
                {
                    emotion = await EmotionService.GetAverageHappinessScoreAsync(file.GetStream());

                    result = EmotionService.GetHappinessMessage((float)emotion);
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            //await UserDialogs.Instance.AlertAsync(result);

            emotion = emotion * 100;
            emotion = Math.Round(emotion, 2);
            return(emotion);
        }
        private async Task ProcessPhoto(MediaFile file)
        {
            if (file == null)
            {
                return;
            }

            using (file)
            {
                SelectedImage = ImageSource.FromStream(() => file.GetStream());
                var selectedPicStream = file.GetStream();
                Emotion = await EmotionService.GetAverageHappinessScoreAsync(selectedPicStream);

                Message = EmotionService.GetHappinessMessage(Emotion);
            }
        }
Exemplo n.º 7
0
        public async Task TakePhotoAndAnalyzeAsync(bool useCamera = true)
        {
            string    result = "Error";
            MediaFile file   = null;

            try
            {
                await CrossMedia.Current.Initialize();


                if (useCamera)
                {
                    file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        Directory   = "Samples",
                        Name        = "test.jpg",
                        SaveToAlbum = true
                    });
                }
                else
                {
                    file = await CrossMedia.Current.PickPhotoAsync();
                }


                if (file == null)
                {
                    result = "No photo taken.";
                }
                else
                {
                    var emotion = await EmotionService.GetAverageHappinessScoreAsync(file.GetStream());

                    result = EmotionService.GetHappinessMessage(emotion);
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            await UserDialogs.Instance.AlertAsync(result, "Emotion", "OK");
        }
Exemplo n.º 8
0
        /// <summary>
        /// 사진 찍기 요청
        /// </summary>
        /// <param name="useCamera"></param>
        /// <returns></returns>
        public async Task TakePhotoAndAnalyzeAsync(bool useCamera = true)
        {
            string          result = "Error";
            MediaFile       file   = null;
            IProgressDialog progress;

            try
            {
                // CrossMedia 플러그인을 사용하여 사진찍기
                await CrossMedia.Current.Initialize();

                if (useCamera)
                {
                    file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        Directory = "Sample",
                        Name      = "face.jpg",
                        PhotoSize = PhotoSize.Medium
                    });
                }
                else
                {
                    file = await CrossMedia.Current.PickPhotoAsync();
                }

                if (file == null)
                {
                    result = "No photo taken.";
                }
                else
                {
                    var emotion = await EmotionService.GetAverageHappinessScoreAsync(file.GetStream());

                    result = EmotionService.GetHappinessMessage(emotion);
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            await UserDialogs.Instance.AlertAsync(result);
        }
Exemplo n.º 9
0
        public async Task AnalyzeImageAsync(string imageUrl)
        {
            var result = string.Empty;

            try
            {
                using (var client = new HttpClient())
                {
                    var stream = await client.GetStreamAsync(imageUrl);

                    var emotion = await EmotionService.GetAverageHappinessScoreAsync(stream);

                    result = EmotionService.GetHappinessMessage(emotion);
                }
            }
            catch (Exception ex)
            {
                result = "Unable to analyze image";
            }
        }
Exemplo n.º 10
0
        public async Task SelectPhoto()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                Message = "Permission not granted to photos.";
                IsBusy  = false;
                return;
            }
            try
            {
                var file = await CrossMedia.Current.PickPhotoAsync().ConfigureAwait(true);


                if (file == null)
                {
                    return;
                }
                SelectedImage     = ImageSource.FromStream(() => file.GetStream());
                selectedPicStream = file.GetStream();
                var emotion = await EmotionService.GetAverageHappinessScoreAsync(selectedPicStream);

                Message = EmotionService.GetHappinessMessage(emotion);
                file.Dispose();
            }
            catch (Exception ex)
            {
                Message = "Uh oh :( Something went wrong \n" + ex.Message;
                IsBusy  = false;
            }
            finally
            {
                IsBusy = false;
            }
        }
        public async Task <string> GetEmotion()
        {
            if (IsBusy)
            {
                return(null);
            }

            Exception error = null;

            try
            {
                IsBusy = true;

                IEmotionService emotionService = new EmotionService();

                var score = await emotionService.GetAverageHappinessScoreAsync(SelectedEmployee.Avatar);

                return(emotionService.GetHappinessMessage(score));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error: " + ex);
                error = ex;
            }
            finally
            {
                IsBusy = false;
            }

            if (error != null)
            {
                await Application.Current.MainPage.DisplayAlert("Error!", error.Message, "OK");
            }

            return(null);
        }