GetPixelColor -> RGB

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Sephta
Newbie
Posts: 3
Joined: Sun Feb 18, 2007 10:30 am

GetPixelColor -> RGB

Post by Sephta » Sun Feb 18, 2007 12:11 pm

My problem ist to check, if a symbol shows up at a specific place in the monitored window. The litte problem is: it has a changing background and it is 20% transparent, so the image recognition fails to check as well as the check for the exact color of certain pixels.

My idea was to check every pixel and calculate a 'range' of color, that matches, but this is difficult, as the getpixelcolor function returns a high range of numbers. To guess my color with the range i'd like to get to this format:

R: X1 +/- x
G: X2 +/- x
B: X3 +/- x

if X1-X3 are integer or hex, i don't mind...

I think the function FindImagePos with the color range does quite a familiar thing, but i can't use this function due to the great chances in the background. Any suggestions?

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Feb 18, 2007 1:40 pm

How about getting the highest and lowest range? You can then do
GetPixelColor>X,Y,COLOR
IF>{(%COLOR%>[Low Range])or(%COLOR% Greater than Low Range
< Less than High Range

Just a though.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Feb 18, 2007 1:45 pm

Sorry it's AND not OR

Let’s say your high range is 15467 and your low range 13678 what you have to do is add 20 or so to the high range and subtract 20 or so from the low range.

The code would look like this:
GetPixelColor>X,Y,COLOR
IF>{(%COLOR%>13658) AND (%COLOR% Greater than Low Range
< Less than High Range

Sephta
Newbie
Posts: 3
Joined: Sun Feb 18, 2007 10:30 am

Post by Sephta » Sun Feb 18, 2007 4:18 pm

Thanks for the hint, thougt about that as well - but:

The range can be very high, so i can tell nothing about a hit for a pixel. This happens every time, the first value (red) changes a bit or the numer of digits for one of the folling blue/green) changes.

And that's exactly my problem to pinpoint the right color range.

Try to get the RGB-values from this color:

color: 1213132

012 - 131 - 032 ?
121 - 031 - 032 ?
012 - 013 - 132 ?

You see, splitting the colors in RGB is quite difficult - for this example, i can't tell if it's mainly blue, green or red. But this can happen in my case.

IF I could split the value from GetPixelColot in it's RGB-Values, i could check every color channel for a small change. But the calculating from the given value is tricky - it's not a exact computable array of variables with the given information (leading zeroes would be fine :) )

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sun Feb 18, 2007 11:22 pm

This not very elegant code converts a macroscheduler color number (px) to RGB. (I'm sure Marcus will now post a single line solution :roll: )

GetPixelColor>%xpos%,%ypos%,px
Let>px2={%px% MOD 16}
Let>px3={(%px%-%px2%)/16}
Let>px4={%px3% MOD 16}
Let>red={%px2%+(%px4%*16)}
Let>px5={(%px3%-%px4%)/16}
Let>px6={%px5% MOD 16}
Let>px7={(%px5%-%px6%)/16}
Let>px8={%px7% MOD 16}
Let>green={%px6%+(%px8%*16)}
Let>px9={(%px7%-%px8%)/16}
Let>px10={%px9% MOD 16}
Let>px11={(%px9%-%px10%)/16}
Let>px12={%px11% MOD 16}
Let>blue={%px10%+(%px12%*16)}

mdl>%red%-%green%-%blue%

Sephta
Newbie
Posts: 3
Joined: Sun Feb 18, 2007 10:30 am

Post by Sephta » Mon Feb 19, 2007 8:31 pm

Thanks for the hint.

So the number I get for the pixel is truely a decimal conversion for the three hex values written in a row? If yes, i will get a algorythm, thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Feb 19, 2007 9:12 pm

Just remember that Macro Scheduler returns the values in BGR sequence (not RGB).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Feb 20, 2007 1:39 am

The code as posted has been tested against several color picking tools such as colorpic and returns the same Red Green Blue values.

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

http://www.mjtnet.com/usergroup/viewtopic.php?t=171&high

Post by Aaron » Mon Apr 30, 2007 3:43 am

Aaron

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Apr 30, 2007 1:11 pm

Huh?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts