Leadtools.Document Deprecated as of v16. Refer to: Leadtools.Forms.Ocr | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
GetRecognizedCharacters Method
See Also  Example
Leadtools.Document Namespace > RasterDocumentEngine Class : GetRecognizedCharacters Method



pageIndex
Specifies the index of the recognized page for which to get the recognized characters. This is a zero-based index
pageIndex
Specifies the index of the recognized page for which to get the recognized characters. This is a zero-based index
Gets all of the characters that have been recognized for a specific page.

Syntax

Visual Basic (Declaration) 
Public Function GetRecognizedCharacters( _
   ByVal pageIndex As Integer _
) As IList(Of RasterDocumentRecognizedCharacters)
Visual Basic (Usage)Copy Code
Dim instance As RasterDocumentEngine
Dim pageIndex As Integer
Dim value As IList(Of RasterDocumentRecognizedCharacters)
 
value = instance.GetRecognizedCharacters(pageIndex)
C# 
public IList<RasterDocumentRecognizedCharacters> GetRecognizedCharacters( 
   int pageIndex
)
C++/CLI 
public:
IList<RasterDocumentRecognizedCharacters>^ GetRecognizedCharacters( 
   int pageIndex
) 

Parameters

pageIndex
Specifies the index of the recognized page for which to get the recognized characters. This is a zero-based index

Return Value

An array of RasterDocumentRecognizedCharacters objects which contains all recognized characters in the specified page

Example

Visual BasicCopy Code
Public Sub GetRecognizedCharactersExample()
   ' Note that this is a sample key, which will not work in your toolkit
   RasterSupport.Unlock(Leadtools.RasterSupportType.Ocr, "TestKey")

   Dim rasterDocument As RasterDocumentEngine
   rasterDocument = RasterDocumentEngine.Instance
   rasterDocument.Startup()
   'assume page is added, refer to AddPage example for more information

   rasterDocument.SpellLanguageId = RasterDocumentLanguage.English
   rasterDocument.RecognitionDataFileName = LeadtoolsExamples.Common.ImagesPath.Path + "test.rdf"

   rasterDocument.Recognize(0, 1, Nothing)

   Dim recognizedChars As IList(Of RasterDocumentRecognizedCharacters) = rasterDocument.GetRecognizedCharacters(0)
   Dim font As RasterDocumentFontFlags
   Dim i As Integer = 0
   Do While i < recognizedChars.Count
      If recognizedChars(i).Confidence > 900 Then
         Dim tmpChar As RasterDocumentRecognizedCharacters = recognizedChars(i)
         font = tmpChar.Font

         font = font Or RasterDocumentFontFlags.Bold Or RasterDocumentFontFlags.Underline
         tmpChar.Font = font
         tmpChar.FontSize = 20

         If (tmpChar.Flags And RasterDocumentCharacterPositionFlags.EndOfWord) = RasterDocumentCharacterPositionFlags.EndOfWord Then
            Dim buffer As String

            buffer = String.Format("Last Character in the word is available at the following position" & Constants.vbLf & "Left = {0}" & Constants.vbLf & "Top = {1}" & Constants.vbLf & "Width = {2}" & Constants.vbLf & "Height = {3}" & Constants.vbLf & "YOffset = {4}", recognizedChars(i).Rectangle.Left, recognizedChars(i).Rectangle.Top, recognizedChars(i).Rectangle.Width, recognizedChars(i).Rectangle.Height, recognizedChars(i).YOffset)
            MessageBox.Show(buffer)

            buffer = String.Format("First guess char = {0}" & Constants.vbLf & "Second guess char = {1}" & Constants.vbLf & "Third guess char = {2}", recognizedChars(i).GuessCode, recognizedChars(i).GuessCode2, recognizedChars(i).GuessCode3)
            MessageBox.Show(buffer)

            buffer = String.Format("First Language Id = {0}" & Constants.vbLf & "Second Language Id = {1}" & Constants.vbLf & "Zone Index = {2}" & Constants.vbLf & "Cell Index = {3}" & Constants.vbLf & "Space = {4}" & Constants.vbLf & "Space Error = {5}", recognizedChars(i).LanguageId2, recognizedChars(i).LanguageId2, recognizedChars(i).ZoneIndex, recognizedChars(i).CellIndex, recognizedChars(i).Space, recognizedChars(i).SpaceError)
            MessageBox.Show(buffer)
         End If

         recognizedChars(i) = tmpChar
      End If
      i += 1
   Loop

   rasterDocument.SetRecognizedCharacters(0, recognizedChars)
   Dim resultOpts As RasterDocumentResultOptions = rasterDocument.SaveResultOptions

   resultOpts.Format = RasterDocumentFormatType.RtfWord2000
   resultOpts.FormatLevel = RasterDocumentFormatLevel.Full

   Dim docOpts As RasterDocumentOptions
   docOpts = resultOpts.Document
   docOpts.PaperSizeMode = RasterDocumentSelector.Predefined
   docOpts.PaperType = RasterDocumentPaperType.A4
   docOpts.PaperOrientation = RasterDocumentPaperOrientation.Portrait
   docOpts.RetainGraphics = RasterDocumentRetainGraphicsMode.Original
   docOpts.TextInboxes = False
   docOpts.Margins = New Rectangle(5, 5, 195, 195)
   docOpts.RetainPageBreaks = True
   docOpts.TableMethod = RasterDocumentTableMethod.UseTabs

   resultOpts.Document = docOpts
   rasterDocument.SaveResultOptions = resultOpts
   rasterDocument.SaveResultsToFile(LeadtoolsExamples.Common.ImagesPath.Path + "Test.doc")

   rasterDocument.Shutdown()
