async Task TakeOrPickPhoto(bool takePhoto)
        {
            selectedPhoto.Image = null;
            loading             = new LoadingView(UIScreen.MainScreen.Bounds);
            View.Add(loading);

            MediaFile returnedPhoto = null;

            if (takePhoto)
            {
                returnedPhoto = await ps.TakePhoto();
            }
            else
            {
                returnedPhoto = await ps.PickPhoto();
            }

            if (returnedPhoto == null)
            {
                loading.Hide();
                return;
            }

            using (var photoStream = returnedPhoto.GetStream())
            {
                selectedPhoto.Image = new UIImage(NSData.FromStream(photoStream));

                var celebrityStream = new MemoryStream();
                photoStream.Position = 0;
                photoStream.CopyTo(celebrityStream);
                photoStream.Position     = 0;
                celebrityStream.Position = 0;

                var landmarkTask  = vs.FindLandmarks(photoStream);
                var celebrityTask = vs.FindCelebrities(celebrityStream);

                await Task.WhenAll(landmarkTask, celebrityTask);

                var landmarks   = landmarkTask.Result;
                var celebrities = celebrityTask.Result;

                var resultText = landmarks?.Landmarks?.FirstOrDefault()?.Name ??
                                 celebrities?.Celebrities?.FirstOrDefault()?.Name ??
                                 "couldn't figure it out";

                descriptionLabel.Text = resultText;

                //descriptionLabel.Text = landmarks?.Landmarks?.FirstOrDefault()?.Name ?? "that's not a landmark!";
            }

            loading.Hide();
        }
Beispiel #2
0
        async Task TakeOrPickPhoto(bool takePhoto, bool handwrite = false)
        {
            theImage.Image        = null;
            descriptionLabel.Text = "";

            loading = new LoadingView(UIScreen.MainScreen.Bounds);
            View.Add(loading);

            MediaFile photo = null;

            if (takePhoto)
            {
                photo = await ps.TakePhoto();
            }
            else
            {
                photo = await ps.PickPhoto();
            }

            if (photo == null)
            {
                loading.Hide();
                return;
            }

            using (var imageStream = photo.GetStream())
            {
                theImage.Image = new UIImage(NSData.FromStream(imageStream));

                imageStream.Position = 0;

                if (handwrite)
                {
                    await OCRHandwriting(imageStream);
                }
                else
                {
                    await Translate(AppDelegate.CurrentLanguage.LanguageCode, imageStream);
                }
            }

            loading.Hide();
        }
Beispiel #3
0
        async Task HandleCamera(bool shouldTakePhoto)
        {
            theEmotion.Text = "";

            MediaFile photo = null;

            loading = new LoadingView(UIScreen.MainScreen.Bounds);
            View.Add(loading);

            if (shouldTakePhoto)
            {
                photo = await photoService.TakePhoto();
            }
            else
            {
                photo = await photoService.PickPhoto();
            }

            if (photo == null)
            {
                loading.Hide();
                return;
            }

            using (var photoStream = photo.GetStream())
            {
                var oldImage = new UIImage(NSData.FromStream(photoStream));
                personPhoto.Image = oldImage;

                var allRecognizedEmotions = await emotionService.RecognizeEmotions(photoStream);

                DrawEmotionsOnImage(oldImage, allRecognizedEmotions);

                var firstEmotion = allRecognizedEmotions?.FirstOrDefault()?.GetMainEmotion() ?? "";
                theEmotion.Text = firstEmotion;
            }

            askForHelp.Hidden = false;
            loading.Hide();
        }
Beispiel #4
0
        async Task TakeOrPickPhoto(bool takePhoto)
        {
            selectedPhoto.Image = null;
            loading             = new LoadingView(UIScreen.MainScreen.Bounds);
            View.Add(loading);

            MediaFile returnedPhoto = null;

            if (takePhoto)
            {
                returnedPhoto = await ps.TakePhoto();
            }
            else
            {
                returnedPhoto = await ps.PickPhoto();
            }

            if (returnedPhoto == null)
            {
                loading.Hide();
                return;
            }

            using (var photoStream = returnedPhoto.GetStream())
            {
                selectedPhoto.Image = new UIImage(NSData.FromStream(photoStream));

                photoStream.Position = 0;

                var landmarks = await vs.DescribePhoto(photoStream);

                descriptionLabel.Text = landmarks?.Landmarks?.FirstOrDefault()?.Name ?? "that's not a landmark!";
            }

            loading.Hide();
        }