public void ShowDocumentViewController() { var cameraViewController = new VNDocumentCameraViewController { Delegate = this }; PresentViewController(cameraViewController, true, null); }
public void DidFinish(VNDocumentCameraViewController controller, VNDocumentCameraScan scan) { var pageCount = (int)scan.PageCount; var allItems = new List <List <string> >(); for (int i = 0; i < pageCount; i++) { var image = scan.GetImage(nuint.Parse(i.ToString())); var imageRequestHandler = new VNImageRequestHandler(image.CGImage, options: new NSDictionary()); var textRequest = new VNRecognizeTextRequest(new VNRequestCompletionHandler((request, error) => { var results = request.GetResults <VNRecognizedTextObservation>(); foreach (var result in results) { var items = new List <string>(); foreach (var candidate in result.TopCandidates(100)) { items.Add(candidate.String); } allItems.Add(items); } Device.BeginInvokeOnMainThread(() => { _page.LoadRecognizedTextItems(allItems); DismissViewController(true, null); }); })); switch (_page.TextRecognitionLevel) { case TextRecognitionLevelEnum.Accurate: textRequest.RecognitionLevel = VNRequestTextRecognitionLevel.Accurate; break; case TextRecognitionLevelEnum.Fast: textRequest.RecognitionLevel = VNRequestTextRecognitionLevel.Fast; break; default: break; } textRequest.UsesLanguageCorrection = true; DispatchQueue.DefaultGlobalQueue.DispatchAsync(() => { imageRequestHandler.Perform(new VNRequest[] { textRequest }, out NSError error); }); } }
public override void ViewDidAppear(bool animated) { var documentCameraController = new VNDocumentCameraViewController(); var documentscanDelegate = new DocumentScanDelegate(); documentscanDelegate.OnScanTaken += (VNDocumentCameraScan scan) => { documentCameraController.DismissViewController(true, null); Debug.WriteLine($"{scan.PageCount} Pages!"); }; documentscanDelegate.OnCanceled += () => { documentCameraController.DismissViewController(true, null); }; documentCameraController.Delegate = documentscanDelegate; documentCameraController.ModalPresentationStyle = UIModalPresentationStyle.OverFullScreen; PresentViewController(documentCameraController, true, null); }
public void DidCancel(VNDocumentCameraViewController controller) { DismissViewController(true, null); }
public override void DidFail(VNDocumentCameraViewController controller, NSError error) { Debug.WriteLine("Failed scanning photo"); }
public override void DidFinish(VNDocumentCameraViewController controller, VNDocumentCameraScan scan) { Debug.WriteLine("DocumentScanDelegate:DidFinish"); OnScanTaken(scan); }
public override void DidCancel(VNDocumentCameraViewController controller) { Debug.WriteLine("DocumentScanDelegate:DidCancel"); OnCanceled(); }