sambuddy Posted September 3, 2008 Share Posted September 3, 2008 Hello Everyone, I am using the MODI control out of office 2007 to do some OCR. This method has been mentioned in previous threads. The problem i am having (and hope someone can help me solve) is that if i continually do ocr, the ocr object reports an error and crashes autoit. The error it reports is "OCR running error". Does anyone know what this error means? Any way to fix it? Any way to continue on after this has happened? Thanks for your help P.S. I am monitoring the video output of a stb with a video capture card, so I basically need to be able to do ocr continually for a 24 hour period. PPS. My code is below and i have also attached the two bitmaps that the script uses if anyone wants to try it out. #include <Date.au3> Dim $oMyError ; Initialize error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") while(1) if (GetText("c:\ocr_test.bmp","private")==True) Then ConsoleWrite("FOUND in ocr_test.bmp" & @CRLF) Else ConsoleWrite("NOT FOUND in ocr_test.bmp" & @CRLF) EndIf if (GetText("c:\screen_dump.bmp","private")==True) Then ConsoleWrite("FOUND in screen dump" & @CRLF) Else ConsoleWrite("NOT FOUND in screen dump" & @CRLF) EndIf WEnd Func GetText($bmp,$searchTxt) Dim $str Dim $oWord dim $start_time dim $stop_time $start_time=TimerInit() Const $miLANG_ENGLISH = 9 ;create the ocr instance dim $miDoc $miDoc = ObjCreate("MODI.Document") $miDoc.Create($bmp);load the image into the ocr engine (M$ use the word create, should really be load) $miDoc.Ocr($miLANG_ENGLISH, True, True);find english words if (@error>0) Then ConsoleWrite("OCR failed"& @CRLF) SetError(1) EndIf For $oWord in $miDoc.Images(0).Layout.Words;get all the words and put them into one big string $str = $str & $oWord.text ; ConsoleWrite("recognition confidance = " & $oWord.RecognitionConfidence() & "for " & $oWord.text & @CRLF) Next $miDoc=0 $stop_time=_NowCalc() ConsoleWrite("Time taken = " & TimerDiff($start_time) & @CRLF) $result=StringInStr($str,$searchTxt);see if the word we want is in the string if ( $result >0) Then Return True Else Return False EndIf EndFunc ;------------------------------ Wait for ocr to finish -------------------------------- Func OCREvent_OnOCRProgress($progress,$cancel) ConsoleWrite("OCR Progress is " & $progress & @CRLF) if($progress==100) Then $finished=True EndIf Endfunc ;------------------------------ This is a COM Error handler -------------------------------- Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Error Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfuncocr_pics.zipocr.au3 Link to comment Share on other sites More sharing options...
sambuddy Posted September 3, 2008 Author Share Posted September 3, 2008 Sorry about the duplicate post. I got a server error while submitting my post Link to comment Share on other sites More sharing options...
joemoeschmoe Posted September 5, 2008 Share Posted September 5, 2008 I get this same problem and am just working out a solution. AFAIK, AutoIt3 can't capture the OCR and not crash. My idea that I haven't finished yet: Run a 2nd program that is constantly making sure the main one is running. If the main one crashes, have the 2nd program start it back up again. Also, the main program has to constantly record to a file saying where its at in the program, so if it crashes it will know where to start again. This is an not an elegant solution, but I don't see anyway around it - the OCR just seems to crash a lot. Link to comment Share on other sites More sharing options...
joemoeschmoe Posted September 5, 2008 Share Posted September 5, 2008 (edited) AFAIK, AutoIt3 can't capture the OCR and not crash. Correction: I had not yet turned my scripts into .exe files. If I turn them into .exe files and use: $oMyError = ObjEvent("AutoIt.Error","MyErrFunc");before trying to OCR and Func MyErrFunc() SetError(1) Endfunc Then all my Bot Watcher needs to do is look for the message box that pops up when the OCR fails and press Enter on it. Then the program continues normally. When I run using F5 in SciTE, the Error Handler doesn't stop the program from crashing. However, it does when its an exe file. Edited September 5, 2008 by joemoeschmoe Link to comment Share on other sites More sharing options...
ofLight Posted September 6, 2008 Share Posted September 6, 2008 Is the error you are getting being generated by the MODI.dll itself or is it being generated by the MyErrFunc() ??? In the case of the latter, you can rewrite the MyErrFunc to NOT popup an error window that will halt your script, or you can completely dissable the error func. I am guessing in your situation one failed read every few thousand is no big deal, so there is no reason really to have the MyErrFunc setup to halt your script. There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly Link to comment Share on other sites More sharing options...
sambuddy Posted September 6, 2008 Author Share Posted September 6, 2008 Hello, To work out if it is autoit or MODI causing the crash i wrote an app in C# to do the same thing with the same graphics as used in my auto it script. It crashed as well with a memory corruption error after about 30 OCR cycles. I was hoping that maybe it was a parameter that i wasn't setting correctly or a state i wasn't checking but it is looking less and less likely to be the case. SO i have started looking at putting MODI into it's own app and launching it as its own process, so if that process dies it doesn't take out my script. The only problem i see from this is the time taken to launch another process and then kill the process maybe too long for my requirements. MODI currently fails after 10 to 30 OCR conversions (not consistant) I have tried disabling the "MyError", in this case the script just crashes when MODI crashes Regards Link to comment Share on other sites More sharing options...
joemoeschmoe Posted September 6, 2008 Share Posted September 6, 2008 Hello, To work out if it is autoit or MODI causing the crash i wrote an app in C# to do the same thing with the same graphics as used in my auto it script. It crashed as well with a memory corruption error after about 30 OCR cycles. I was hoping that maybe it was a parameter that i wasn't setting correctly or a state i wasn't checking but it is looking less and less likely to be the case. SO i have started looking at putting MODI into it's own app and launching it as its own process, so if that process dies it doesn't take out my script. The only problem i see from this is the time taken to launch another process and then kill the process maybe too long for my requirements.MODI currently fails after 10 to 30 OCR conversions (not consistant)I have tried disabling the "MyError", in this case the script just crashes when MODI crashesRegardsI've got mine fully functioning without having to use a Watcher program. I realized that I had a an "If @Error Then MsgBox..." code after OCR. Basically, all I have to do is capture the error, then ignore it. Even with the capturing of the error code, the OCR error crashed my code when I ran with F5, but then when I use Ctrl + F7 to compile into an exe (in SciTE), the OCR error no longer crashes my code. My code now continues forward even when there's an OCR error.Sambuddy, are you compiling your code into an exe before running it with the error handling? Link to comment Share on other sites More sharing options...
sambuddy Posted September 6, 2008 Author Share Posted September 6, 2008 No, i've been running mine from F5 all the time. I'll try the compile option and see how it goes. I'll keep you informed Link to comment Share on other sites More sharing options...
Eguun Posted April 3, 2011 Share Posted April 3, 2011 (edited) Hi, I am facing the same issue: OCR works just fine for some loops, then it crash. Hard crash: AutoIT has encoutered an error and is forced to close. I would like very much to capture the error and tell autoit to just ignore it. Is there anyone out there who found a solution for this? I'ld very much appreciate to read some thoughts about it. joemoeschmoe's idea sounds highly promising, but I can't make it work. I am calling OCR from a function and have defined another function as ocrerror. Nota: I have pinpointed the part that makes the program crash: it is this function: $miDoc.Ocr($miLANG_ENGLISH, True, True); Compiled or not, the error message remains the same. I tried this with Office versions 2007 (no SP, and with SP2) and 2010. Any hints are very welcome Cheers Edited April 3, 2011 by Eguun Link to comment Share on other sites More sharing options...
Eguun Posted April 4, 2011 Share Posted April 4, 2011 Hi, I managed to get around the crash by running the OCR as an external script from my main script. When it crashes I make my main script check for the error message and simply click the button. It's all good now Cheers Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now