Sign in to follow this  
Followers 0
cili1

"Continueing a PixelSearch"

8 posts in this topic

The search is performed left-to-right, top-to-bottom and the first match is returned.

How do I make a PixelSearch function that continues after the first result.

Example:

Start PixelSearch

Found matching pixel!

Msgbox(Cords)

Looking for next.

Found matching pixel 2!

Msgbox(Cords)

And so on...

Share this post


Link to post
Share on other sites



Get the cords and add 1 to it them do a search again, easy right!

WolfWorld, your answers are of poor quality and never provide much insight in the task at hand at all. Sometimes you misinform people completely by giving wrong answers. Giving a bad answer is not always avoidable but when 95% of the time your answers are bad and hastily made up, I think it might be time to stop.

As for the original question. What WolfWorld is suggesting requires that you fragment the screen in a lot of seperate ways, creating a large and complicated recursive function that searches the screen.

What I suggest as a more simple approach is using PixelGetColor to loop through the screen like this:

_PixelSearchScreen(0xFF00FF)

Func _PixelSearchScreen($color)
   $w = @DesktopWidth
   $h = @DesktopHeight
   For $x = 0 to $w
      For $y = 0 to $h
         If (PixelGetColor($x, $y) == $color)) Then
            _FoundColor($x, $y)
         EndIf
      Next
   Next
EndFunc

Func _FoundColor($x, $y)
   ConsoleWrite("Color was found on: " & $x & ", " & $y & @CRLF)
EndFunc

You'll find that this is rather slow! So I suggest using the UDF I wrote that significantly increases speed for a pixelsearch operation:

http://www.autoitscript.com/forum/index.php?showtopic=63318

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

WolfWorld, your answers are of poor quality and never provide much insight in the task at hand at all. Sometimes you misinform people completely by giving wrong answers. Giving a bad answer is not always avoidable but when 95% of the time your answers are bad and hastily made up, I think it might be time to stop.

As for the original question. What WolfWorld is suggesting requires that you fragment the screen in a lot of seperate ways, creating a large and complicated recursive function that searches the screen.

What I suggest as a more simple approach is using PixelGetColor to loop through the screen like this:

_PixelSearchScreen(0xFF00FF)

Func _PixelSearchScreen($color)
   $w = @DesktopWidth
   $h = @DesktopHeight
   For $x = 0 to $w
      For $y = 0 to $h
         If (PixelGetColor($x, $y) == $color)) Then
            _FoundColor($x, $y)
         EndIf
      Next
   Next
EndFunc

Func _FoundColor($x, $y)
   ConsoleWrite("Color was found on: " & $x & ", " & $y & @CRLF)
EndFunc

You'll find that this is rather slow! So I suggest using the UDF I wrote that significantly increases speed for a pixelsearch operation:

http://www.autoitscript.com/forum/index.php?showtopic=63318

That you provide his slow cause you are looping all the possible cords by using Autoit script itself.

You can do this it's much faster and it work just the same.

_PixelSearchScreen(0xFFFFFF)

Func _PixelSearchScreen($color, $x = 0, $y = 0)
    $aTemp = PixelSearch($x, $y,@DesktopWidth, @DesktopHeight, $color)
    If (Not @error) Then
        _FoundColor($aTemp[0], $aTemp[1])
        If ($aTemp[0] < @DesktopWidth) And ($aTemp[1] < @DesktopHeight) Then _PixelSearchScreen($color, $aTemp[0] + 1, $aTemp[1])
    EndIf
EndFunc   ;==>_PixelSearchScreen

Func _FoundColor($x, $y)
    ConsoleWrite("Color was found on: " & $x & ", " & $y & @CRLF)
EndFunc   ;==>_FoundColor

Is this the better answer now?

Edited by WolfWorld

Share this post


Link to post
Share on other sites

Thank you both!

I'll be going with Manadar's code since it was easy to modify and fast enough for what I need.

Share this post


Link to post
Share on other sites

That you provide his slow cause you are looping all the possible cords by using Autoit script itself.

You can do this it's much faster and it work just the same.

_PixelSearchScreen(0xFFFFFF)

Func _PixelSearchScreen($color, $x = 0, $y = 0)
    $aTemp = PixelSearch($x, $y,@DesktopWidth, @DesktopHeight, $color)
    If (Not @error) Then
        _FoundColor($aTemp[0], $aTemp[1])
        If ($aTemp[0] < @DesktopWidth) And ($aTemp[1] < @DesktopHeight) Then _PixelSearchScreen($color, $aTemp[0] + 1, $aTemp[1])
    EndIf
EndFunc   ;==>_PixelSearchScreen

Func _FoundColor($x, $y)
    ConsoleWrite("Color was found on: " & $x & ", " & $y & @CRLF)
EndFunc   ;==>_FoundColor

Is this the better answer now?

Your answer is much improved. However, as I said the problem is not the answer, it's the overall behavior. If all your posts were of this quality then this forum would be a much better place, ultimately benefiting everyone.

However, your answer is still flawed. This is the search behavior that your function has where the black dots are found colors. The gray areas are new searches, and the red pieces are missed completely.

Posted Image

Share this post


Link to post
Share on other sites

I think I addressed this in my PixelAreaFind...the code is old and delapidated but the idea is to search, find, search to the end of the line, then start the search at the the next row.

here is a snippet that I don't have time to clean up...

Func find()
    $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,"Error","Could not find area.")
            Exit
        ElseIf @error Then
            $y = $ypixel + 1
            $ypixel = ($VIRTUALDESKTOPHEIGHT - 1)
            $x = 0
        ElseIf String($chksum) = String(PixelCheckSum($xy[0]-5,$xy[1]-5,$xy[0]+5,$xy[1]+5)) Then
            MouseMove($xy[0],$xy[1])
            ToolTip("There it is.")
            Sleep(3000)
            Exit
        Else
            $y = $xy[1]
            $ypixel = $y
            $x = $xy[0] + 1
        EndIf
    WEnd
EndFunc

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

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