Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, October 9, 2006 4:30:13 AM(UTC)

rjoe  
rjoe

Groups: Registered
Posts: 4


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

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Monday, October 9, 2006 10:04:55 PM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

Hello,

You may try to resolve this issue by converting the resolution of the images to 300DPI before drawing the zones.
You can change the image resolution by setting the values of the LeadImage.XResolution and LeadImage.YResolution properties to 300.

Please let me know if this helps.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#3 Posted : Tuesday, October 10, 2006 7:13:57 AM(UTC)

rjoe  
rjoe

Groups: Registered
Posts: 4


It sort of helped [:)]

Just setting the X & Y resolution still generated the error but it did give me an idea.

I figured out what the ratio was for where I wanted the rectangle and did this (works every time regardless of resolution so far):

               'Load a temporary image
                Dim rasterImage As IRasterImage = codecs.Load(filename)

                Dim RecLeft As Integer = rasterImage.XResolution * 4.667
                Dim RecTop As Integer = rasterImage.YResolution * 3.833
                Dim RecWidth As Integer = rasterImage.XResolution * 3.333
                Dim RecHeight As Integer = rasterImage.YResolution * 1.167

                'add the image to the the ocr raster object
                rasterOcr.AddPage(rasterImage, -1)

                rasterImage.Dispose()

            'add zone
            Dim zoneData As RasterOcrZoneData = New RasterOcrZoneData
            With zoneData
                .Rectangle = New Rectangle(RecLeft, RecTop, RecWidth, RecHeight)
                .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

Thanks for pointing me to the XResolution and YResolution though.

Regards

 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.098 seconds.