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, August 6, 2007 9:49:38 AM(UTC)
mespinosa

Groups: Registered
Posts: 1


Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Codecs.RasterCodecs
Imports Leadtools.WinForms
Imports Leadtools.Ocr
Imports Leadtools.ImageProcessing

Public Class OCR
Inherits System.Windows.Forms.Form
Public WithEvents rasterOcr As rasterOcr
Private WithEvents rasterOcrZoneData As rasterOcrZoneData

Public Sub New()
RasterSupport.Unlock(RasterSupportType.Ocr, System.Configuration.ConfigurationSettings.AppSettings("OCRKey"))
RasterSupport.Unlock(RasterSupportType.Document, System.Configuration.ConfigurationSettings.AppSettings("DocumentKey"))


rasterOcr = New RasterOcr

Me.Visible = False

Dim wait As New WaitCursor
Try
rasterOcr.StartUp()
Catch ex As Exception
' check if the OCR engine could be initialized
Dim showEngine As Boolean = False

If (TypeOf (ex) Is RasterOcrException) Then
Dim oe As RasterOcrException = DirectCast(ex, RasterOcrException)
If (oe.Code = RasterOcrExceptionCode.InitializeEngine) Then
showEngine = True
End If
End If
Return
Finally
wait.Dispose()
End Try

' Initialize a new RasterOcrZoneData object
rasterOcrZoneData = New RasterOcrZoneData

RasterCodecs.CodecsPath = System.Configuration.ConfigurationSettings.AppSettings("CodecPath")

'Initialize a new RasterCodecs object
Dim codecs As RasterCodecs = New RasterCodecs

AddHandler Me.Closing, AddressOf Form_Cancel

AddHandler rasterOcrZoneData.Verification, AddressOf rasterOcrZoneData_Verification

End Sub


Public Function Analyze(ByVal fileName As String) As String
Dim strReturn As String
Dim sb As New System.Text.StringBuilder

'Initialize a new RasterCodecs object
Dim codecs As RasterCodecs = New RasterCodecs
'Load a temporary image
Dim rasterImage As IRasterImage = codecs.Load(fileName)

Try
'Some information about the new added image

Try
'Add the temporary image as a page to the RasterOcr object
If rasterOcr.PageCount > 0 Then
rasterOcr.RemovePage(0)
End If
rasterOcr.AddPage(rasterImage, -1)

rasterOcr.SpellLanguageID = RasterOcrLanguage.English
rasterOcr.EnableSubSystem = True
rasterOcr.EnableCorrection = True

' Specifies the name of the file that will be used in the recognition.
rasterOcr.RecognitionDataFileName = "c:\tempOCRData.rdf"
'rasterOcr.SaveResultsToMemory()
' Recognize the first page of the RasterOcr object.
rasterOcr.Recognize(0, 1)
Dim recogWords As RasterOcrRecognizedWords() = rasterOcr.GetRecognizedWords(0)

Dim i As Integer

For i = 0 To recogWords.Length - 1
sb.Append(recogWords(i).Word & " ")
Next
strReturn = sb.Replace(vbCrLf, "").ToString.Trim()

Catch ex As Exception
Dim er As New ErrorRecorder(ex.Message & vbCrLf & ex.StackTrace)
strReturn = "error"
End Try

Finally
rasterImage.Dispose()
End Try
Return strReturn
End Function
Private Sub rasterOcrZoneData_Verification(ByVal sender As Object, ByVal e As RasterOcrVerificationEventArgs) Handles rasterOcrZoneData.Verification
rasterOcrZoneData.VerifyCode = RasterOcrVerificationCode.Accept
rasterOcrZoneData.Flags = RasterOcrZoneFlags.DontUseVerificationEvent
End Sub
Protected Sub Form_Cancel(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
rasterOcr.ShutDown()
rasterOcrZoneData = Nothing
rasterOcr = Nothing
End Sub


Private Sub InitializeComponent()
'
'OCR
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "OCR"

End Sub

Private Sub OCR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class


-- I have this OCR class in version 14. Now it does not work on version 15. What namespaces, new commands to I need to import/code to make it work
on version 15. Thank you for your help
 

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 : Thursday, August 9, 2007 11:37:14 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


There are several changes from 14 to 15.  The most major in relation to your snippet would be the OCR namespace.  It has been removed and reorganized into the Leadtools.Document namespace.  The logic won't need to change much, and for the most part you can replace "OCR" with "Document".  For more information regarding changes between 14 and 15, please consult the version history in the .NET help file in the Contents section.
 
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.142 seconds.