TesseractOcrEngineDoOcrAsync Method (TesseractOcrJobRequest, Int32, Int32, Int32) |
Namespace: DevScope.Ocr.Tesseract.WindowsPhone
public IAsyncOperationWithProgress<TesseractOcrJobResponse, TesseractOcrProgressEventArgs> DoOcrAsync( TesseractOcrJobRequest request, int pixelWidth, int pixelHeight, int[] pixels )
void RunOcrEngineByWritableBitmap() { ... var ocrEngine = new TesseractOcrEngine(tessdataRootFolder.Path, languageCode); // Create the ocr job request var request = new TesseractOcrJobRequest { OrientationMode = TesseractOcrOrientationMode.None, JobName = "MyJob " + DateTime.Now.ToString(), PageSegmentationMode = TesseractOcrPageSegmentationMode.AutomaticPageSegmentationNoOCR }; request.ImagePreProcessing.AutoDeskew = true; request.ImagePreProcessing.AutoDespeckle = true; request.ImagePreProcessing.UseLocalAdaptiveThresholding = true; // Create the doOcr operation var imgBitmapToOcr = await ImageUtils.LoadImageFromIsolatedStorageAsync(CommonSettings.FileNameFullResImageSentToOcr); WriteableBitmap wb = new WriteableBitmap(imgBitmapToOcr); var operationDoOcr = ocrEngine.DoOcrAsync(request, wb.PixelWidth, wb.PixelHeight, wb.Pixels); // setup progress handler operationDoOcr.Progress = new AsyncOperationProgressHandler<TesseractOcrJobResponse, TesseractOcrProgressEventArgs>((operation, report) = > { if (_cancelCurrentOcrJob) report.Cancel = true; Dispatcher.BeginInvoke(() = > { pbar.Value = report.Percent; }); }); // now, run the ocr and get the results var jobResponse = await operationDoOcr; // handle the results accordingly switch (jobResponse.Status) { case TesseractOcrResultStatus.Error: { MessageBox.Show(_ocrJobResponse.ErrorMessage, "Ocr Error", MessageBoxButton.OK); break; } case TesseractOcrResultStatus.InvalidLicense: { MessageBox.Show("INVALID LICENSE. Please contact Devscope Support.", "Ocr Error", MessageBoxButton.OK); break; } case TesseractOcrResultStatus.Ok: { textOcr.Text = jobResponse.Text; break; } } }