In addition to the captured text MODI can return other information about the bmp or jpg file passed to it, such as the image size. I use it as a clue to determine whether there is a vbscript problem when no text is returned.
Often you want to capture the text in a very specific area of the screen and not have it confused with other text. So you use Image Recogntion to find a text field label, do a screencapture of the adjacent field, and use DoOCR to capture the text. This post will illustrate the same text in several scenarioes showing where MODI works and does not work.
Here is my DoOCR script:
Code: Select all
VBSTART
Function DoOCR(bitmapfile)
Dim miDoc
Dim miLayout
Dim stringOut
Dim miImg
Dim PixelWidth
Dim PixelHeight
on error resume next
set miDoc=CreateObject("MODI.Document")
miDoc.Create (bitmapfile)
' Perform OCR.
'You can change the mousepointer here to an hourglass or something.
miDoc.Images(0).OCR
'Change the mouse back to normal default.
set miLayout = miDoc.Images(0).Layout
stringOut=miLayout.Text
'MsgBox(stringOut)
set miImg = miDoc.Images(0)
PixelWidth=miImg.PixelWidth
PixelHeight=miImg.PixelHeight
DoOCR = PixelWidth & "," & PixelHeight & " " & stringOut
Set miLayout = Nothing
Set miDoc = Nothing
End Function
VBEND
//Need minimum 3 pixel boarder around text
Let>sImageFileBmpOrJPG=C:\MJT_Log\_testOCR.bmp
VBEval>DoOCR("%sImageFileBmpOrJPG%"),sImagePixelSizeAndTextFound
MDL>%sImagePixelSizeAndTextFound%
In all of the images below the text is 8 pixels high. The differences are in the image height and size/color of the border.
Here is an image that contains only the screen text and no adjacent graphics or differently colored background:
TestOCR1 Readable 86x36pixels White area 17 pixels high

TestOCR2: Not readable 86x17 pixels

TestOCR3 Not readable 86x21 pixels

TestOCR4 Not readable 86x21 pixels

TestOCR5 Readable 86x36 pixels

TestOCR6 Readable 86x36 pixels

TestOCR7 Not readable 86x36 pixels

Conclusions:
1. Include sufficient background pixels above and below the expected text.
2. OCR works best when contrast between background and border is low.
3. Choose light colored screen background and field highlighting.
4. Choose font color that contrasts with background.
5. Capture minimum size image and add low contrast border.
6. Manipulate image colors and intensities.
7. Third party image manipulation tool will help
8. Enhancing Macro Scheduler to include such a tool will help.
If you have additional insights, please add them to this thread.
Hope people find this useful,
Gale