Gets all of the characters that have been recognized for a specific page.
Syntax
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 Basic | Copy Code |
---|
Public Sub GetRecognizedCharactersExample()
RasterSupport.Unlock(Leadtools.RasterSupportType.Ocr, "TestKey")
Dim rasterDocument As RasterDocumentEngine
rasterDocument = RasterDocumentEngine.Instance
rasterDocument.Startup()
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
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also