←Select platform

DetectLanguages Method

Summary
Detects the language of the page from a list of languages that is provided by the user.
Syntax
C#
Objective-C
C++/CLI
Python
public string[] DetectLanguages( 
   string[] languages 
) 
- (NSArray<NSNumber *> *)detectLanguages:(NSArray<NSNumber *> *)languages error:(NSError **)error 
array<String^>^ DetectLanguages(  
   array<String^>^ languages 
)  
def DetectLanguages(self,languages): 

Parameters

languages
An array of String objects that contains the names of the languages to check for. The language values used throughout the LEADTOOLS OCR toolkit are string values based on RFC 4646 (Windows Vista and later). The name could be an ISO 639 two-letter lowercase culture code associated with a language or a combination of ISO 630 and ISO 3166 two-letter uppercase subculture codes associated with a country or region.

It is suggested to use few (fewer than 5) languages only. The recognition engine will use all those language dictionaries to recognize the words in the document.

Return Value

An array of String objects that contains the names of the detected page language(s).

Remarks

DetectLanguages is only supported in the LEADTOOLS OCR Module - LEAD Engines.

The page may contain a single language only, but it can be any Latin-alphabet or Asian language.

Note: Automatic detection of Greek and Cyrillic is not proposed.

If the language can not be determined, the language of the previous page will be used.

To improve the detection accuracy, set an array with possible languages to be used, then pass it through the  languages parameter.

Automatic language detection is performed as a relatively fast initial processing step before character recognition. Therefore, the accuracy will dependent on the image quality and many other conditions.

Use the GetSupportedLanguages to obtain a list of the languages supported by the IOcrEngine.

Use the IsLanguageSupported to check if a given language is supported by the IOcrEngine.

Example

This example will detect images with English, French, and German languages.

C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Forms.Common; 
using Leadtools.Document.Writer; 
using Leadtools.WinForms; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
public void DetectLanguagesExample() 
{ 
   string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "OCR1.tif"); 
 
   // Create an instance of the engine 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
   { 
      // Start the engine using default parameters 
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir); 
 
      // Load the TIF file 
      RasterImage rasterImage = ocrEngine.RasterCodecsInstance.Load(tifFileName, 1); 
 
      // Create an OCR page from it 
      using (IOcrPage ocrPage = ocrEngine.CreatePage(rasterImage, OcrImageSharingMode.AutoDispose)) 
      { 
         // Auto detect page language. 
         string[] languages = { "en", "fr", "de" }; 
         string[] pageLanguages = ocrPage.DetectLanguages(languages); 
 
         if (pageLanguages != null && pageLanguages.Length > 0) 
         { 
            Console.WriteLine("Page language(s)"); 
            foreach (string lang in pageLanguages) 
            { 
               // Get the friendly name of this language using the .NET CultureInfo class 
               CultureInfo ci = new CultureInfo(lang); 
               Console.WriteLine("{0}", ci.EnglishName); 
            } 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.4.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Ocr Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.