ImageGear .NET v24.12 - Updated
Automatically Detect Languages
User Guide > How to Work with... > OCR > How to... > Automatically Detect Languages

In addition to explicitly recognizing pages in different languages, ImageGear also has the ability to detect a page’s language. This can be done in two ways:

Calling the Preprocess Method on ImGearRecImage

Calling the Preprocess method on ImGearRecImage will report the page’s most prominent language in the DetectedLanguages property of the parent ImGearRecPage of the image. This is currently limited to returning a single language. The detected language can then be manually enabled later to perform OCR normally.

C#
Copy Code
using (ImGearRecognition recognitionEngine = new ImGearRecognition())
{
    using (ImGearRecPage page = recognitionEngine.ImportPage(rasterPage))
    {
        page.Image.Preprocess();
        
        // Enable only the found languages before calling Recognize.
        recognitionEngine.Recognition.LanguageEnabled.DisableAll();
        foreach(ImGearRecLanguage language in page.DetectedLanguages)
        {
           recognitionEngine.Recognition.LanguageEnabled[language] = true; 
        }

        page.Recognize();
    }
}
VB.NET
Copy Code
Using recognitionEngine As New ImGearRecognition()
 Using page As ImGearRecPage = recognitionEngine.ImportPage(rasterPage)
  page.Image.Preprocess()

  ' Enable only the found languages before calling Recognize.
  recognitionEngine.Recognition.LanguageEnabled.DisableAll()
  For Each language As ImGearRecLanguage In page.DetectedLanguages
   recognitionEngine.Recognition.LanguageEnabled(language) = True
  Next

  page.Recognize()
 End Using
End Using

Enabling SingleLanguageDetection Property on ImGearRecRecognitionSettings

If you enable the SingleLanguageDetection property on ImGearRecRecognitionSettings before calling recognition, the OCR engine will detect the single most prominent language automatically when performing OCR normally.

C#
Copy Code
using(ImGearRecognition recognitionEngine = new ImGearRecognition())
{
    using (ImGearRecPage page = recognitionEngine.ImportPage(rasterPage))
    {
        recognitionEngine.Recognition.SingleLanguageDetection = true;  
        page.Recognize();
    }   
}
VB.NET
Copy Code
Using recognitionEngine As New ImGearRecognition()
 Using page As ImGearRecPage = recognitionEngine.ImportPage(rasterPage)
  recognitionEngine.Recognition.SingleLanguageDetection = True
  page.Recognize()
 End Using
End Using