Sign in to follow this  
Followers 0
ofLight

alittle help with PixelCheckSum \ PixelSearch

6 posts in this topic

I have tried Larrys old Script and it is 100% accurate and reliable, but i am trying to move over to the new PixelCheckSum.

http://www.autoitscript.com/forum/index.ph...xelRectFromFile

This is my current script, it Works, but only Sometimes... and only if i select a VERY unique pixel to look for. I need a way to make it More reliable, and I need to be able to select a starting pixel that is NOT unique.

Any Suggestions would be greatly Appreciated, TY

HotKeySet("`","_find")
HotKeySet("~","record")
HotKeySet('{esc}', '_Exit')

Global $msg =   "Press Shift+tilde to Record " & @LF & _
                "Press tilde to Find " & @LF & _
                "info saved in Pixel.ini" 
Global $xy,$currentpixel

;If $pixel = -1 Or $chksum = -1 Then
;   MsgBox(4096,"Error","Could not read INI")
;   Exit
;EndIf

While 1
    $xy = MouseGetPos()
    $currentpixel = PixelGetColor($xy[0],$xy[1])
    ToolTip("Pixel color = " & $currentpixel & @LF & $msg)
    Sleep(100)
WEnd

Func record()
    IniWrite(".\Pixel.ini","Main","PixelColor",$currentpixel)
    Local $chksum = PixelChecksum($xy[0]-5, $xy[1]-5, $xy[0]+5, $xy[1]+5)
    IniWrite(".\Pixel.ini","Main","PixelCheckSum",$chksum)
    MsgBox(4096,"","Pixel Area Recorded." & @LF & @LF & "See INI file for details.", 2)
    ;Exit
EndFunc

Func _find()
    Local $pixel =  Int(IniRead(".\Pixel.ini","Main","PixelColor","-1"))
    Local $chksum = Int(IniRead(".\Pixel.ini","Main","PixelCheckSum","-1"))
    
    $w = 1
    $x = 5
    $y = 5
    $ypixel = @DesktopHeight - 5
    $xpixel = @DesktopWidth - 5
        
    While $w = 1
        $xy = PixelSearch($x,$y,$xpixel,$ypixel,$pixel)
        If $w = 3 Then 
            Exit
        EndIf
        If @error Then
            $y = $ypixel + 1
            $ypixel = (@DesktopHeight - 1)
            $x = 0
            _cont()
            ;$w = 2
        ElseIf $chksum = PixelCheckSum($xy[0]-5, $xy[1]-5, $xy[0]+5, $xy[1]+5) Then
            $w = 3
            MouseMove($xy[0],$xy[1], 30)
            ToolTip("Found Checksum")
                $pos = MouseGetPos()
                MouseMove( $pos[0], $pos[1] -10, 20)        ;Top
                MouseMove( $pos[0] +10, $pos[1], 20)        ;Right
                MouseMove( $pos[0], $pos[1] +10, 20)        ;Bottom
                MouseMove( $pos[0] -10, $pos[1], 20)        ;Left
            ;Exit
        Else
            MsgBox(4096, 'Error', 'Not @Error, and cant find checksum', 5)
            $w = 2 
        EndIf
    WEnd
EndFunc

Func _cont()
    MsgBox(4096,"@Error","Could not find Checksum" & @LF & '     looking again in 3sec', 3)
    _find() 
EndFunc 

Func _Exit()
    ToolTip('          '&@CRLF&'  EXITING  '&@CRLF&'          ')
    Sleep(500)
    Exit
EndFunc

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post


Link to post
Share on other sites




