async void ScanButtonClicked(object sender, EventArgs args) { ScanButton.IsEnabled = false; ImageProcess img = new ImageProcess(); img = await img.GetImage(); if(img !=null) { if(img.img!=null) { image.Source = img.img; string temp = await img.ProcessImage(img.imgraw); if (temp == null) { CrossTextToSpeech.Current.Speak("I can't connect at the moment, try again!"); return; } var labels = Blindist1.Operations.GetMatch(temp); labels = labels.OrderByDescending(x => x.label_score).ToList(); CrossTextToSpeech.Current.Speak("I guess there is " + labels[0].label_name + " in front of you" + "Also there might be " + labels[1].label_name + " in front of you"); ScanButton.IsEnabled = true; } else { await DisplayAlert("Error", img.error, "Ok"); ScanButton.IsEnabled = true; } } }
public async Task<ImageProcess> GetImage() { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsPickPhotoSupported) { ImageProcess ob = new ImageProcess() { error = "Oh No ! No Camera.. I can't access your camera", imgraw = null, img = null }; return ob; } var file = await CrossMedia.Current.TakePhotoAsync(new Media.Plugin.Abstractions.StoreCameraMediaOptions { Directory = "Sample", Name = "test.jpg" }); if (file == null) return null; var imgrawtemp = new BinaryReader(file.GetStream()).ReadBytes((int)file.GetStream().Length); var image = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return stream; }); ImageProcess temp = new ImageProcess() { imgraw = imgrawtemp, error = "Success", img = image }; return temp; }