Click or drag to resize
TesseractOcrEngineDoOcrAsync Method (TesseractOcrJobRequest, String)
Executes an instance (job) of the OCR engine over the image file stored in 'filename' with the specified settings present in the TesseractOcrJobRequest in an Asynchronous way, preventing blocking of the main thread.

Namespace: DevScope.Ocr.Tesseract.WindowsPhone
Assembly: DevScope.Ocr.Tesseract.WindowsPhone (in DevScope.Ocr.Tesseract.WindowsPhone.dll) Version: 255.255.255.255
Syntax
public IAsyncOperationWithProgress<TesseractOcrJobResponse, TesseractOcrProgressEventArgs> DoOcrAsync(
	TesseractOcrJobRequest request,
	string filename
)

Parameters

request
Type: DevScope.Ocr.Tesseract.WindowsPhoneTesseractOcrJobRequest
The job request settings.
filename
Type: SystemString
The absolute path of the filename containing the image to OCR. The supported image formats are bmp,tif,png and jpg.

Return Value

Type: IAsyncOperationWithProgressTesseractOcrJobResponse, TesseractOcrProgressEventArgs
The results of the OCR process.
Remarks

Starting from version 2.0 of the SDK, you must specify the absolute path of the image to OCR in the filename parameter. In the previous versions it was assumed that the filename was relative to the app LocalFolder.

Regarding the tif format we do not support multi-page documents.

Examples
This sample shows how to call the DoOcrAsync method.
void RunOcrEngine()  
{ 
   ... 
   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 by specifiying a filename that holds the image 
   // Please note that the filename must be absolute path
   var ocrImageFile=Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path,CommonSettings.FileNameFullResImageSentToOcr);
   var operationDoOcr = ocrEngine.DoOcrAsync(request, ocrImageFile);

   // 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;
        }
   }
}
See Also