#Include <GDIPlus.au3>
#include <Clipboard.au3>
Local $sTifFile, $sText
_GDIPlus_Startup()
While Sleep( 10 )
$sTifFile = _AutCaptcha_FromClip()
If $sTifFile Then
$sText = _AutCaptcha_Tesseract( $sTifFile )
; -
SplashOff()
If StringRegExp( $sText, "^(\d+)$" ) Then
SplashTextOn( "OK!", $sText, 100, 80, 0, 500, 4, "")
Else
SplashTextOn( "FAIL!", $sText, 100, 80, 0, 500, 4, "")
EndIf
ClipPut( $sText )
; -
FileDelete( $sTifFile )
EndIf
WEnd
_GDIPlus_Shutdown()
; ### AutCaptcha_API by Firex
Func _AutCaptcha_FromClip()
Local $hBitmap, $hImage
; ---
If _ClipBoard_Open(0) Then
$hBitmap = _ClipBoard_GetDataEx($CF_BITMAP)
If Not IsPtr($hBitmap) Then _
Return
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
_ClipBoard_Close()
If IsPtr($hImage) Then
_WinAPI_DeleteObject($hBitmap)
Else
Return
EndIf
Return _AutCaptcha_Convert( $hImage )
EndIf
Return
EndFunc
Func _AutCaptcha_Convert( $hImage )
Local $sCLSID, $tParams, $pParams, $iW, $iH, _
$sPath = @TempDir & "\" & Random( 1, 99, 1 ) & ".tif", _
$iScale = 1.2
; ---
$iW = _GDIPlus_ImageGetWidth( $hImage )
$iH = _GDIPlus_ImageGetHeight( $hImage )
$hContext = _GDIPlus_ImageGetGraphicsContext($hImage)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW*$iScale,$iH*$iScale,$hContext)
$hNewContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hNewContext,$hImage,0,0,$iW*$iScale,$iH*$iScale)
$tParams = _GDIPlus_ParamInit(2)
$tData = DllStructCreate("int ColorDepth;int Compression")
$tData.ColorDepth = 24
$tData.Compression = $GDIP_EVTCOMPRESSIONNONE
; *
_GDIPlus_ParamAdd($tParams, $GDIP_EPGCOLORDEPTH, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "ColorDepth"))
_GDIPlus_ParamAdd($tParams, $GDIP_EPGCOMPRESSION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Compression"))
; *
$sCLSID = _GDIPlus_EncodersGetCLSID("TIF")
_GDIPlus_ImageSaveToFileEx($hBitmap, $sPath, $sCLSID, DllStructGetPtr($tParams))
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_GraphicsDispose($hNewContext)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)
; ---
Return $sPath
EndFunc
Func _AutCaptcha_Tesseract( $sTifImg )
Local $sRet, $iPid, $sTxt = $sTifImg & ".txt"
; ---
$iPid = Run( @ProgramFilesDir & '\Tesseract-OCR\tesseract.exe "' & $sTifImg & '" "' & $sTifImg & '"', @ProgramFilesDir & '\Tesseract-OCR', @SW_HIDE )
While ProcessExists( $iPid ) And Sleep( 100 )
;Nothing
WEnd
$sRet = FileRead( $sTxt )
FileDelete( $sTxt )
; ---
Return $sRet ;_AutCaptcha_PostFilter( $sRet )
EndFunc
Func _AutCaptcha_PostFilter( $sText )
Local $aLib[12][2] = [ [11], _
[ "\%", 8 ], _
[ "\'!", 7 ], _
[ "\’", "" ], _
[ "A", "4" ], _
[ "Q", "9" ], _
[ "O", "0" ], _
[ "J", "1" ], _
[ "b", "6" ], _
[ "S", "5" ], _
[ "\:", "" ], _
[ "\/.", "4" ] ], $Idx
; ---
$sText = StringStripWS( $sText, 8 )
For $Idx = 1 To $aLib[0][0] Step 1
$sText = StringRegExpReplace( $sText, $aLib[$Idx][0], $aLib[$Idx][1] )
Next
Return $sText
EndFunc