Sign in to follow this  
Followers 0
woodyfly

Pixelsearch help

6 posts in this topic

#1 ·  Posted (edited)

I need help on making pixelsearch more accurate. Let's say I'm trying to find pixel 0xFFFFFF but on the screen there's dozens of the same pixel scattered. How would I make it find the right pixel that I need?

I thought of an idea but perhaps there are better ways? How about checking the pixels in relation to the pixel that we found. For example, if we find pixel 0xFFFFFF, then check pixel to the right. If the pixel to the right = 0xCCCCCC then we're done. If the pixel to the right is not 0xCCCCCC, then move on to the next 0xFFFFFF and repeat until there are no more pixels left to search. When we've reached the last 0xFFFFFF, start over from the first one and keep looping.

To make it even more accurate, we could check the pixels all around the initial pixel but would that make it too time consuming for the script? or no?

Would this be the best way to accurately get the right pixel and how would I write this?

Edited by woodyfly

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

I just searched 10+ pages on "pixelsearch", didn't really find anything specific to what I need. I'll try to keep looking until then....

Edited by woodyfly

Share this post


Link to post
Share on other sites

Hope this is what you are after:

This requires a MS Paint application with a screen size of 800x600 or greater (i called my image "MouseMoveTestImage.bmp") the Paint file will need to be opened.

$top_border_height = 24
$left_border_width = 4

$screen_width = 800
$screen_height = 600

$color_search = 0x00FF00    ;color you want to find
$color_search_tolerance = 30    ;how many different shades of the color are tolerated (set to 0 when looking for an exact color)
$color_search_step = 2      ;Pixel interval of the search, 2 means that two pixels of the same color (within the tolerance) are whats required.

WinActivate ("MouseMoveTestImage.bmp", "")
WinSetOnTop ("MouseMoveTestImage.bmp", "", 0)

$win_pos = WinGetPos ("MouseMoveTestImage.bmp", "") ;change the name of the file you are searching
$win_x = $win_pos[0] + $left_border_width
$win_y = $win_pos[1] + $top_border_height

;search borders
$top = $win_y + (.20 * $screen_height)
$bottom = $top + (.80 * $screen_height) - 1
$left = $win_x + (.08 * $screen_width)
$right = $left + $screen_width - (.05 * 2.0 * $screen_width) - 1

find_color()

func find_color()

    while 1

        $pos = PixelSearch ($left, $top, $right, $bottom, $color_search, $color_search_tolerance, $color_search_step)

        if @error then
            SetError(0)

        else
            ;code here what you want to do once it finds the color

        endif

    wend

endfunc

I have sourced some of this code from some friends on a VB.net forum (AutoIt and Visual Basic are a great and powerful combo. Unless your pro with AutoIt then you dont need VB)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks but I kind of have that step already. I'm trying to figure out how to write the code after it finds the initial pixel. I found a way to check for the adjacent pixel but I think it's poorly written and incorrect. Even so, I don't know how to make it check the next available pixel in the row

search()

Func search()

$coord = pixelsearch(339,205,721,481,0xFF0000,0)

IF not @error then

$x=$coord[0]+1

$y=$coord[1]

$color= pixelgetcolor($x,$y);gets the color from the pixel on x+1(right)

If $color = "0x00000" then

mousemove($coord[0],$coord[1])

msgbox(0,"",hex($color, 6))

Else

;Check next pixel

EndIf

EndIf

EndFunc

This checks the first pixel (red) it finds and sees if the next one to it is black. It isn't, but I don't know how to make it find the next pixel available and keep searching. And the code is probably wrong and sucks anyways

Edited by woodyfly

Share this post


Link to post
Share on other sites

I just searched 10+ pages on "pixelsearch", didn't really find anything specific to what I need. I'll try to keep looking until then....

Well you went right past them both, for example is on page 8 and has what you need I think, By Malkey.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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