[jawsscripts] Convenient OCR

  • From: "Jim Snowbarger" <Snowman@xxxxxxxxxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Mon, 30 Jun 2014 21:55:01 -0500

I am trying to make an addition to HSC that will allow you to describe a 
small area of the screen, and run a hot spot which will cause JAWS to do OCR 
on that small area, such that HSC can then speak the result for that field.
That sounds like a very tantalizing thing to do.
But, I am having a lot of trouble getting that  to work well, if at all. 
If I define a small area,  jaws says that no text was recognized, even 
though I am sure the area is large enough to hold the entire phrase.  I 
learned that from a normal OCR run which shows text in that location, and by 
exploring that text with the jaws cursor and reporting cursor coords.
If I do insert+space, o, w, to OCR the window, I get one set of results.
But,. if I position the jaws cursor in this text, and call the jaws builtin 
OCRScreenArea, providing the corners of the window returned by 
GetCurrentWindow, I get different results.  they are similar enough that I 
recognize the windo.  But, several key things are missing.
And, after I do that, what OCR results do exist are blended in with the jaws 
cursor, as expected.  So, I can review them.  But, the debug code which 
captures all the text nodes in the XML, does not include all the things that 
are shown by the jaws cursor.  I expected a better match there.

Below is the code that I am using to do this, almost entirely swiped out of 
the jaws documentation on the subject.
Have a look, if you got time and are interested,  and see if you can tell me 
what the heck I'm doing wrong here.


Function HSCPerformOCr ()
; HSC calls this to start an OCR job.
; Before calling:
; activate and position jaws cursor to the center of the  area.
; to describe the area,
; preload globals HSLeftLimit, HSIghtLimit, HSUpLimit, and HSDownlLimit
var
 Handle hCurrent,
 int iCol,
 int iRow,
 Int iLeft,
 Int iRight,
 Int iBottom,
 Int iTop,
 Int iPrimary,
 Int iSecondary,
 int iVersion

; OCR is not available in all jaws versions
Let iVersion = GetJFWVersion ()
if (iVersion < 1200000) then
 SayString ("OCR is not available")
 return
endif
; cheat on the language for now
Let iPrimary = 1033  ;ReadSettingInteger (section_OCR, 
hKey_PrimaryRecognitionLanguage, 1033, FT_DEFAULT_JCF),
Let iSecondary = 1033  ; ReadSettingInteger (section_OCR, 
hKey_SecondaryRecognitionLanguage, 1033, FT_DEFAULT_JCF),
; get the center point of the area to OCR
Let iCol = GetCursorCol()
Let iRow = GetCursorRow()
; now expand that to cover the desired area
Let iLeft = iCol - HSLeftLimit
Let iRight = iCol + HSRightLimit
Let iTop = iRow - HSUpLimit
Let iBottom = iRow + HSDownLimit
; tell JAWS to OCR
Let HSCJobId = OCRScreenArea (iLeft, iTop, iRight, iBottom, iPrimary, 
iSecondary)
; next thing to happen is that OCRCompletedEvent fires
EndFunction

Void Function OCRCompletedEvent (Int iJobID, Int iResult)
; runs  when jaws completes the OCR job
If (iJobID == HSCJobId) then
 Let HSCJobID = 0
 If Not iResult then
  SayString ("no text recognized")
  Return
 EndIf
;  SayString ("stuff was recognized")
 HSCSpeakOCRResult()
else
 ; not our job
 OCRCompletedEvent (iJobID, iResult)
EndIf
EndFunction


Function HSCSpeakOCRResult ()
; decode the screen XML and speak the OCR text.
var
 string sText,
 object fsxml,
 object results,
 object attribs

Let fsxml = CreateObject ("msxml2.DOMDocument.6.0")
if (fsxml) then
 Let fsxml.async = 0
 Let fsxml.resolveExternals = 0
 fsxml.loadXML(GetScreenXML())
 Let results = fsxml.selectNodes("//Span")
 if (results) then
  ForEach node in results
   Let sText = node.text
   SayDebugStringJLS ("", sText) ;@@@test
   let attribs = node.attributes
   if (attribs) then
    if (attribs.GetNamedItem("Source").nodeValue == "OCR") then
     HSSay (node.text, node.text)
    endif
   endif
  EndForEach
 endif
endif
EndFunction

*** end of code



__________�

View the list's information and change your settings at 
http://www.freelists.org/list/jawsscripts

Other related posts: