←Select platform

DetectLanguage Method

Summary
Detects the language used in the specified IOcrPage from a list of languages that is provided by the user.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public int DetectLanguage( 
   IOcrPage page, 
   string[] languages, 
   int[] confidences, 
   int minimumConfidence 
) 
- (NSUInteger)detectLanguage:(LTOcrPage *)page  
                   languages:(NSArray<NSNumber *> *)languages  
                 confidences:(NSArray<NSNumber *> * _Nullable * _Nullable)confidences  
           minimumConfidence:(NSUInteger)minimumConfidence  
                       error:(NSError **)error 
public int detectLanguage(OcrPage page, 
                          String[] languages, 
                          int[] confidences, 
                          int minimumConfidence) 
int DetectLanguage(  
   IOcrPage^ page, 
   array<String^>^ languages, 
   array<int>^ confidences, 
   int minimumConfidence 
)  
def DetectLanguage(self,page,languages,confidences,minimumConfidence): 

Parameters

page
The IOcrPage for which to detect its language.

languages
An array of String objects that contains the names of the languages for which to check. The language values used throughout the LEADTOOLS OCR toolkit are string values based on RFC 5646. These string values for the languages and their abbreviations are based on the ISO 639-1 language code list. To see the specific languages supported by the LEADTOOLS OCR SDKs, refer to OCR Languages and Spell-Checking for the lists.

confidences
An array of Int32 objects updated with the confidences of the languages. The array size must be equivalent to the number of items in the  languages array. When set to null it will be ignored. The confidence value range is between -1 and 100. A value of -1 means the language is not supported, 0 means it is not confident, and 100 is completely confident.

minimumConfidence
The minimum confidence value at which point to stop checking other languages. If a language's confidence value is equal to or higher than the  minimumConfidence value the language check can be stopped.

Return Value

The index of the language with the highest confidence in the  languages parameter.

Remarks

This method is only supported by the LEADTOOLS OCR Module - LEAD Engine.

Zone language detection is a dictionary-based method. The confidence of a language without a dictionary is low. If a language does not have a dictionary installed, then that language will not be detected and the default (main) language will be used to recognize the text. For example, Asian languages such as Chinese, Japanese and Korean do not have dictionaries. If an Asian language text is present in the input image, then you should set the desired language as the default (main) language in the OCR engine in order to recognize text with the highest accuracy. To determine whether a given spell language (dictionary) is supported by the current spell checker engine use IsSpellLanguageSupported. In order to get a list of the languages (dictionaries) supported by the current spell checker engine use GetSupportedSpellLanguages. For more information on OCR languages and spell checkers, refer to IOcrLanguageManager and IOcrSpellCheckManager.

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

Use the IsLanguageSupported to determine whether a given language is supported by the IOcrEngine.

Example

This example will OCR images for English, French, or German text.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
 
private void DetectLanguageExample(IOcrEngine engine, IOcrPage page) 
{ 
   string[] languages = new string[3]; 
   languages[0] = "en"; 
   languages[0] = "fr"; 
   languages[0] = "de"; 
   int[] confidences = new int[languages.Length]; 
   int maxIndex = engine.LanguageManager.DetectLanguage(page, languages, confidences, 90); 
   if (maxIndex == -1) 
      Console.WriteLine("No language has been detected"); 
   else 
      Console.WriteLine("The page language with the highest confidence is: " + languages[maxIndex] + ", with confidence: " + confidences[maxIndex]); 
   for (int i = 0; i < languages.Length; i++) 
      Console.WriteLine("Language: " + languages[i] + ", with confidence: " + confidences[i]); 
} 
 
import java.util.ArrayList; 
import java.util.Locale; 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.ocr.*; 
 
 
public void DetectLanguageExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   final String LEAD_VARS_OCR_DIR = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime"; 
   RasterCodecs codecs = new RasterCodecs(); 
   OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
   ocrEngine.startup(codecs, null, null, LEAD_VARS_OCR_DIR); 
   assertTrue("OCR engine is not started", ocrEngine.isStarted()); 
 
   // Prepare page to be recognized 
   OcrDocument ocrDocument = ocrEngine.getDocumentManager().createDocument(); 
   RasterImage image = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf")); 
   OcrPage page = ocrDocument.getPages().addPage(image, null); 
       
   // Set language recognition preferences 
   String[] languages = new String[3]; 
   languages[0] = "en"; 
   languages[1] = "fr"; 
   languages[2] = "de"; 
   int[] confidences = new int[languages.length]; 
 
   // Detect the language 
   int maxIndex = ocrEngine.getLanguageManager().detectLanguage(page, languages, confidences, 90); 
       
   // Print results 
   if (maxIndex == -1) { 
      System.out.println("No language has been detected"); 
   } else 
      System.out.println("The page language with the highest confidence is: " + languages[maxIndex] 
            + ", with confidence: " + confidences[maxIndex]); 
   for (int i = 0; i < languages.length; i++) 
      System.out.println("Language: " + languages[i] + ", with confidence: " + confidences[i]); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.3.3
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.