Jump to content

PixelChecksum - PixelSearch


Recommended Posts

is there some way to compare two PixelChecksum's in a more "diffuse" way ? I'd like to know how to simulate the PixelSearch Shade-Variation when using PixelChecksum. This is needed for some simple OCR experiment for a game.

...Fenster fährt mich Nüsse...
Link to comment
Share on other sites

I was able to do what i wanted via PixelSearch.

Now, how can i create a PixelChecksum of a certain are on the screen and then use it to find that exact location on the screen again ?

Draft:

$bla=CreatePixelChecksum(screenarea)

LocateChecksum(screen,$bla)

Thanks folks.

...Fenster fährt mich Nüsse...
Link to comment
Share on other sites

  • Moderators

I was able to do what i wanted via PixelSearch.

Now, how can i create a PixelChecksum of a certain are on the screen and then use it to find that exact location on the screen again ?

Draft:

$bla=CreatePixelChecksum(screenarea)

LocateChecksum(screen,$bla)

Thanks folks.

What have you tried? Seems like 2 For/Next Loops to me... (the answer I gave, the example I didn't (look familiar :D :D )

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.

Link to comment
Share on other sites

  • 2 weeks later...

What have you tried? Seems like 2 For/Next Loops to me... (the answer I gave, the example I didn't (look familiar :D :D )

Ok, doing a pixelchecksum search via 0 to height nested in 0 to width works but very SLOOOOOWLY, is this the only way to do it?

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
Share on other sites

Ok, doing a pixelchecksum search via 0 to height nested in 0 to width works but very SLOOOOOWLY, is this the only way to do it?

No, let's say you pixelchecksumed from 200, 200 to 300, 300.

You get the value $myCheckSum.

You also stored the color of 200, 200 in a vairable called $topLeftColor.

You PixelSearch for $topLeftColor and check whether it is the thing you want by PixelCheckSumming the appropriate area.

Hope I make any sense.

#)

Link to comment
Share on other sites

Thanks, I finally figured it out with the PixelAreaFind.au3 example.

I'm going to post code shortly of what I have been working on. - Posted

Instructions:

Needs beta to run.

Start it up.

Setup for area to PixelCheckSum.... I minimized everything and used my desktop.

Move mouse to Top/Left corner of area you want to PixelCheckSum.

Press either Shift key once.

Move mouse to Bottom/Right corner.

Press either Shift key again.

MessageBox will pop up with Left/Top/Bottom/Right/Width/Height/Top-Left Pixel color and PixelCheckSum for the area you have selected.

You can click OK or it will time out. (Put the time out in because I selected the entire screen once and couldn't get back to messagebox to click OK - lesson learned)

After that press the ~ (tilde) key and it will attempt to find the area you selected before. Doesn't work very well. Still trying to figure out how it's searching.

#include <GUIConstants.au3>
#include <Misc.au3>

HotKeySet("`","_Find_Checksum")

Global Const $SM_VIRTUALWIDTH = 78
Global Const $SM_VIRTUALHEIGHT = 79

Global $Pixel = 0
Global $Checksum = 0

$VIRTUALDESKTOPWIDTH = DLLCall("user32.dll","int","GetSystemMetrics","int",$SM_VIRTUALWIDTH)
$VIRTUALDESKTOPWIDTH = $VIRTUALDESKTOPWIDTH[0]
$VIRTUALDESKTOPHEIGHT = DLLCall("user32.dll","int","GetSystemMetrics","int",$SM_VIRTUALHEIGHT)
$VIRTUALDESKTOPHEIGHT = $VIRTUALDESKTOPHEIGHT[0]

$Click = 0
$Top = 0
$Left = 0
$Bottom = 0
$Right = 0
$Width = 0
$Height = 0
$Transparency = 100
$Checksum = ""
$dll = DllOpen("user32.dll")
$yPixel = 0

While 1
    Sleep(10)
    $Pos = MouseGetPos()
    If _IsPressed("10", $dll) And $Click = 0 Then
        _Start()
    ElseIf _IsPressed("10", $dll) And $Click = 1 Then
        _End()
    ElseIf $Click = 1 Then
        SplashTextOn("PixelCheckSumBox", "", $Pos[0] - $Left, $Pos[1] - $Top, $Left, $Top, 1 + 16)
        WinSetTrans("PixelCheckSumBox", "", $Transparency)
    ElseIf _IsPressed("1B", $dll) Then
        DllClose($dll)
        Exit
    EndIf

WEnd
Exit

Func _Start()
    $Left = $Pos[0]
    $Top = $Pos[1]
    $Pixel = PixelGetColor($Left, $Top)
    $Click = 1
    Sleep(100)
EndFunc

Func _End()
    $Right = $Pos[0]
    $Bottom = $Pos[1]
    $Width = $Right - $Left + 1
    $Height = $Bottom - $Top + 1
    $Click = 2
    $Checksum = PixelChecksum($Left, $Top, $Right, $Bottom)
    Sleep(1000)
    _Checksum()
EndFunc

Func _Checksum()
    MsgBox(0,"PixelCheckSumBox information...", "" _ 
    & "Left = " & $Left  & "  " & "Top = " & $Top & @CRLF _
    & "Right = " & $Right & "  " & "Bottom = " & $Bottom & @CRLF _
    & "Width = " & $Width & "  " & "Height = " & $Height & @CRLF _
    & "Pixel Color at " & $Left & " x " & $Top & " is " & $Pixel & @CRLF _
    & "PixelCheckSum = " & $Checksum, 10)
    $Click = 0
    SplashOff()
    Sleep(100)
EndFunc

Func _Find_Checksum()
    $x = 0
    $y = 0
    $yPixel = $VIRTUALDESKTOPHEIGHT - 1
    While 1
        $xy = PixelSearch($x,$y,$VIRTUALDESKTOPWIDTH - 1,$yPixel,$Pixel)
        If @error And $yPixel = ($VIRTUALDESKTOPHEIGHT - 1)Then
            MsgBox(4096,"Sorry","Couldn't locate it.")
            Exit
        ElseIf @error Then
            $y = $yPixel + 1
            $yPixel = ($VIRTUALDESKTOPHEIGHT - 1)
            $x = 0
        ElseIf $Checksum = PixelCheckSum($Width, $Height, $xy[0], $xy[1]) Then
            MouseMove($xy[0],$xy[1])
            SplashTextOn("PixelCheckSumBox", "", $xy[0], $xy[1], $Width, $Height, 1 + 16)
            WinSetTrans("PixelCheckSumBox", "", $Transparency)
            Sleep(3000)
            Exit
        Else
            $y = $xy[1]
            $yPixel = $y
            $x = $xy[0] + 1
        EndIf
    WEnd
EndFunc

If you recognize some of your code - THANKS it helped me learn alot.

Edited by Fossil Rock

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
Share on other sites

The results from the previous efforts just didn't do what I wanted. So I rewrote it.

Explaination: This, simply put, allows you to select a portion (any size) of your screen and then it gives you the information of the selected area . Then it attempts to find the area you selected.

Gotta say, so far it's got a 100% success rate.

More features planned... stay tuned.

Feedback and bug reports welcome.

Edit: Forgot to mention it requires Beta

Instructions:

Start the script.

Position your mouse pointer to where you want to begin

Press either Shift key

Reposition your mouse pointer (down & right) to complete the selection area.

Press either Shift key again.

Self explanitory beyond that.

; PixelCheckSum tool thingy.

#include <GUIConstants.au3>
#include <Misc.au3>

$x = 0; Search coordinate for Height
$y = 0; Search coordinate for Width
$Pos = 0; Mouse coordinates
$Press = 0; Button press counter
$Top = 0; Top of search area
$Left = 0; Left of search area
$Bottom = 0; Bottom of search area
$Right = 0; Right of search area
$Width = 0; Width of search area
$Height = 0; Height of search area
$Transparency = 100; Transparency for SplashText
$Checksum = ""; Initial Checksum value
$dll = DllOpen("user32.dll"); Needed for IsPressed
$Pixel = ""; Initial Pixel value
$Count = 0
$L = 0
$T = 0
$C = 0

While 1; Main routine... waiting for you to do something
    $Pos = MouseGetPos()
    If _IsPressed("10", $dll) And $Press = 0 Then
        Sleep(50)
        _Start()
    ElseIf _IsPressed("10", $dll) And $Press = 1 Then
        Sleep(50)
        _End()
    ElseIf $Press = 1 Then
        SplashTextOn("PixelCheckSumBox", "",  _
                $Pos[0] - $Left,  _
                $Pos[1] - $Top,  _
                $Left,  _
                $Top,  _
                1 + 16)
        WinSetTrans("PixelCheckSumBox", "", $Transparency)
    ElseIf _IsPressed("1B", $dll) Then
        DllClose($dll)
        Exit
    EndIf
WEnd

Func _Start()
    $Left = $Pos[0]
    $Top = $Pos[1]
    $Pixel = PixelGetColor($Left, $Top); Gets the Pixel color to search for
    $Press = 1
    Sleep(100)
EndFunc

Func _End()
    $Right = $Pos[0]
    $Bottom = $Pos[1]
    $Width = $Right - $Left + 1
    $Height = $Bottom - $Top + 1
    $Press = 2
    $Checksum = PixelChecksum($Left, $Top, $Right, $Bottom); Gets the PixelCheckSum for the area selected
    Sleep(100)
    MsgBox(0,"Box information...", "" _
        & "Left = " & $Left  & "  " & "Top = " & $Top & @CRLF _
          & "Right = " & $Right & "  " & "Bottom = " & $Bottom & @CRLF _
        & "Width = " & $Width & "  " & "Height = " & $Height & @CRLF _
        & "Pixel at " & $Left & " x " & $Top & " is " & $Pixel & @CRLF _
        & "PixelChecksum = " & $Checksum)
    $Press = 0
    SplashOff()
    Sleep(1000)
    MsgBox(0,"Begin search","I'll try to find what you selected now.")
    _Find_Pixel()
EndFunc

Func _Find_Pixel()
    For $y = 0 to @DesktopWidth -1
        For $x = 0 to @DesktopHeight -1
            $pgc = PixelGetColor($x,$y)
            If $pixel = $pgc Then
                SplashTextOn("PixelCheckSumBox", "", $Width, $Height, $x, $y, 1 + 16)
                WinSetTrans("PixelCheckSumBox", "", $Transparency)
                GUICtrlSetData($T, PixelCheckSum($x, $y, $Right, $Bottom))
                _Do_Checksum($x, $y)
            EndIf
        Next
    Next
    MsgBox(0,"Search Complete","All done.")
    Exit
EndFunc

Func _Do_Checksum($a, $b)
    GUICtrlSetData($C, "Checking")
    If $Checksum = PixelCheckSum($a, $b, $Right, $Bottom) Then
        MouseMove($a + ($Width / 2),$b + ($Height / 2))
        GUICtrlSetData($C, "Match Found")
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(36,"Continue...","Keep searching?")
Select
   Case $iMsgBoxAnswer = 6;Yes
;       MsgBox(0,"Test","You pressed Yes")
   Case $iMsgBoxAnswer = 7;No
        Exit
EndSelect
EndIf
    GUICtrlSetData($C, "Searching")
EndFunc
Edited by Fossil Rock

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

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...