TesseractOcrEngineInitializeEngine Method |
Namespace: DevScope.Ocr.Tesseract.WindowsPhone
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.
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; } } }