Click or drag to resize
TesseractOcrEngineInitializeEngine Method
Initializes the OCR engine with the language dictionary.

Namespace: DevScope.Ocr.Tesseract.WindowsPhone
Assembly: DevScope.Ocr.Tesseract.WindowsPhone (in DevScope.Ocr.Tesseract.WindowsPhone.dll) Version: 255.255.255.255
Syntax
public bool InitializeEngine(
	string tessdataRootPath,
	string lang
)

Parameters

tessdataRootPath
Type: SystemString
The tessdataRootPath must be the name of the parent directory of tessdata and must end in '/'. Any name after the last '/' will be stripped.
lang
Type: SystemString
The language to use (language dictionary first 3 chars). The language is(usually) an ISO 639 - 3 string or NULL will default to eng.

Return Value

Type: Boolean
True if successfull otherwise False
Remarks

InitializeEngine starts the tesseract ocr engine.

It is entirely safe(and eventually will be efficient too) to call Init multiple times on the same instance to change language, or just to reset the classifier.

The lang parameter may be a string of the form[~]<lang>[+[~]<lang>] * indicating that multiple languages are to be loaded.Eg hin + eng will load Hindi and English.

Languages may specify internally that they want to be loaded with one or more other languages, so the ~sign is available to override that.Eg if hin were set to load eng by default, then hin + ~eng would force loading only hin.The number of loaded languages is limited only by memory, with the caveat that loading additional languages will impact both speed and accuracy, as there is more work to do to decide on the applicable language, and there is more chance of hallucinating incorrect words.

WARNING: On changing languages, all Tesseract parameters are reset back to their default values. (Which may vary between languages.) If you have a rare need to set a Variable that controls initialization for a second call to Init you should explicitly call End() and then use SetVariable before Init.This is only a very rare use case, since there are very few uses that require any parameters to be set before Init.

Examples
This sample shows how to instantiate using InitializeEngine and call the DoOcrAsync method.
void RunOcrEngine(...)  
{ 
   ... 
   var ocrEngine = new TesseractOcrEngine();
   ocrEngine.InitializeEngine(tessdataRootFolder.Path, languageCode);

   // Create the ocr job request
   var request = new TesseractOcrJobRequest
   {
       JobName = "MyJob " + DateTime.Now.ToString()
   };

   // Create the doOcr operation by specifiying a filename that holds the image 
   var operationDoOcr = ocrEngine.DoOcrAsync(request, CommonSettings.FileNameFullResImageSentToOcr);


   // 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