Jump to content

Pixel search Counter


gcdot
 Share

Recommended Posts

Hi i need help with the code below. It works exactly how i want it to except it only looks for one point and quits.

My screen resolution is 1280 x 1024 so the search area is set up for 0, 0, 1280, 1024. On my screen i am looking for lets say hot pink pixels so my color is 0xFF00FF.

I simply want this program to count how many pixels it sees in the screen and tell me where the coordinates are.

The codes below do the job but only give out one cordinate, i want it to list every single coordinate found and since the colors i am looking for is so unique it should only produce a few dozens at the most.

$coord = PixelSearch(0, 0, 1280, 1024, 0xFF00FF, 50)
If Not @error Then
    MsgBox(0, "Results", "X = " & $coord[0] & "  Y = "  & $coord[1])
EndIf

I went through 3 hours of searching this forum and cannot find any links, if there is a link please post it otherwise any help would be greatly appreciated!

Link to comment
Share on other sites

try this

Dim $X = 0, $Y = 0 
DO $coord = PixelSearch($X, $Y, 1280, 1024, 0xFF00FF, 50)
If Not @error Then
MsgBox(0, "Results", "X = " & $coord[0] & " Y = " & $coord[1]) 
$X = $coord[0] 
$Y = $coord[1] 
EndIf
 UNTIL $X >= 1280 OR $Y >= 1024

For further improvement, say you want all result altogether, you can easily store it in array.

Edited by RazorTorque4X
Link to comment
Share on other sites

Dim $X = 0, $Y = 0 
DO 
$coord = PixelSearch($X, $Y, 1280, 1024, 0xFF00FF, 50)
If Not @error Then
MsgBox(0, "Results", "X = " & $coord[0] & " Y = " & $coord[1]) 
$X = $coord[0] 
$Y = $coord[1] 
EndIf
 UNTIL $X >= 1280 OR $Y >= 1024

I can't see how that would increase the x and y value. Would it? If it would increas x AND y at the same time, it would only test a diagonal line, right?

Or am I completely mistaken here?

Mike

Link to comment
Share on other sites

If I am not wrong then what I think it should do is that first it will perform a pixel search in the given area ( the full resolution ) and if it founds a result, displays it and as by default it check from left to right and top to bottom, the result would be the first instant of the search, so then we put those coordinates as new $X and $Y so as to check starting from them, and the same goes on until $X or $Y grows more then screen resolution and for a safer choice put this thing is last line.

UNTIL $X >= 1280 OR $Y >= 1024 OR @error

So this will quit when it stops finding any more result.

And no, it will surely not check just diagonal !:mellow: Why you think so ? It checks from LTR and TTB so it will cover a whole new rectangle every time after a result if found.

Link to comment
Share on other sites

And no, it will surely not check just diagonal !:mellow: Why you think so ? It checks from LTR and TTB so it will cover a whole new rectangle every time after a result if found.

Apologies, I was mistaken here. But there's still a problem, I suppose.

Lets say we got a 100x100 rectangle, and the first match would be at x,y = 98,0

then the next searched rectangle would be 98,0 to 98,100

How about a possible match at e.g. 37,50?

Maybe I still don't get it right, blame it on the time, I should get myself some sleep now...

Regards,

Mike

Link to comment
Share on other sites

Yeah, actually you are right I didn't thought about that,

but its no big deal, we can create a new sub region by breaking the first one into two and so and then search in each one until there is @error as that would be when there is no more result.

Just wait till I come up with that...

Link to comment
Share on other sites

Sorry, I had to quit abruptly, there was a power cut...:mellow:

Anyways, I think this should work, if not, then cool we'll figure the error :(

Dim $X = 0, $Y = 0, $count = 0, $res1 = True, $res2 = True ;declare vars
Global $i = 1, $max = 1024 ;here too
Global $Xi[$max], $Yi[$max] ;here also

$coord = PixelSearch($X, $Y, 1280, 1024, 0xFF00FF, 50) ;search
If Not @error Then
    MsgBox(0, "Results", "X = " & $coord[0] & " Y = " & $coord[1])
    $X = $coord[0] ;set cords for partition
    $Y = $coord[1] ;second cord
EndIf

_recursrc($X, $Y) ;call recur func

Func _recursrc(ByRef $X, ByRef $Y) ;def
    If $res1 Then ;true initially
        $coord = PixelSearch(0, 0, $X, $Y, 0xFF00FF, 50) ;serach in first part
        If Not @error Then
            MsgBox(0, "Results #1", "X = " & $coord[0] & " Y = " & $coord[1])
            $X = $coord[0] ;update cord
            $Y = $coord[1] ;update cord
            MsgBox(Default, "updated", "after update coords are " & $X & ", " & $Y)
            $Xi[$i] = $X ;store those values in $Xi[1]
            $Yi[$i] = $Y ;store those values in $Yi[1]

            $count += 1 ;increase count
            $i += 1 ;increase $i
            _recursrc($X, $Y) ;call func again with new args
        Else
            $res1 = False ;if error toggle the flag so no more calls
        EndIf
    EndIf

EndFunc ;==>_recursrc

Func _recursrc2(ByRef $Xi, ByRef $Yi) ;func to check in last part
    If $res2 Then ;first true
        $coord = PixelSearch($Xi, $Yi, 1280, 1024, 0xFF00FF, 50) ;search in second part
        If Not @error Then
            MsgBox(0, "Results #2", "X = " & $coord[0] & " Y = " & $coord[1])
            ;no need to update coords as we've stored them in the previous function in the array
        Else
            $res2 = False
        EndIf
    EndIf
EndFunc ;==>_recursrc2

For $i = 1 To $count
    _recursrc2($Xi[$i], $Yi[$i]) ;call func for all args
Next
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...