End Sub
C#Copy Code
public void GetRecognizedCharactersExample() 

   //  Note that this is a sample key, which will not work in your toolkit 
   RasterSupport.Unlock(RasterSupportType.Ocr, "TestKey"); 
   RasterDocumentEngine rasterDocument; 
   rasterDocument = RasterDocumentEngine.Instance; 
   rasterDocument.Startup(); 
 
   // assume page is added, refer to AddPage example for more information 
 
   rasterDocument.SpellLanguageId = RasterDocumentLanguage.English; 
   rasterDocument.RecognitionDataFileName = LeadtoolsExamples.Common.ImagesPath.Path + "test.rdf"; 
 
   rasterDocument.Recognize(0, 1, null); 
 
   IList<RasterDocumentRecognizedCharacters> recognizedChars  = rasterDocument.GetRecognizedCharacters(0); 
   RasterDocumentFontFlags font; 
   for(int i = 0; i < recognizedChars.Count; i++) 
   { 
      if (recognizedChars[i].Confidence > 900) 
      { 
         RasterDocumentRecognizedCharacters tmpChar = recognizedChars[i]; 
         font = tmpChar.Font; 
 
         font |= RasterDocumentFontFlags.Bold | RasterDocumentFontFlags.Underline; 
         tmpChar.Font = font; 
         tmpChar.FontSize = 20; 
 
         if ((tmpChar.Flags & RasterDocumentCharacterPositionFlags.EndOfWord) == RasterDocumentCharacterPositionFlags.EndOfWord) 
         { 
            string buffer; 
 
            buffer = String.Format("Last Character in the word is available at the following position\nLeft = {0}\nTop = {1}\nWidth = {2}\nHeight = {3}\nYOffset = {4}", recognizedChars[i].Rectangle.Left, recognizedChars[i].Rectangle.Top, recognizedChars[i].Rectangle.Width, recognizedChars[i].Rectangle.Height, recognizedChars[i].YOffset); 
            MessageBox.Show(buffer); 
 
            buffer = String.Format("First guess char = {0}\nSecond guess char = {1}\nThird guess char = {2}", recognizedChars[i].GuessCode, recognizedChars[i].GuessCode2, recognizedChars[i].GuessCode3); 
            MessageBox.Show(buffer); 
 
            buffer = String.Format("First Language Id = {0}\nSecond Language Id = {1}\nZone Index = {2}\nCell Index = {3}\nSpace = {4}\nSpace Error = {5}", recognizedChars[i].LanguageId2, recognizedChars[i].LanguageId2, recognizedChars[i].ZoneIndex, recognizedChars[i].CellIndex, recognizedChars[i].Space, recognizedChars[i].SpaceError); 
            MessageBox.Show(buffer); 
         } 
 
         recognizedChars[i] = tmpChar; 
      } 
   } 
 
   rasterDocument.SetRecognizedCharacters(0, recognizedChars); 
   RasterDocumentResultOptions resultOpts = rasterDocument.SaveResultOptions; 
 
   resultOpts.Format = RasterDocumentFormatType.RtfWord2000; 
   resultOpts.FormatLevel = RasterDocumentFormatLevel.Full; 
 
   RasterDocumentOptions docOpts; 
   docOpts = resultOpts.Document; 
   docOpts.PaperSizeMode = RasterDocumentSelector.Predefined; 
   docOpts.PaperType = RasterDocumentPaperType.A4; 
   docOpts.PaperOrientation = RasterDocumentPaperOrientation.Portrait; 
   docOpts.RetainGraphics = RasterDocumentRetainGraphicsMode.Original; 
   docOpts.TextInboxes = false; 
   docOpts.Margins = new Rectangle(5, 5, 195, 195); 
   docOpts.RetainPageBreaks = true; 
   docOpts.TableMethod = RasterDocumentTableMethod.UseTabs; 
 
   resultOpts.Document = docOpts; 
   rasterDocument.SaveResultOptions = resultOpts; 
   rasterDocument.SaveResultsToFile(LeadtoolsExamples.Common.ImagesPath.Path + "Test.doc"); 
 
   rasterDocument.Shutdown(); 
}

Remarks

This method will return an array for all recognized characters for the specified recognized page.
This method can be called after a successful recognition process started by calling Recognize.
This method should not be called before calling Recognize.
To update the recognized characters, call SetRecognizedCharacters.
To save the updated recognized characters to a file, call SaveResultsToFile.
Also, To save the results into memory, call SaveResultsToMemory.
For more information, refer to Recognizing Document Pages.
For more information, refer to Confidence Reporting.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

The Leadtools.Document namespace is deprecated and no longer supported as of LEADTOOLS v16. For v16 and later, please refer to: Leadtools.Forms.Ocr. This documentation is retained for v15 and earlier informational use only.