;autoit-v3.2.12.1 ;Tested Windows XP SP2 with MS Office 2007 #Include #include #include #Include #include #include #include ; Local $v = 0, $X,$Y,$W,$H, $Image = @ScriptDir&"\ScreenCapture.jpg", $Error = False $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") While 1 _ScreenCapture_Capture($Image,535,454,656,490, False) ;; clipput("x="&$x&",y="&$y&",w="&$w&",h="&$h) _ImageResize($Image, $Image, 1000, 1000) $OCR = OCR($Image) WEnd Func OCR($Image) Local $miDoc, $Doc Local $str Local $oWord Local $sArray[500] $miDoc = ObjCreate("MODI.Document") $miDoc.Create(@ScriptDir & '\OCR_ImageResize.jpg') $miDoc.Ocr(9, True, False) If $Error = False Then $i = 0 For $oWord in $miDoc.Images(0).Layout.Words $str = $str & $oWord.text & @CrLf ConsoleWrite($oWord.text & @CRLF) $sArray [$i] = $oWord.text $i += 1 Next $as_Text = _ArrayToString($sArray," ",0) $as_Text = StringReplace($as_Text, " ", "", 0) ClipPut($as_Text) TrayTip("Info",ClipGet(),2,1) SoundPlay("b.wav", 1) $recognise = FileOpen("reckon.txt", $FO_APPEND) FileWrite($recognise, $as_Text&@crlf) FileClose($recognise) Return 0 ElseIf $Error = True Then $Error = False ;; TrayTip("Info","Error. OCR could not 'read' any characters.",2,1) ;; ClipPut("Error") EndIf EndFunc Func MyErrFunc() SetError(1) ; to check for after this function returns $Error = True Endfunc ; #FUNCTION# ========================================================================================= ; Name...........: _ImageResize ; Description....: Resize an image and optionally convert it to the format you want. ; Syntax.........: _ImageResize($sInImage, $sOutImage, $iW, $iH) ; Parameters ....: $sInImage - Full path to the image to resize / convert. ; In types: *.bmp, *.gif, *.ico, *.jpg, *.jpeg, *.png, *.tif, *.tiff ; $sOutImage - Full path where to save the resized / converted image. ; Out types: *.bmp, *.gif, *.jpg, *.jpeg, *.png, *.tif, *.tiff ; $iW - Width to resize image to. ; $iH - Height to resize image to. ; Return values .: Success - Return 1 and @error 0 ; Failure - Return 0 and @error 1~5 ; @error 1 = In File does not exist ; @error 2 = In File format not supported ; @error 3 = Out File path does not exist ; @error 4 = Out file format not supported ; @error 5 = Resize Width or Height not an integer ; Author ........: smashly ; ==================================================================================================== Func _ImageResize($sInImage, $sOutImage, $iW, $iH) Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0 Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF" If Not FileExists($sInImage) Then Return SetError(1, 0, 0) $sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1))) If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0) ;OutFile path, to use later on. $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1)) If Not FileExists($sOP) Then Return SetError(3, 0, 0) ;OutFile name, to use later on. $sOF = StringTrimLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1)) ;OutFile extension , to use for the encoder later on. $Ext = StringUpper(StringTrimLeft($sOutImage, StringInStr($sOutImage, ".", 0, -1))) If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0) If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0) ;Start GDIPlus _GDIPlus_Startup() $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage) $ImageHeight = (_GDIPlus_ImageGetHeight($hImage2)) * 1.25 $ImageWidth = (_GDIPlus_ImageGetWidth($hImage2)) * 1.25 ; WinAPI to create blank bitmap at the width and height to put your resized image on. $hBitmap = _WinAPI_CreateBitmap($ImageWidth, $ImageHeight, 1, 32) ;Get the handle of blank bitmap you created above as an image $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) ;Load the image you want to resize. ;$hImage2 = _GDIPlus_ImageLoadFromFile($sInImage) ;Get the graphic context of the blank bitmap $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1) $ImageHeight = _GDIPlus_ImageGetHeight($hImage2) $ImageWidth = _GDIPlus_ImageGetWidth($hImage2) ;Draw the loaded image onto the blank bitmap at the size you want _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $ImageWidth * 1.25, $ImageHeight * 1.25) ;Get the encoder of to save the resized image in the format you want. $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image. ;Do ; $i += 1 ;Until (Not FileExists($sOP & $i & "_" & $sOF)) ;Prefix the number to the begining of the output filename $sOutImage = @ScriptDir & '\OCR_ImageResize.jpg' FileDelete($sOutImage) ;Save the new resized image. _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID) ;Clean up and shutdown GDIPlus. _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_DeleteObject($hBitmap) _GDIPlus_Shutdown() Return SetError(0, 0, 1) EndFunc ;==>_ImageResize