void UseTextRecognitionModel() { VisionTextRecognizer textRecognizer; if (currentApiResource == ApiResource.OnDevice) { textRecognizer = vision.GetOnDeviceTextRecognizer(); } else { // To provide language hints to assist with language detection: // See https://cloud.google.com/vision/docs/languages for supported languages var options = new VisionCloudTextRecognizerOptions { LanguageHints = new [] { "es" } }; textRecognizer = vision.GetCloudTextRecognizer(options); } var image = new VisionImage(ImgSample.Image); textRecognizer.ProcessImage(image, HandleVisionTextRecognitionCallback); void HandleVisionTextRecognitionCallback(VisionText text, NSError error) { TxtData.Text = error?.Description ?? text?.Text; } }
/// <summary> /// <see cref="LabelReaderBase.GetFullTextFromImage(object)"/> /// </summary> /// <param name="image"></param> /// <returns></returns> public override async Task <string> GetFullTextFromImageAsync(object image) { CoreMedia.CMSampleBuffer iOSImage = (CoreMedia.CMSampleBuffer)image; VisionImage visionImage = new VisionImage(iOSImage); visionImage.Metadata = new VisionImageMetadata { Orientation = GetOrientation() }; VisionApi api = VisionApi.Create(); VisionTextRecognizer textRecognizer = api.GetOnDeviceTextRecognizer(); VisionText textResult = await textRecognizer.ProcessImageAsync(visionImage); return(textResult?.Text); }