Hi all.
I am relatively new to this so...
I have a letter that gets scanned into our imaging system from various scanners. Some are set at 200dpi and some at 300dpi. All TIFF CCITT (Group 4) The below code works fine for 300dpi but I get "Invalid zone coordinates" when a 200dpi image is used.
What's the best way to handle this for any resolution? I don't want to OCR the entire document, I only care about a little piece of it.
Thanks is advance.
Public Sub OCR(ByVal filename As String)
'Start up the Ocr engine
Try
rasterOcr.StartUp()
Catch ex As Exception
msg = "ERROR: " & ex.Message.ToString
End Try
'Type the path of the Leadtools Bin folder.
RasterCodecs.CodecsPath = "C:\Program Files\LEAD Technologies, Inc\LEADTOOLS 14.5\Bin\Dotnet\v11"
'Initialize a new RasterCodecs object
Dim codecs As RasterCodecs = New RasterCodecs
'Load a temporary image
Dim rasterImage As IRasterImage = codecs.Load(filename)
Try
'add the image to the the ocr raster object
rasterOcr.AddPage(rasterImage, -1)
Catch ex As Exception
msg = "Error: " + ex.Message + ". The engine could not add a new page to the document"
Finally
rasterImage.Dispose()
End Try
'add zone
Dim zoneData As RasterOcrZoneData = New RasterOcrZoneData
With zoneData
.Rectangle = New Rectangle(1400, 1150, 1000, 350)
.FillMethod = Leadtools.Ocr.RasterOcrFillMethod.Default
.RecognizeModule = Leadtools.Ocr.RasterOcrRecognizeModule.Auto
.CharacterFilter = Leadtools.Ocr.RasterOcrCharacterFilter.Default
.Type = Leadtools.Ocr.RasterOcrZoneType.FlowText
.Flags = Leadtools.Ocr.RasterOcrZoneFlags.None
.DisableEvents()
.SectionName = "t303data"
End With
Dim buffer As String = ""
Try
rasterOcr.AddZone(0, 0, zoneData)
Catch ex As Exception
msg = "Error: " + ex.Message
End Try
'get the data
Dim strPath As String = Path.GetTempPath
If strPath = "" Then
'could not determine TEMP directory
strPath = "C:"
End If
Dim strFile As String = strPath & "\ocrtemp.rdf"
If File.Exists(strFile) Then
'delete it, will get recreated later
File.Delete(strFile)
End If
With rasterOcr
.RecognitionDataFileName = strFile
.SpellLanguageID = RasterOcrLanguage.English
End With
Try
'recognize the image in the rectangle we created
'and save the results to a string variable
rasterOcr.Recognize(0, 1)
Dim strResult As String = rasterOcr.SaveResultsToMemory
mvarCheckNumber = GetCheckNumber(strResult)
mvarCheckDate = GetCheckDate(strResult)
mvarCheckAmount = GetCheckAmount(strResult)
'If mvarCheckNumber.Length > 0 And mvarCheckDate.Length > 0 Then
' GetDCSData(mvarCheckNumber, mvarCheckDate)
'End If
Catch ex As Exception
msg = "Error: " + ex.Message + " in saving recognition result to memory"
End Try
' Shut down the RasterOcr engine
rasterOcr.ShutDown()
rasterOcrZoneData = Nothing
End Sub