Color picking

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

simplejamie
Newbie
Posts: 16
Joined: Sat Nov 18, 2006 7:19 am

Color picking

Post by simplejamie » Sat Nov 18, 2006 7:36 am

is there any easier/faster way to do something like this..

findcolor>(color) or findcolor>(color),startX,startY,endX,endY
mousemove>x,y
Lclick

i understand there's a lib/plugIN in downloads, buts its slow and complicated. and to me, this system is build around being easy to understand and follow. i myself dont know how to make dlls..

could anyone help please?

thanks

jamie

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

Post by Marcus Tettmar » Sat Nov 18, 2006 8:25 am

This comes up frequently, maybe I need to add this to FAQs. But the answer is to use GetPixelColor inside two nested loops, one for X coords, the other for the Y coords:

Code: Select all

Let>XStart=10
Let>XStop=30
Let>YStart=10
Let>YStop=30

Let>x=XStart
Repeat>x
Let>y=YStart
  Repeat>y
         GetPixelColor>x,y,color
	 If>color=ColorToFind
             MouseMove>x,y
             LClick
         Endif
     Let>y=y+1
  Until>y>YStop
  Let>x=x+1
Until>x>XStop
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 » Sat Nov 18, 2006 3:40 pm

A tip that I think would be worth to include is that if the object/area of color to click on is larger than a single pixel, then the search can run much faster by incrementing the x and y positions in steps equal to the x and y dimensions of the target.

simplejamie
Newbie
Posts: 16
Joined: Sat Nov 18, 2006 7:19 am

Post by simplejamie » Sun Nov 19, 2006 8:15 pm

sounds easy enough thank you very much, i thought of something like that. but i was corious if they was an easier or better way.. thanks again

simplejamie
Newbie
Posts: 16
Joined: Sat Nov 18, 2006 7:19 am

Post by simplejamie » Tue Nov 21, 2006 7:23 pm

i did a few tests with the current method above.. takes 5-10 seconds, depending on machine to check an area of pixels 100x100..so think is you was doing 500x500, thats 25-50 seconds.. this seems to be a little slow.

ive seen other ''programs'' use commands like:
findcolor(color,x,y) finds color in window sets x,y to cords found
findcolor(color,SRTx,SRTy,ENDx,ENDy,x,y) looks for color in rect of SRTxy and ENDxy, returns x,y as cords found..

these commands work instantly.. is there any way to do this faster with this program? mabie a dll of some sort?

thanks
jamie

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

Post by Marcus Tettmar » Tue Nov 21, 2006 7:31 pm

a FindColor function would still have to have a loop and check each pixel, but, yes, it would be faster as it would all be happening at a lower level, internal to Macro Scheduler. I'll add that to the wish list. But right now in the absence of a built in function, if you want something faster then a custom DLL would be the best solution. Then Macro Scheduler could call the DLL function which could be written in a lower level language and therefore more optimized. We could write you such a DLL. Email support if you are interested.
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 Nov 21, 2006 9:32 pm

simplejamie wrote:i did a few tests with the current method above.. takes 5-10 seconds, depending on machine to check an area of pixels 100x100..so think is you was doing 500x500, thats 25-50 seconds.. this seems to be a little slow.
But see my comment above, how often are you looking for a single pixel?

simplejamie
Newbie
Posts: 16
Joined: Sat Nov 18, 2006 7:19 am

Post by simplejamie » Wed Nov 22, 2006 1:37 am

to me_: yes true.. buy even if im looking for something 20x20, it still takes time..
to mte:ok thanks, i would love a dll.. i looked into using a windows api dll, but no luck

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

Post by Me_again » Wed Nov 22, 2006 2:06 am

Right, faster/instant would be nice, but stepping 20x20 would be 400 times faster which is very useable.

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

Post by Marcus Tettmar » Wed Nov 22, 2006 10:39 am

Ok, download FindColor.dll here:
http://www.mjtnet.com/plugins.htm
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Nov 22, 2006 6:27 pm

Hi Marcus,

Just wanted to say thanks for FindColor.dll and... I have a question I'm sure you could help with.

I used a colorpicker program to grab the color of an Icon I wanted to detect on the desktop, it told me the color's value was #F5C838.

I then used a web app available here to convert from Hex to decimal and it gave a result of 16107576 however this number did not work with the dll.

Then I used the Macro Scheduler GetPixelColor> command to get the color value and it told me that color was 3721461. Plugging this value into the dll worked.

What I'm wondering is, why didn't 16107576 work? Isn't that the proper conversion from Hex #F5C838 ? Could the colorpicker program be giving false values?
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Post by Marcus Tettmar » Wed Nov 22, 2006 6:42 pm

It's just a different format. The hex value is an RGB value where:

F5 = red intensity
C8 = green intensity
38 = blue intensity

Note that 38C8F5 converted to decimal is 3712461 ...

Please don't ask me why Windows returns it in the opposite format to what is commonly used in HTML. I don't know. But it's a case of comparing like with like.

Use Macro Scheduler's color locator (it's on the macro properties form, it can follow the cursor, and in 9.0 it's on the Editor toolbar) to get colors that you will use/find within Macro Scheduler. And we won't be reversing the format, as that will cause backward compatibility issues.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Nov 22, 2006 8:55 pm

mtettmar wrote:It's just a different format. The hex value is an RGB value where:

F5 = red intensity
C8 = green intensity
38 = blue intensity

Note that 38C8F5 converted to decimal is 3712461 ...
Well... 3721461 actually but I see what you mean... an "RGB" value but formatted backwards... "BRG".
mtettmar wrote:Please don't ask me why Windows returns it in the opposite format to what is commonly used in HTML. I don't know. But it's a case of comparing like with like.

Use Macro Scheduler's color locator (it's on the macro properties form, it can follow the cursor, and in 9.0 it's on the Editor toolbar) to get colors that you will use/find within Macro Scheduler.
I forgot that tool did colors too, very helpful. I'll just use that from now on for this sort of thing.
mtettmar wrote:And we won't be reversing the format, as that will cause backward compatibility issues.
I wouldn't dream of asking for that... :wink:

Thanks and take care...
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Post by Me_again » Wed Nov 22, 2006 9:53 pm

I find it more convenient to use (free) ColorPic http://www.iconico.com/colorpic/ for this and HTML purposes, it returns hex codes and decimal color codes that match the Macro Scheduler ones :D

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Nov 22, 2006 10:37 pm

Hi Me_again,

I tried out ColorPic (Direct download from Downloads.com here). Yes, I see the decimal color codes match the Macro Scheduler ones so that's handy. Also, the magnification feature allows one to easily select the exact color you want, right down to the pixel.... nice. Thank you for taking the time to mention this. :D
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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