Exemple #1
0
        /// <summary>
        /// Takes the picture. This is a variation from the CameraPage example.
        /// In this version, we need to return the Path to the file, since we need
        /// that path to attach it to the email.
        /// </summary>
        /// <returns>Take Picture Task.</returns>
        private async Task <MediaFile> TakePicture()
        {
            SetupCamera();

            return(await _mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400 }).ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    Status = t.Exception.InnerException.ToString();
                }
                else if (t.IsCanceled)
                {
                    Status = "Canceled";
                }
                else
                {
                    var mediaFile = t.Result;

                    _path = mediaFile.Path;

                    Status = string.Format("Path: {0}", _path);

                    return mediaFile;
                }

                return null;
            }, _scheduler));
        }
Exemple #2
0
        /// <summary>
        //kes the picture.
        /// </summary>

        // <returns>Take Picture Task.</returns>
        public async Task <MediaFile> TakePicture()
        {
            Setup();

            //_imageSource = null;

            return(await _mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400 }).ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    _status = t.Exception.InnerException.ToString();
                }
                else if (t.IsCanceled)
                {
                    _status = "Canceled";
                }
                else
                {
                    var mediaFile = t.Result;

                    //_imageSource = ImageSource.FromStream(() => mediaFile.Source);

                    return mediaFile;
                }

                return null;
            }, _scheduler));
        }
Exemple #3
0
        /// <summary>
        /// Takes the picture.
        /// </summary>
        /// <returns>Take Picture Task.</returns>
        private async Task <MediaFile> TakePicture()
        {
            Setup();

            ImageSource = null;

            return(await _mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400 }).ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    Status = t.Exception.InnerException.ToString();
                }
                else if (t.IsCanceled)
                {
                    Status = "Canceled";
                }
                else
                {
                    var mediaFile = t.Result;

                    ImageSource = ImageSource.FromStream(() => mediaFile.Source);
                    FileStream fs = new FileStream(mediaFile.Path, FileMode.Open, FileAccess.Read);
                    byte[] ImageData = new byte[fs.Length];
                    fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
                    fs.Close();
                    imageString = Convert.ToBase64String(ImageData);

                    return mediaFile;
                }

                return null;
            }, _scheduler));
        }
Exemple #4
0
        private async void TakePicture()
        {
            IsRunning = true;
            var resourceManager = Resource.ResourceManager;

            try
            {
                var    date      = DateTime.Now;
                string fullName  = "Subien-" + date.Minute + "-" + date.Hour + "-" + date.Day + "-" + Convert.ToString(this.Images.Count() + 1) + ".jpg";
                var    mediaFile = await mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions
                {
                    DefaultCamera     = CameraDevice.Front,
                    MaxPixelDimension = 400,
                    Name = fullName
                });

                var result = utilities.ImageData(mediaFile.Path, utilities.Path, fullName, 1062, 597);
                if (!result)
                {
                    await dialogService.ShowMessage(resourceManager.GetString("TakePictureTitle"), resourceManager.GetString("TakePicture"), resourceManager.GetString("ConfirmMessageAcept"));
                }
                string fullpath = utilities.Path + "/" + fullName;
                await SavePhoto(fullName, fullpath);
                await AddImageToList(fullName, fullpath);
            }
            catch (System.Exception ex)
            {
                await dialogService.ShowMessage(resourceManager.GetString("TakePictureTitle"), resourceManager.GetString("TakePicture"), resourceManager.GetString("ConfirmMessageAcept"));
            }
            IsRunning = false;
        }
Exemple #5
0
        /// <summary>c
        /// Takes the picture.
        /// </summary>
        /// <returns>Take Picture Task.</returns>
        private async Task <MediaFile> TakePicture()
        {
            try
            {
                Setup();

                //ImageSource = null;

                return(await _mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400 }).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        Status = t.Exception.InnerException.ToString();
                    }
                    else if (t.IsCanceled)
                    {
                        Status = "Canceled";
                    }
                    else
                    {
                        var mediaFile = t.Result;

                        ImageSource = ImageSource.FromStream(() => mediaFile.Source);
                        this.ImagenArray = ReadToEnd(mediaFile.Source);
                        return mediaFile;
                    }

                    return null;
                }, _scheduler));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        async Task TakePicture()
        {
            Setup();

            ImageSource = null;

            await _mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400 }).ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    var s = t.Exception.InnerException.ToString();
                }

                else if (t.IsCanceled)
                {
                    var canceled = true;
                }

                else
                {
                    var mediaFile = t.Result;
                    ImageSource   = ImageSource.FromStream(() => mediaFile.Source);

                    return(mediaFile);
                }

                return(null);
            }, _scheduler);
        }
