Regency Posted October 14, 2009 Share Posted October 14, 2009 It looks for pixels making a simple simple ocr for numbers on this page. Anyone have any ideas on how to work this better? expandcollapse popup#include <IE.au3> #include <Misc.au3> #include <WindowsConstants.au3> #include <Timers.au3> Global $1 = '' Global $2 = '' Global $3 = '' Global $4 = '' Global $5 = '' Global $6 = '' Global $7 = '' Global $8 = '' Global $9 = '' Global $10 = '' Global $11 = '' Global $12 = '' Global $13 = '' Global $14 = '' Global $15 = '' Global $16 = '' Global $17 = '' Global $18 = '' Global $19 = '' Global $21 = '' Global $22 = '' Global $23 = '' Global $24 = '' Global $25 = '' Global $First = '' Global $Second = '' Global $Third = '' Global $Fourth = '' Global $Fifth = '' $oJailPage = _IECreate("Tmnx.net/authenticated/jail.aspx",0,1,1,1) _IELoadWait($oJailPage) Sleep(3000) Get() Func Get() ;First Number $1 = PixelGetColor(527, 146);top $2 = PixelGetColor(526, 151);middle $3 = PixelGetColor(527, 157);bottom $4 = PixelGetColor(523, 151);left $5 = PixelGetColor(529, 151);right ;second number $6 = PixelGetColor(536, 146) $7 = PixelGetColor(535, 151) $8 = PixelGetColor(536, 157) $9 = PixelGetColor(532, 151) $10 = PixelGetColor(538, 151) ;third number $11 = PixelGetColor(545, 146) $12 = PixelGetColor(546, 151) $13 = PixelGetColor(545, 157) $14 = PixelGetColor(541, 151) $15 = PixelGetColor(547, 151) ;fourth number $16 = PixelGetColor(554, 146) $17 = PixelGetColor(555, 151) $18 = PixelGetColor(554, 157) $19 = PixelGetColor(550, 151) $20 = PixelGetColor(556, 151) ;fifth number $21 = PixelGetColor(563, 146) $22 = PixelGetColor(564, 151) $23 = PixelGetColor(563, 157) $24 = PixelGetColor(559, 151) $25 = PixelGetColor(565, 151) IniWrite("Pixel.ini", "Pixel", "1", $1) IniWrite("Pixel.ini", "Pixel", "2", $2) IniWrite("Pixel.ini", "Pixel", "3", $3) IniWrite("Pixel.ini", "Pixel", "4", $4) IniWrite("Pixel.ini", "Pixel", "5", $5) IniWrite("Pixel.ini", "Pixel 2", "6", $6) IniWrite("Pixel.ini", "Pixel 2", "7", $7) IniWrite("Pixel.ini", "Pixel 2", "8", $8) IniWrite("Pixel.ini", "Pixel 2", "9", $9) IniWrite("Pixel.ini", "Pixel 2", "10", $10) IniWrite("Pixel.ini", "Pixel 3", "11", $11) IniWrite("Pixel.ini", "Pixel 3", "12", $12) IniWrite("Pixel.ini", "Pixel 3", "13", $13) IniWrite("Pixel.ini", "Pixel 3", "14", $14) IniWrite("Pixel.ini", "Pixel 3", "15", $15) IniWrite("Pixel.ini", "Pixel 4", "16", $16) IniWrite("Pixel.ini", "Pixel 4", "17", $17) IniWrite("Pixel.ini", "Pixel 4", "18", $18) IniWrite("Pixel.ini", "Pixel 4", "19", $19) IniWrite("Pixel.ini", "Pixel 4", "20", $20) IniWrite("Pixel.ini", "Pixel 5", "21", $21) IniWrite("Pixel.ini", "Pixel 5", "22", $22) IniWrite("Pixel.ini", "Pixel 5", "23", $23) IniWrite("Pixel.ini", "Pixel 5", "24", $24) IniWrite("Pixel.ini", "Pixel 5", "25", $25) ;If 0 = 0 Then; 0 --- ; MsgBox("", "0", $10) ; Second() If $4 = 12763842 Then; 1 -- $First = ConsoleWrite("1") Second() ElseIf $4 = 12171705 Then; 2--- $First = ConsoleWrite("2") Second() ElseIf $4 = 13355979 Then; 3--- $First = ConsoleWrite("3") Second() ElseIf $4 = 12434877 Then; 4 -- $First = ConsoleWrite("4") Second() ElseIf $4 = 15527148 Then; 5--- $First = ConsoleWrite("5") Second() ElseIf $4 = 15856113 Then; 6--- $First = ConsoleWrite("6") Second() ElseIf $4 = 12961221 Then; 7--- $First = ConsoleWrite("7") Second() ElseIf $4 = 13421772 Then; 8--- $First = ConsoleWrite("8") Second() ElseIf $4 = 15461355 Then; 9 $First = ConsoleWrite("9") Second() EndIf sleep(100) get() EndFunc ;==>Get Func Second() ;If 0 = 0 Then; 0 --- ; MsgBox("", "0", $10) ; Third() If $10 = 13092807 Then; 1 --- $Second = ConsoleWrite("1") Third() ElseIf $10 = 16316664 Then; 2---? $Second = ConsoleWrite("2") Third() ElseIf $10 = 16316664 Then; 3--- $Second = ConsoleWrite("3") Third() ElseIf $10 = 16514043 Or $10 = 15527148 Then; 4 -- $Second = ConsoleWrite("4") Third() ElseIf $8 = 16777215 Then; 5--- $Second = ConsoleWrite("5") Third() ElseIf $7 = 16316664 Then; 6--- $Second = ConsoleWrite("6") Third() ElseIf $9 = 12171705 Then; 7--- $Second = ConsoleWrite("7") Third() ElseIf $8 = 16777215 Then; 8--- $Second = ConsoleWrite("8") Third() ;ElseIf $4 = 15461355 Then; 9 ; MsgBox("", "9", $4) ; Third() EndIf Sleep(100) get() EndFunc ;==>Second Func Third() If $11 = 15592941 Then; 0 --- $Third = ConsoleWrite("0") Fourth() ElseIf $11 = 13092807 Then; 1 --- $Third = ConsoleWrite("1") Fourth() ElseIf $11 = 16316664 Then; 2---? $Third = ConsoleWrite("2") Fourth() ElseIf $11 = 16579836 Then; 3--- $Third = ConsoleWrite("3") Fourth() ElseIf $11 = 14145495 Then; 4 -- $Third = ConsoleWrite("4") Fourth() ElseIf $11 = 15527148 Then; 5--- $Third = ConsoleWrite("5") Fourth() ElseIf $11 = 16382457 Then; 6--- $Third = ConsoleWrite("6") Fourth() ElseIf $11 = 15856113 Then; 7--- $Third = ConsoleWrite("7") Fourth() ElseIf $11 = 15987699 Then; 8--- $Third = ConsoleWrite("8") Fourth() ElseIf $11 = 15658734 Then; 9 $Third = ConsoleWrite("9") Fourth() EndIf sleep(100) Get() EndFunc ;==>Third Func Fourth() If $16 = 15921906 Then; 0 --- $Fourth = ConsoleWrite("0") Fifth() ElseIf $16 = 15461355 Then; 1 --- $Fourth = ConsoleWrite("1") Fifth() ElseIf $16 = 16250871 Then; 2---? $Fourth = ConsoleWrite("2") Fifth() ElseIf $16 = 16579836 Then; 3--- $Fourth = ConsoleWrite("3") Fifth() ElseIf $16 = 13355979 Then; 4 -- $Fourth = ConsoleWrite("4") Fifth() ElseIf $16 = 16053492 Then; 5--- $Fourth = ConsoleWrite("5") Fifth() ElseIf $16 = 16119285 Then; 6--- $Fourth = ConsoleWrite("6") Fifth() ElseIf $16 = 15724527 Then; 7--- $Fourth = ConsoleWrite("7") Fifth() ElseIf $16 = 16053492 Then; 8--- $Fourth = ConsoleWrite("8") Fifth() ElseIf $16 = 16119285 Then; 9 $Fourth = ConsoleWrite("9") Fifth() EndIf sleep(100) Get() EndFunc ;==>Fourth Func Fifth() If $21 = 16382457 Then; 0 --- $Fifth = ConsoleWrite("0") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) ElseIf $21 = 15790320 Then; 1 --- $Fifth = ConsoleWrite("1") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) ElseIf $21 = 16316664 Then; 2--- $Fifth = ConsoleWrite("2") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) ElseIf $21 = 16316664 Then; 3--- $Fifth = ConsoleWrite("3") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) ElseIf $21 = 13027014 Then; 4 -- $Fifth = ConsoleWrite("4") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) ElseIf $21 = 16382457 Then; 5--- $Fifth = ConsoleWrite("5") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) ElseIf $21 = 15921906 Then; 6--- $Fifth = ConsoleWrite("6") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) ElseIf $21 = 16448250 Then; 7--- $Fifth = ConsoleWrite("7") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) ElseIf $21 = 16185078 Then; 8--- $Fifth = ConsoleWrite("8") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) ElseIf $21 = 15921906 Then; 9 $Fifth = ConsoleWrite("9") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $First & $Second & $Third & $Fourth & $Fifth) EndIf EndFunc ;==>Fifth Link to comment Share on other sites More sharing options...
Tvern Posted October 14, 2009 Share Posted October 14, 2009 I don't know a way to make this script work better, other then using 3rd party ocr, but I would advise you to store the colors in an array, rather then separate variables. It should allow you to make the script a fair bit smaller. Link to comment Share on other sites More sharing options...
Mat Posted October 14, 2009 Share Posted October 14, 2009 No speed gain, but heres the array version: expandcollapse popup#include <IE.au3> #include <Misc.au3> #include <WindowsConstants.au3> #include <Timers.au3> Global $a[26], $a2[5] $oJailPage = _IECreate("Tmnx.net/authenticated/jail.aspx",0,1,1,1) _IELoadWait($oJailPage) Sleep(3000) Get() Func Get() ;First Number $a[0] = PixelGetColor(527, 146);top $a[1] = PixelGetColor(526, 151);middle $a[2] = PixelGetColor(527, 157);bottom $a[3] = PixelGetColor(523, 151);left $a[4] = PixelGetColor(529, 151);right ;second number $a[5] = PixelGetColor(536, 146) $a[6] = PixelGetColor(535, 151) $a[7] = PixelGetColor(536, 157) $a[8] = PixelGetColor(532, 151) $a[9] = PixelGetColor(538, 151) ;third number $a[10] = PixelGetColor(545, 146) $a[11] = PixelGetColor(546, 151) $a[12] = PixelGetColor(545, 157) $a[13] = PixelGetColor(541, 151) $a[14] = PixelGetColor(547, 151) ;fourth number $a[15] = PixelGetColor(554, 146) $a[16] = PixelGetColor(555, 151) $a[17] = PixelGetColor(554, 157) $a[18] = PixelGetColor(550, 151) $a[19] = PixelGetColor(556, 151) ;fifth number $a[20] = PixelGetColor(563, 146) $a[21] = PixelGetColor(564, 151) $a[22] = PixelGetColor(563, 157) $a[23] = PixelGetColor(559, 151) $a[24] = PixelGetColor(565, 151) IniWrite("Pixel.ini", "Pixel", "1", $a[0]) IniWrite("Pixel.ini", "Pixel", "2", $a[1]) IniWrite("Pixel.ini", "Pixel", "3", $a[2]) IniWrite("Pixel.ini", "Pixel", "4", $a[3]) IniWrite("Pixel.ini", "Pixel", "5", $a[4]) IniWrite("Pixel.ini", "Pixel 2", "6", $a[5]) IniWrite("Pixel.ini", "Pixel 2", "7", $a[6]) IniWrite("Pixel.ini", "Pixel 2", "8", $a[7]) IniWrite("Pixel.ini", "Pixel 2", "9", $a[8]) IniWrite("Pixel.ini", "Pixel 2", "10", $a[9]) IniWrite("Pixel.ini", "Pixel 3", "11", $a[10]) IniWrite("Pixel.ini", "Pixel 3", "12", $a[11]) IniWrite("Pixel.ini", "Pixel 3", "13", $a[12]) IniWrite("Pixel.ini", "Pixel 3", "14", $a[13]) IniWrite("Pixel.ini", "Pixel 3", "15", $a[14]) IniWrite("Pixel.ini", "Pixel 4", "16", $a[15]) IniWrite("Pixel.ini", "Pixel 4", "17", $a[16]) IniWrite("Pixel.ini", "Pixel 4", "18", $a[17]) IniWrite("Pixel.ini", "Pixel 4", "19", $a[18]) IniWrite("Pixel.ini", "Pixel 4", "20", $a[19]) IniWrite("Pixel.ini", "Pixel 5", "21", $a[20]) IniWrite("Pixel.ini", "Pixel 5", "22", $a[21]) IniWrite("Pixel.ini", "Pixel 5", "23", $a[22]) IniWrite("Pixel.ini", "Pixel 5", "24", $a[23]) IniWrite("Pixel.ini", "Pixel 5", "25", $a[24]) ;If 0 = 0 Then; 0 --- ; MsgBox("", "0", $a[9]) ; Second() If $a[3] = 12763842 Then; 1 -- $a2[0] = ConsoleWrite("1") Second() ElseIf $a[3] = 12171705 Then; 2--- $a2[0] = ConsoleWrite("2") Second() ElseIf $a[3] = 13355979 Then; 3--- $a2[0] = ConsoleWrite("3") Second() ElseIf $a[3] = 12434877 Then; 4 -- $a2[0] = ConsoleWrite("4") Second() ElseIf $a[3] = 15527148 Then; 5--- $a2[0] = ConsoleWrite("5") Second() ElseIf $a[3] = 15856113 Then; 6--- $a2[0] = ConsoleWrite("6") Second() ElseIf $a[3] = 12961221 Then; 7--- $a2[0] = ConsoleWrite("7") Second() ElseIf $a[3] = 13421772 Then; 8--- $a2[0] = ConsoleWrite("8") Second() ElseIf $a[3] = 15461355 Then; 9 $a2[0] = ConsoleWrite("9") Second() EndIf sleep(100) get() EndFunc ;==>Get Func Second() ;If 0 = 0 Then; 0 --- ; MsgBox("", "0", $a[9]) ; Third() If $a[9] = 13092807 Then; 1 --- $a2[1] = ConsoleWrite("1") Third() ElseIf $a[9] = 16316664 Then; 2---? $a2[1] = ConsoleWrite("2") Third() ElseIf $a[9] = 16316664 Then; 3--- $a2[1] = ConsoleWrite("3") Third() ElseIf $a[9] = 16514043 Or $a[9] = 15527148 Then; 4 -- $a2[1] = ConsoleWrite("4") Third() ElseIf $a[7] = 16777215 Then; 5--- $a2[1] = ConsoleWrite("5") Third() ElseIf $a[6] = 16316664 Then; 6--- $a2[1] = ConsoleWrite("6") Third() ElseIf $a[8] = 12171705 Then; 7--- $a2[1] = ConsoleWrite("7") Third() ElseIf $a[7] = 16777215 Then; 8--- $a2[1] = ConsoleWrite("8") Third() ;ElseIf $a[3] = 15461355 Then; 9 ; MsgBox("", "9", $a[3]) ; Third() EndIf Sleep(100) get() EndFunc ;==>Second Func Third() If $a[10] = 15592941 Then; 0 --- $a2[2] = ConsoleWrite("0") Fourth() ElseIf $a[10] = 13092807 Then; 1 --- $a2[2] = ConsoleWrite("1") Fourth() ElseIf $a[10] = 16316664 Then; 2---? $a2[2] = ConsoleWrite("2") Fourth() ElseIf $a[10] = 16579836 Then; 3--- $a2[2] = ConsoleWrite("3") Fourth() ElseIf $a[10] = 14145495 Then; 4 -- $a2[2] = ConsoleWrite("4") Fourth() ElseIf $a[10] = 15527148 Then; 5--- $a2[2] = ConsoleWrite("5") Fourth() ElseIf $a[10] = 16382457 Then; 6--- $a2[2] = ConsoleWrite("6") Fourth() ElseIf $a[10] = 15856113 Then; 7--- $a2[2] = ConsoleWrite("7") Fourth() ElseIf $a[10] = 15987699 Then; 8--- $a2[2] = ConsoleWrite("8") Fourth() ElseIf $a[10] = 15658734 Then; 9 $a2[2] = ConsoleWrite("9") Fourth() EndIf sleep(100) Get() EndFunc ;==>Third Func Fourth() If $a[15] = 15921906 Then; 0 --- $a2[3] = ConsoleWrite("0") Fifth() ElseIf $a[15] = 15461355 Then; 1 --- $a2[3] = ConsoleWrite("1") Fifth() ElseIf $a[15] = 16250871 Then; 2---? $a2[3] = ConsoleWrite("2") Fifth() ElseIf $a[15] = 16579836 Then; 3--- $a2[3] = ConsoleWrite("3") Fifth() ElseIf $a[15] = 13355979 Then; 4 -- $a2[3] = ConsoleWrite("4") Fifth() ElseIf $a[15] = 16053492 Then; 5--- $a2[3] = ConsoleWrite("5") Fifth() ElseIf $a[15] = 16119285 Then; 6--- $a2[3] = ConsoleWrite("6") Fifth() ElseIf $a[15] = 15724527 Then; 7--- $a2[3] = ConsoleWrite("7") Fifth() ElseIf $a[15] = 16053492 Then; 8--- $a2[3] = ConsoleWrite("8") Fifth() ElseIf $a[15] = 16119285 Then; 9 $a2[3] = ConsoleWrite("9") Fifth() EndIf sleep(100) Get() EndFunc ;==>Fourth Func Fifth() If $a[20] = 16382457 Then; 0 --- $a2[4] = ConsoleWrite("0") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) ElseIf $a[20] = 15790320 Then; 1 --- $a2[4] = ConsoleWrite("1") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) ElseIf $a[20] = 16316664 Then; 2--- $a2[4] = ConsoleWrite("2") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) ElseIf $a[20] = 16316664 Then; 3--- $a2[4] = ConsoleWrite("3") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) ElseIf $a[20] = 13027014 Then; 4 -- $a2[4] = ConsoleWrite("4") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) ElseIf $a[20] = 16382457 Then; 5--- $a2[4] = ConsoleWrite("5") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) ElseIf $a[20] = 15921906 Then; 6--- $a2[4] = ConsoleWrite("6") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) ElseIf $a[20] = 16448250 Then; 7--- $a2[4] = ConsoleWrite("7") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) ElseIf $a[20] = 16185078 Then; 8--- $a2[4] = ConsoleWrite("8") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) ElseIf $a[20] = 15921906 Then; 9 $a2[4] = ConsoleWrite("9") $Verify = _IEGetObjById($oJailPage, "myScriptTest_txtVerify") _IEFormElementSetValue($Verify, $a2[0] & $a2[1] & $a2[2] & $a2[3] & $a2[4]) EndIf EndFunc ;==>Fifth You probably should avoid calling a function from within itself, in order to create a loop. Use a proper loop instead. Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Regency Posted October 14, 2009 Author Share Posted October 14, 2009 The script only now hangs up on the first number, it writes the first number then stops doing anything, i tried clearing the console read after it writes it, but no clue why it is doing this.. anyone? BTW thank you for the array'd version! 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