[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thank You for the Post Smoke.

Ive Looked at Your Script and Mine, and i think i see what the problem with mine is. The reason its not reliable is Because it only finds the First Instance of the Correct pixel, and then checks the Checksum. When this doesnt match the script fails.

So now I need to figure out howto tell my script to Skipover/Ignore a location that Matches the Pixel but not the Checksum.

Any Ideas guys??


There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thank You for the Post Smoke.

Ive Looked at Your Script and Mine, and i think i see what the problem with mine is. The reason its not reliable is Because it only finds the First Instance of the Correct pixel, and then checks the Checksum. When this doesnt match the script fails.

So now I need to figure out howto tell my script to Skipover/Ignore a location that Matches the Pixel but not the Checksum.

Any Ideas guys??

Yeah... Use the one I posted. Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

All Right got it Working. Thanks for the Help Guys.

Just in case anyone wants to see, this is the result. Seems to work every time, as long as you specify an appropriate size for the checksum based on how complex or simple a Word or character u are looking for.

HotKeySet("`","_find")
HotKeySet("~","record")
HotKeySet('{esc}', '_Exit')

Global $msg =   "Press Shift+tilde to Record " & @LF & _
                "Press tilde to Find " & @LF & _
                "info saved in Pixel.ini" 
Global $xy,$currentpixel

;If $pixel = -1 Or $chksum = -1 Then
;   MsgBox(4096,"Error","Could not read INI")
;   Exit
;EndIf

While 1
    $xy = MouseGetPos()
    $currentpixel = PixelGetColor($xy[0],$xy[1])
    ToolTip("Pixel color = " & $currentpixel & @LF & $msg)
    Sleep(100)
WEnd

Func record()
    IniWrite(".\Pixel.ini","Main","PixelColor",$currentpixel)
    Local $chksum = PixelChecksum($xy[0]-15, $xy[1]-15, $xy[0]+15, $xy[1]+15)
    IniWrite(".\Pixel.ini","Main","PixelCheckSum",$chksum)
    MsgBox(4096,"","Pixel Area Recorded." & @LF & @LF & "See INI file for details.", 2)
    ;Exit
EndFunc

Func _find()
    Local $pixel =  Int(IniRead(".\Pixel.ini","Main","PixelColor","-1"))
    Local $chksum = Int(IniRead(".\Pixel.ini","Main","PixelCheckSum","-1"))
    
    $w = 1
    $x = 5
    $y = 5
    $ypixel = @DesktopHeight - 5
    $xpixel = @DesktopWidth - 5
    $sv = 0
    
    While $w = 1
        $xy = PixelSearch($x,$y,$xpixel,$ypixel,$pixel, $sv)
        
        ;MouseMove($xy[0],$xy[1], 30)
        
        
        If $w = 3 Then 
            Exit
        EndIf

        If @error And $ypixel = (@DesktopHeight - 1)Then
            SetError(1)
            Return 0
        ElseIf @error Then
            $y = $ypixel + 1
            $ypixel = (@DesktopHeight - 1)
            $x = 0
            ;_cont()
        ElseIf $chksum = PixelCheckSum($xy[0]-15, $xy[1]-15, $xy[0]+15, $xy[1]+15) Then
            $w = 3
            MouseMove($xy[0],$xy[1], 30)
            ToolTip("Found Checksum")
                $pos = MouseGetPos()
                MouseMove( $pos[0], $pos[1] -10, 20)        ;Top
                MouseMove( $pos[0] +10, $pos[1], 20)        ;Right
                MouseMove( $pos[0], $pos[1] +10, 20)        ;Bottom
                MouseMove( $pos[0] -10, $pos[1], 20)        ;Left
            ;Exit
        Else
            $y = $xy[1]
            $ypixel = $y
            $x = $xy[0] + 1
            ;$sv = $sv+1
            ;Sleep(50)
            ;MsgBox(4096, 'Error', 'Not @Error, and cant find checksum'&@CRLF&$sv, 2)
            ;$w = 2 
        EndIf
    WEnd
EndFunc

Func _cont()
    MsgBox(4096,"@Error","Could not find Checksum" & @LF & '     looking again in 2sec', 2)
    _find() 
EndFunc 

Func _Exit()
    ToolTip('          '&@CRLF&'  EXITING  '&@CRLF&'          ')
    Sleep(500)
    Exit
EndFunc

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You're doing this for an OCR?

Anyway... on your code, you could definitely run into a recursion issue there.

Edit:

Never mind, I didn't notice (hard to see) that you commented out _cont().

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
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
Sign in to follow this  
Followers 0