Exemple #7
0
        async void btnTakePicture_Clicked(object sender, EventArgs e)
        {
            var mediaFile = await mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions
            {
                DefaultCamera     = CameraDevice.Rear,
                MaxPixelDimension = 400
            });

            Debug.WriteLine($"picture path : {mediaFile.Path}");

            imgPhoto.Source = mediaFile.Path;
        }
Exemple #8
0
        async void ScanTextBtn_Clicked(object sender, EventArgs e)
        {
            scanTextBtn.IsEnabled = false;
            mainPageBtn.IsEnabled = false;
            resultLabel.Text      = "Opening camera. Might take a while so please be patient!";
            originalPhoto.Source  = "";

            //tesseractille whitelist sallituista merkeistä
            //tesseractApi.SetVariable("tessedit_char_whitelist", "012345789()/-+*");

            //kameran käyttöön optiot HUOM! pienentäminen ei toimi näissä kuin windowsilla
            var options = new CameraMediaStorageOptions {
                DefaultCamera = CameraDevice.Rear
            };

            MediaFile picture = await mediaPicker.TakePhotoAsync(options);

            resultLabel.Text = "Processing image and recognizing text..";
            if (picture != null && picture.Source != null)
            {
                bool readSuccess = await imageParser.parseTextFromImageASync(picture);

                if (readSuccess)
                {
                    originalPhoto.Source = ImageSource.FromStream(() => picture.Source);

                    string calculation = imageParser.returnParsedText();

                    //tässä rajoitetaan laskutoimituksen pituus
                    if (calculation.Length <= 10)
                    {
                        //HUOM! tässä ei tarkisteta menevää stringiä mitenkään joten ohjelma kaatuu jos sinne pääsee mitäsattuu läpi
                        string result = CalculateString(calculation);
                        resultLabel.Text = calculation + " = " + result;
                    }

                    //jos ei saada järkevää stringiä luettua ts. siitä tulee aivan liian pitkä niin =>
                    else
                    {
                        resultLabel.Text = "OCR result unclear, please try again.";
                    }
                }
            }
            scanTextBtn.IsEnabled = true;
            mainPageBtn.IsEnabled = true;
            scanTextBtn.Text      = "Calculate again";
        }
        public async Task <MediaFile> TakePhotoFromCamera()
        {
            try
            {
                return(await
                       _mediaPicker.TakePhotoAsync(
                           new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400 }).ContinueWith(
                           t =>
                {
                    var mediaFile = t.Result;
                    return mediaFile;
                }));
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(null);
        }
Exemple #10
0
        public async Task <MediaFile> TakePicture()
        {
            var cmso = new CameraMediaStorageOptions
            {
                DefaultCamera      = CameraDevice.Rear,
                SaveMediaOnCapture = false
            };

            return(await m_MediaPicker.TakePhotoAsync(cmso).ContinueWith(t =>
            {
                if (t.IsCompleted &&
                    t.Status == TaskStatus.RanToCompletion)
                {
                    var mediaFile = t.Result;
                    return mediaFile;
                }

                return null;
            }, m_Scheduler));
        }
