Thursday, December 28, 2006

HOW TO USE ZONAL OCR

Use following code for the same
Public Function Execute(oBatch As RepObject) As Long
Dim workarray(1 To 1) As RepObject
Dim iResult As Long
Dim bShowForm As Boolean

DoEvents

Dim intZoneID As Integer
Dim lngLeft As Long
Dim lngTop As Long
Dim lngRight As Long
Dim lngBottom As Long
Dim lngReq1 As Long
Dim lngReq2 As Long

With OCR1 - This is the zonal ocr component

Set .CurrentObject = oBatch
.Load oBatch

DoEvents
DoEvents
DoEvents

Set workarray(1) = oBatch

intZoneID = 1
lngLeft = 1988
lngTop = 392
lngRight = 2438
lngBottom = 467
lngReq1 = 0
lngReq2 = 0
.SetOcrZone intZoneID, lngLeft, lngTop, lngRight, lngBottom, lngReq1, lngReq2

intZoneID = 2
lngLeft = 902
lngTop = 446
lngRight = 2432
lngBottom = 521
lngReq1 = 0
lngReq2 = 0
.SetOcrZone intZoneID, lngLeft, lngTop, lngRight, lngBottom, lngReq1, lngReq2

intZoneID = 3
lngLeft = 908
lngTop = 518
lngRight = 1607
lngBottom = 607
lngReq1 = 0
lngReq2 = 0
.SetOcrZone intZoneID, lngLeft, lngTop, lngRight, lngBottom, lngReq1, lngReq2

intZoneID = 4
lngLeft = 905
lngTop = 593
lngRight = 1619
lngBottom = 686
lngReq1 = 0
lngReq2 = 0
.SetOcrZone intZoneID, lngLeft, lngTop, lngRight, lngBottom, lngReq1, lngReq2

intZoneID = 5
lngLeft = 392
lngTop = 2771
lngRight = 774
lngBottom = 2885
lngReq1 = 0
lngReq2 = 0
.SetOcrZone intZoneID, lngLeft, lngTop, lngRight, lngBottom, lngReq1, lngReq2

.VerifyMode = vmVerifyWords
.OCRVerification = False

.AutoLoadSettings = False
.Reset

End With

If OCR1.OCRVerification Then
bShowForm = True
Me.Show vbModal
End If

State = "Execute"

iResult = OCR1.Execute(workarray)

DoEvents
DoEvents
DoEvents

State = "Idle"

If bShowForm Then
'Me.Hide
End If

Execute = iResult
'MsgBox iResult

End Function

**********************************************************

This is where the OCR values are picked up and assigned to text boxes on the form.

**********************************************************
Set oRepObject = gobjCurrentDoc.Contents(gintCurrentPageNo - 1)
Call frmZonalOCR.Execute(oRepObject) '- Calling above function

If oRepObject.NodeId = fnniPage Then
Set oAttr = oRepObject.Attributes("UserDefined", "OCRValue1")
If Not oAttr Is Nothing Then
'MsgBox "First OCR Value " & " is " & CStr(oAttr.Value)
txtIndex(1).text = CStr(oAttr.Value)
End If

Set oAttr = oRepObject.Attributes("UserDefined", "OCRValue2")
If Not oAttr Is Nothing Then
'MsgBox "Second OCR Value " & " is " & oAttr.Value
txtIndex(2).text = CStr(oAttr.Value)
End If

Set oAttr = oRepObject.Attributes("UserDefined", "OCRValue3")
If Not oAttr Is Nothing Then
'MsgBox "Third OCR Value " & " is " & oAttr.Value
txtIndex(3).text = CStr(oAttr.Value)
End If

Set oAttr = oRepObject.Attributes("UserDefined", "OCRValue4")
If Not oAttr Is Nothing Then
'MsgBox "Fourth OCR Value " & " is " & oAttr.Value
'txtIndex(4).text = CStr(oAttr.Value)
End If

Set oAttr = oRepObject.Attributes("UserDefined", "OCRValue5")
If Not oAttr Is Nothing Then
'MsgBox "Fifth OCR Value " & " is " & oAttr.Value
txtIndex(5).text = CStr(oAttr.Value)
End If
End If

1 comment:

Extract Website Data said...

Hello friends,

Zonal OCR is the process by which optical character recognition applications read specifically zoned text from a scanned image. Many batch document imaging applications allow the end user to identify and draw a zone on a sample image to be recognized. Thanks a lot......