Jump to content

Modi OCR problem with images that have no text in them


Ashen
 Share

Recommended Posts

Hello dear forum members, This is my first post here so please be patient with me.
 
My problem is fairly simple - I am capturing a certain part of the screen, and this part of the screen will sometime have text in it and sometimes it will not. The problem is that for some reason Modi crashes the program when it can't recognize any text in the image I provide it.
 
here's the code snipet:

#include <GUIConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <ScreenCapture.au3>




; OCR to text function. input is the coords on the screen that need translation

Func OCR_This($Top_Left_X , $Top_Left_Y , $Buttom_Right_X , $Buttom_Right_Y)

    Dim $miDoc
    Dim $oWord
    Dim $sArray[500]
    dim $sFilePath = "C:\Users\A\Desktop\tmp.tif"  ; in order for OCR to happen,  screenshot will be saved in this file.

    Const $miLANG_ENGLISH = 9

; Initialize error handler
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

    $miDoc = ObjCreate("MODI.Document")


    _ScreenCapture_SaveImage($sFilePath, _ScreenCapture_Capture("",$Top_Left_X,$Top_Left_Y,$Buttom_Right_X,$Buttom_Right_Y,False),True)

    $miDoc.Create($sFilePath)
    $miDoc.Ocr($miLANG_ENGLISH, False, False)

    $i = 0

    For $oWord in $miDoc.Images(0).Layout.Words
        $sArray [$i] = $oWord.text
        $i += 1
    Next



    Return $sArray



EndFunc


Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _
            "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            "err.description is: " & @TAB & $oError.description & @CRLF & _
            "err.source is: " & @TAB & $oError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

anyone have any idea how I can avoid the program crashing here?

thanks in advance,

Amir.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...