Exemple #11
0
        private async Task TakePicture()
        {
            mediaPicker = DependencyService.Get <IMediaPicker>();

            imageSource = null;

            try
            {
                var mediaFile = await mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions
                {
                    DefaultCamera     = CameraDevice.Front,
                    MaxPixelDimension = 400
                });

                imageSource = ImageSource.FromStream(() => mediaFile.Source);
                img.Source  = imageSource;
            }
            catch (System.Exception ex)
            {
                this.status = ex.Message;
            }
        }
        async void AnalyzeAction()
        {
            try
            {
                //TODO:check if camera etc os available media.phot etc.

                var options = new CameraMediaStorageOptions()
                {
                    SaveMediaOnCapture = false,
                };
                var result = await mediaPicker.TakePhotoAsync(options);

                var data = receiptAnalyser.Analyse(result.Source);
                ShoppingItems = new ObservableCollection <ShoppingItem>(data);
                ;
            }
            catch (Exception ex)
            {
                logger.Log(ex.Message + ex.StackTrace, Category.Exception, Priority.Medium);
                await pageDialogService.DisplayAlertAsync(locale.RUnknownErrorTitle, locale.RUnknonwnMessage, locale.RUnknownErrorConfirm);
            }
        }
        private async Task TakePhotoAsync()
        {
            IsBusy = true;

            var visionService     = ViewModelLocator.VisionServiceClient;
            var translatorService = ViewModelLocator.TranslatorService;

            string recognizeText = null;

            try
            {
                using (var stream = await mediaPicker.TakePhotoAsync())
                {
                    if (stream != null)
                    {
                        var imageBytes = await stream.ToArrayAsync();

                        MessengerInstance.Send(new NotificationMessage <byte[]>(imageBytes, Constants.PhotoTaken));
                        Message = null;

                        if (await Network.IsInternetAvailableAsync())
                        {
                            var results = await visionService.RecognizeTextAsync(stream);

                            var text = results.GetRecognizedText();

                            if (string.IsNullOrWhiteSpace(text))
                            {
                                recognizeText = AppResources.UnableToRecognizeText;
                            }
                            else
                            {
                                recognizeText = text;
                            }
                        }
                        else
                        {
                            // Internet isn't available, the service cannot be reached.
                            recognizeText = AppResources.NoConnection;
                        }
                    }
                    else
                    {
                        // If message is null at this point, this is the first request. If we cancel it, turns automatically to the
                        // previous page.
                        if (message == null)
                        {
                            Navigator.GoBack();
                        }

                        IsBusy = false;
                        return;
                    }
                }
            }
            catch (WebException)
            {
                // Internet isn't available, the service cannot be reached.
                recognizeText = AppResources.NoConnection;
            }
            catch (ClientException)
            {
                // Unable to access the service (tipically, due to invalid registration keys).
                recognizeText = AppResources.UnableToAccessService;
            }
            catch (Exception ex)
            {
                var error = AppResources.RecognitionError;

                if (Settings.ShowExceptionOnError)
                {
                    error = $"{error} ({ex.Message})";
                }

                recognizeText = error;
            }

            // Shows the result.
            Message = this.GetNormalizedMessage(recognizeText);
            IsBusy  = false;
        }
        private async Task TakePhotoAsync()
        {
            IsBusy = true;

            string recognizeText = null;

            try
            {
                using (var stream = await mediaPicker.TakePhotoAsync())
                {
                    if (stream != null)
                    {
                        var imageBytes = await stream.ToArrayAsync();

                        MessengerInstance.Send(new NotificationMessage <byte[]>(imageBytes, Constants.PhotoTaken));
                        Message = null;

                        if (await NetworkService.IsInternetAvailableAsync())
                        {
                            var result = await cognitiveClient.AnalyzeAsync(stream, Language, RecognitionType.Text);

                            var ocrResult = result.OcrResult;

                            if (ocrResult.ContainsText)
                            {
                                recognizeText = ocrResult.Text;
                            }
                            else
                            {
                                recognizeText = AppResources.UnableToRecognizeText;
                            }
                        }
                        else
                        {
                            // Internet isn't available, the service cannot be reached.
                            recognizeText = AppResources.NoConnection;
                        }
                    }
                    else
                    {
                        // If message is null at this point, this is the first request. If we cancel it, turns automatically to the
                        // previous page.
                        if (message == null)
                        {
                            AppNavigationService.GoBack();
                        }

                        IsBusy = false;
                        return;
                    }
                }
            }
            catch (CognitiveException ex)
            {
                // Unable to access the service (message contains translated error details).
                recognizeText = ex.Message;
            }
            catch (WebException)
            {
                // Internet isn't available, the service cannot be reached.
                recognizeText = AppResources.NoConnection;
            }
            catch (Exception ex)
            {
                var error = AppResources.RecognitionError;

                if (Settings.ShowExceptionOnError)
                {
                    error = $"{error} ({ex.Message})";
                }

                recognizeText = error;
            }

            // Shows the result.
            Message = this.GetNormalizedMessage(recognizeText);
            IsBusy  = false;
        }
        private async void GetPhotoButton_OnClicked(object sender, EventArgs e)
        {
            var result = await _mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions());

            await Recognise(result);
        }