First, vbscript find a word and report its location on a wordlist:
Code: Select all
VBSTART
Function DoOCRGetWordNum(bitmapfile,strTargetWord)
Dim miDoc
Dim miLayout
Dim miWords
Dim miWord
Dim miWordText
Dim strText
Dim numWords
Dim numWord
Dim numWordFound
on error resume next
Set miDoc = CreateObject("MODI.Document")
miDoc.Create (bitmapfile)
miDoc.Images(0).OCR
set miLayout = miDoc.Images(0).Layout
Set miWords = miDoc.Images(0).Layout.Words
numWords=miWords.Count
numWord=0
numWordFound=-1
Do
strWord=miWords(numWord).Text
'Case sensitive compare
'We can also compare on .Id, .LineID, .FontId, and .RecognitionConfidence
if strWord=strTargetWord then
numWordFound=numWord
numWord=numWords
end if
numWord=numWord+1
Loop While NumWord < numWords
DoOCRGetWordNum = numWordFound
Set miDoc = Nothing
Set miLayout = Nothing
Set miWords = Nothing
Set miWord = Nothing
Set miWordText = Nothing
End Function
VBEND
Code: Select all
VBSTART
Function DoOCRGetRect(bitmapfile,numWord)
Dim miDoc
Dim miRects
Dim miRect
Dim strRectInfo
on error resume next
Set miDoc = CreateObject("MODI.Document")
miDoc.Create (bitmapfile)
miDoc.Images(0).OCR
'Get numWord word
'numWord = numWord+0
Set miRects = miDoc.Images(0).Layout.Words(numWord).Rects
'strRectInfo = "Word falls within " & miRects.Count & " bounding rectangle(s)." & vbCrLf
For Each miRect In miRects
strRectInfo = miRect.Left & "," & miRect.Top & "," & miRect.Right & "," & miRect.Bottom
Next
DoOCRGetRect = strRectInfo
'Or you might want to calc and return the center of the rectangle
Set miRect = Nothing
Set miRects = Nothing
Set miWord = Nothing
Set miDoc = Nothing
End Function
VBEND
Gale