Jump to content

Help with pixel search and color


Recommended Posts

Hello,

Its what i need is to search for the color blue in a window but might have more than the same color ( has to be close to each other ) Then if has a match searches each side of the 2 blues for other blues and clicks if finds the 3 blue.

For example:

__1____2_______ 3

Blue__Blue____Red

_____________^

__4____5___6_|

Yellow Red Blue

So basically first finds "1" then cause of "1" does a search for more blues which is so many pixels away and found "2" then added them together and then did a search and found 6 and clicks and hold left mouse from the "6" position and then the "3" position.

Any help is much appreciated thanks :)

Edited by Zer0Velocity
Link to comment
Share on other sites

If its hard to explain it is even hard to understand. If you wish for us to help you you will have provide us with enough detailed information Ex Coord MousClicks and Moves. Or look at example scripts and use the Help Files to create the script yourself. :)

Edited by inline853
Link to comment
Share on other sites

Just use a combination of PixelGetColor ,If/Then and Loops.

Something like this to search a 10 x 10 area for example.

x = 10

y = 10

$colortofind = 13421772

For i = 1 to y

For j = 1 to x

$test = PixelGetColor (j,i)

If $test = 13421772 then

$test2 = PixelGetColor (j + 10,i) <----to search x + 10 pixels

If $test2 = $colortofind then

msgbox found

endif

endif

Next j

Next i

Sorry I don't feel like coding this all the way but this should give you a general idea.

Kohr

Link to comment
Share on other sites

But it don't seem to get msgbox?

$x = 250

$y = 250

$colortofind = 16432444

For $i = 1 to $y

For $j = 1 to $x

$test = PixelGetColor ($j,$i)

If $test = 16432444 then

$test2 = PixelGetColor ($j + 10,$i) ; <----to search x + 10 pixels

If $test2 = $colortofind then

msgbox found

endif

endif

Next $j

Next $i

Link to comment
Share on other sites

I see no reason why Kohr's method should not work, it is what I would have suggested first. If you are having problems with that method, I would suggest just using PixelCheckSum. It will compare the primary pixel to the relation of all the pixels around it of the same color.

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

Link to comment
Share on other sites

This is the Baseline code I use to show howto use PixelCheckSum.

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"))
    
    $sv = 0
    $w = 1
    $x = 5 ;LEFT pixel of Total Area to Search for $pixel
    $y = 5 ;TOP 
    $xpixel = @DesktopWidth - 5 ;Right
    $ypixel = @DesktopHeight - 5 ;Bottom
    
    While $w = 1
        $xy = PixelSearch($x,$y,$xpixel,$ypixel,$pixel, $sv)
        If $w = 3 Then 
            Exit
        EndIf

        If @error And $ypixel = (@DesktopHeight - 5)Then
            MsgBox(4096,"@Error ","Could not find Checksum" & @LF & '     Finished Searching all of Screen', 4)
            SetError(1)
            Return 0
        ElseIf @error Then
            $y = $ypixel + 1
            $ypixel = (@DesktopHeight - 5)
            $x = 0
            ;MsgBox(4096,"@Error","Could not find Checksum" & @LF & '     looking again in 2sec', 2)
        ElseIf $chksum = PixelCheckSum($xy[0]-5, $xy[1]-5, $xy[0]+5, $xy[1]+5) Then 
            $w = 3          ;PixelCheckSum(left, top, right, bottom [, step] )
            MouseMove($xy[0],$xy[1], 30)
            ToolTip("Found Checksum")
                $pos = MouseGetPos()
                MouseMove( $pos[0], $pos[1] -5, 20)     ;Top
                MouseMove( $pos[0] +5, $pos[1], 20)     ;Right
                MouseMove( $pos[0], $pos[1] +5, 20)     ;Bottom
                MouseMove( $pos[0] -5, $pos[1], 20)     ;Left
            ;Exit
        Else
            $y = $xy[1]
            $ypixel = $y
            $x = $xy[0] + 1
        EndIf
    WEnd
EndFunc

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

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

Link to comment
Share on other sites

How would i use that code to do a double search on 2 colours the same? Cause when i use the ` key it finds the right colour and moves the mouse around it.

Can you post a link to a screenshot or something? How close are the two pixels you are trying to find to each other ?

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

Link to comment
Share on other sites

Yup, now i understand, thanks for the Pic. With that kind of Layout you could get away with just looking for one pixel and then another (pixelsearch as opposed to pixelchecksum). I would suggest just giving the function an output of the CoOrds, and then you can create your Logic based on whatever you want to do with the Location. Like match 3 in a row or whatever.

I think it was Smoke_N who made a script awile back as an example that did a search for all instances of a checksum and returned an array? (Dont remember exactly) You could look for that script or just add array output to this one and nest it to search the whole area.

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

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