forked from TungstenTransformation/KTScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZonalOCRinScript.vb
33 lines (32 loc) · 1.79 KB
/
ZonalOCRinScript.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Public Sub SL_CustomZones(ByVal pXDoc As CASCADELib.CscXDocument, ByVal pLocator As CASCADELib.CscXDocField)
'Script Locator
Dim Zone As New CscXDocFieldAlternative, OCR_Chars As CscXDocChars
Set Zone= pLocator.Alternatives.Create
Zone.PageIndex=0 ' First Page
Zone.Left=50 ' Pixels
Zone.Width=25
Zone.Top=300
Zone.Height=25
Set OCR_Chars=XDocument_ZonalOCR(pXDoc,Zone,"FR_HandAlphanum")
Zone.Text=OCR_Chars.Text
Zone.Confidence=OCR_Chars.ConfAvg
End With
End Sub
Public Function XDocument_ZonalOCR(ByVal pXDoc As CscXDocument, zone As Object, ProfileName As String) As CscXDocChars
'Zone can be a cscxdocfield, cscxdocword, cscxdocfieldalternative
'Add reference to C:\Program Files (x86)\Common Files\Kofax\Components\MpsForms.6.0.dll
'Perform zonal ocr on the CSCXDOCFIELD or CSCXDocSubfield passed in.
Dim ZR As New MpsZoneRecognizing, ZonalProfile As IMpsRecogProfile, Image As CscImage, chars As CscXDocChars
Dim ResultText As String, ResultConf As Double
'Check if profile name exists and is zonal
If Not Project.RecogProfiles.ItemExistsByName(ProfileName) Then Err.Raise(4566,"The profile " & ProfileName & " does not exist!")
Set ZonalProfile=Project.RecogProfiles.ItemByName(ProfileName)
If Not ZonalProfile.Type=MpsRecogType.MpsRecogTypeZone Then Err.Raise(4567,ProfileName & " is not a Zonal Profile!")
If zone.PageIndex<0 Or zone.PageIndex>pXDoc.CDoc.Pages.Count-1 Then Err.Raise(4568, "Invalid Page Number: " & zone.PageIndex & "!")
Set Image = pXDoc.CDoc.Pages(zone.PageIndex).GetBitonalImage(Project.ColorConversion)
Set chars=New CscXDocChars
ZR.Recognize(Image, ZonalProfile, zone.Left, zone.Top, zone.Width, zone.Height, ResultText, ResultConf, chars)
zone.Text=ResultText
zone.Confidence=ResultConf
Return chars
End Function