Jump to content

Pixels, shades, and variations. Oh my!


Recommended Posts

Hey guys. Well, I am working on a project that has me heavily relying on pixels and whatnot, and I find that there is a bit of variance in the thing I'm trying to match. I'm creating a program that can find the location of a picture on the screen, but I need a bit of variance for each pixel. I had absolutely no idea how the 'shade' feature of pixelsearch actually works, so I made one of my own. Unfortunately mine is about 4 times slower. Performance is the highest priority, so I figured I'd ask you guys.

Here is what I came up with:

; Returns 1 if pixel is within the set shade variance, 0 if it is not.
; RGB = the color you are looking for.
; pixel = the actual color of the pixel
; shade the ammount of variance allowed. I think its 0-255.
Func TestTrans($RBG, $pixel, $shade = 0)
    $difference = 0
    $mask = BitAND($RBG, 0xff0000)
    $mask = BitShift($mask, 16)
    $pix = BitAND($pixel, 0xff0000)
    $pix = BitShift($pix, 16)
    $difference = abs($mask-$pix)
    If $difference > $shade Then
        Return 0
    EndIf
    
    $mask = BitAND($RBG, 0x00ff00)
    $mask = BitShift($mask, 8)
    $pix = BitAND($pixel, 0x00ff00)
    $pix = BitShift($pix, 8)
    $difference = abs($mask-$pix)
    If $difference > $shade Then
        Return 0
    EndIf
    
    
    $mask = BitAND($RBG, 0x0000ff)
    $pix = BitAND($pixel, 0x0000ff)
    $difference = abs($mask-$pix)
    If $difference > $shade Then
        Return 0
    EndIf
    
    Return 1
EndFunc   ;==>TestTrans

This is the only way I could think of doing it. It is most likely the hardest way possible to do it. :)

I *could* loop the pixelsearch function a few thousand times, but I figured that would be even less efficient.

Thanks for your help!

Brick

Link to comment
Share on other sites

Not sure why you would need all that

PixelSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )

A number between 0 and 255 to indicate the allowed number of shades of variation of the red, green, and blue components of the colour. Default is 0 (exact match).

Maybe.. take a look at this

http://www.autoitscript.com/forum/index.ph...st&p=154392

Note the "Skip" allows you to pass-up small areas of pixels so you can search faster

8)

BTW ... like the theme lions, tigers and bears, Oh my!!!

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

What I am doing is creating a function to find a picture (A 2d array of colors) on the screen. The Pixelsearch function only finds 1 pixel. I could loop the pixel search for every pixel, but that seemed inefficient. So what I did is have it look for the first pixel in the array, and return all instances. (See _pixelsearchex)

Then for each of those instances I'd check and see if the surrounding pixels match the pixels in my array. If not, it goes on.

It works great. It can find pictures and icons and such, but I then needed it to have a variation. Some colors vary slightly. First I thought I could loop the pixelsearch function and have it search a 1x1 area for the color with a shade variance. If it failed, that means the pixel did not match my array with a variance. But that seemed a waste of resources. I could just get the pixel color and check to see if it is "close enough" to the color in the array without all the rest of the pixelsearch stuff. That is why I created the function above. Unfortunately the pixelsearch function must be doing something entirely different, since it is MUCH faster.

Any hints on how to speed mine up, or should I just rewrite it to loop pixelsearch 50,000 times?

Thanks for your time!

Brick

Edited by Brickoneer
Link to comment
Share on other sites

What I am doing is creating a function to find a picture (A 2d array of colors) on the screen. The Pixelsearch function only finds 1 pixel. I could loop the pixel search for every pixel, but that seemed inefficient. So what I did is have it look for the first pixel in the array, and return all instances. (See _pixelsearchex)

Then for each of those instances I'd check and see if the surrounding pixels match the pixels in my array. If not, it goes on.

It works great. It can find pictures and icons and such, but I then needed it to have a variation. Some colors vary slightly. First I thought I could loop the pixelsearch function and have it search a 1x1 area for the color with a shade variance. If it failed, that means the pixel did not match my array with a variance. But that seemed a waste of resources. I could just get the pixel color and check to see if it is "close enough" to the color in the array without all the rest of the pixelsearch stuff. That is why I created the function above. Unfortunately the pixelsearch function must be doing something entirely different, since it is MUCH faster.

Any hints on how to speed mine up, or should I just rewrite it to loop pixelsearch 50,000 times?

Thanks for your time!

Brick

PixelSearch() is fast because it was optimized in C++, the language the AutoIt interpreter is written in. If you want your function to be anywhere near that fast, I think you'll need to write it in C++, not in an interpreted scripting language like AutoIt.

AutoIt and other interpreted scripting languages like Perl have a lot going for them, but the speed of a real compiled language like C++ is not part of it.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...