Jump to content

_PixelSearchX


seandisanti
 Share

Recommended Posts

there were a couple of topics on this in the last few days,seemed a simple udf might be in order...

;This is a UDF to perform a pixelsearch for multiple colors.
;pass a 1 based array (with element 0 being a count of colors) of colors, function returns a 2 dimensional array, with coords for each found color.
;each color not found will have coordinates -1,-1.  if no colors found, @error is set to 1

Func _PixelSearchX($left, $top, $right, $bottom, $ColorArray, $ShadeVar = 0, $step = 1)
    If Not IsArray($ColorArray) Then Return (PixelSearch($left, $top, $right, $bottom, $ColorArray, $ShadeVar, $step))
    Dim $ToBeReturned[$ColorArray[0]][2]
    $ToBeReturned[0][0] = $ColorArray[0]
    $x = 1
    Local $tmp[2]
    $found = 0
    While $x <= $ColorArray[0]
        $tmp = PixelSearch($left, $top, $right, $bottom, $ColorArray[$x], $ShadeVar, $step)
        If Not @error Then
            $ToBeReturned[$x][0] = $tmp[0]
            $ToBeReturned[$x][1] = $tmp[1]
            $found = 1
        Else
            $ToBeReturned[$x][0] = -1
            $ToBeReturned[$x][1] = -1
        EndIf
        $x = $x + 1
    WEnd
    If Not $found Then
        SetError(1)
    Else
        Return ($ToBeReturned)
    EndIf
EndFunc ;==>_PixelSearchX
Edited by cameronsdad
Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...

this seems very useful but can you explain a little more

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

  • Moderators

I still don't quite understand. Can you give me an example?

This is what I had in mind, but it throws errors.

#include <Array.au3>

$NumColors = 3
$Color_1 = 21989
$Color_2 = 15526360
$Color_3 = 13421772

$Color_Array = _ArrayCreate($NumColors, $Color_1, $Color_2, $Color_3)

$ReturnArray = _PixelSearchX(1, 1, (@DesktopWidth-1), (@DesktopHeight-1), $Color_Array)

_ArrayDisplay($ReturnArray, "This is your pixelsearch array.")
Link to comment
Share on other sites

This is what I had in mind, but it throws errors.

#include <Array.au3>

$NumColors = 3
$Color_1 = 21989
$Color_2 = 15526360
$Color_3 = 13421772

$Color_Array = _ArrayCreate($NumColors, $Color_1, $Color_2, $Color_3)

$ReturnArray = _PixelSearchX(1, 1, (@DesktopWidth-1), (@DesktopHeight-1), $Color_Array)

_ArrayDisplay($ReturnArray, "This is your pixelsearch array.")
thats exactly what i tried but it showed 2 numbers

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Here, try this:

#include <Array.au3>

$NumColors = 3
$Color_1 = 21989
$Color_2 = 15526360
$Color_3 = 13421772

$Color_Array = _ArrayCreate($NumColors, $Color_1, $Color_2, $Color_3)

$ReturnArray = _PixelSearchX(1, 1, (@DesktopWidth-1), (@DesktopHeight-1), $Color_Array)

$msg = ""

For $i = 1 To $ReturnArray[0][0]
    $msg &= $ReturnArray[$i][0] & ", " & $ReturnArray[$i][1] & @CRLF
Next
MsgBox (0, $ReturnArray[0][0] & " colors seached, " & $ReturnArray[0][1] & " colors found", $msg)

Func _PixelSearchX($left, $top, $right, $bottom, $ColorArray, $ShadeVar = 0, $step = 1)
    If Not IsArray($ColorArray) Then Return (PixelSearch($left, $top, $right, $bottom, $ColorArray, $ShadeVar, $step))
    Dim $ToBeReturned[$ColorArray[0]+1][2] = [[$ColorArray[0], 0]]
    Local $tmp[2]
    For $x = 1 To $ColorArray[0]
        $tmp = PixelSearch($left, $top, $right, $bottom, $ColorArray[$x], $ShadeVar, $step)
        If Not @error Then
            $ToBeReturned[$x][0] = $tmp[0]
            $ToBeReturned[$x][1] = $tmp[1]
            $ToBeReturned[0][1] += 1
        Else
            $ToBeReturned[$x][0] = -1
            $ToBeReturned[$x][1] = -1
        EndIf
    Next
    If ($ToBeReturned[0][1] = 0) Then SetError(1)
    Return $ToBeReturned
EndFunc;==>_PixelSearchX

Requires beta for += and &=, but that can be changed if required.

Link to comment
Share on other sites

Here, try this:

#include <Array.au3>

$NumColors = 3
$Color_1 = 21989
$Color_2 = 15526360
$Color_3 = 13421772

$Color_Array = _ArrayCreate($NumColors, $Color_1, $Color_2, $Color_3)

$ReturnArray = _PixelSearchX(1, 1, (@DesktopWidth-1), (@DesktopHeight-1), $Color_Array)

$msg = ""

For $i = 1 To $ReturnArray[0][0]
    $msg &= $ReturnArray[$i][0] & ", " & $ReturnArray[$i][1] & @CRLF
Next
MsgBox (0, $ReturnArray[0][0] & " colors seached, " & $ReturnArray[0][1] & " colors found", $msg)

Func _PixelSearchX($left, $top, $right, $bottom, $ColorArray, $ShadeVar = 0, $step = 1)
    If Not IsArray($ColorArray) Then Return (PixelSearch($left, $top, $right, $bottom, $ColorArray, $ShadeVar, $step))
    Dim $ToBeReturned[$ColorArray[0]+1][2] = [[$ColorArray[0], 0]]
    Local $tmp[2]
    For $x = 1 To $ColorArray[0]
        $tmp = PixelSearch($left, $top, $right, $bottom, $ColorArray[$x], $ShadeVar, $step)
        If Not @error Then
            $ToBeReturned[$x][0] = $tmp[0]
            $ToBeReturned[$x][1] = $tmp[1]
            $ToBeReturned[0][1] += 1
        Else
            $ToBeReturned[$x][0] = -1
            $ToBeReturned[$x][1] = -1
        EndIf
    Next
    If ($ToBeReturned[0][1] = 0) Then SetError(1)
    Return $ToBeReturned
EndFunc;==>_PixelSearchX

Requires beta for += and &=, but that can be changed if required.

That works great, thanks.

What about multiple occourences???

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

That works great, thanks.

What about multiple occourences???

Multiple occurrences, like more than one pixel of a certain search color? PixelSearch only returns the first match, so unless an option is added to PixelSearch that returns all matches (which, by the way, would really slow down the function), I don't see that as an option for this. It could be done I suppose, but it would be a very difficult task (at least the way I imagine it).

Link to comment
Share on other sites

Multiple occurrences, like more than one pixel of a certain search color? PixelSearch only returns the first match, so unless an option is added to PixelSearch that returns all matches (which, by the way, would really slow down the function), I don't see that as an option for this. It could be done I suppose, but it would be a very difficult task (at least the way I imagine it).

yeah but I think that atleast pixelsearch shoul have that option or atleast a function called pixelfindnext, what do u think

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

  • 10 months later...

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