Image Recognition: Multiple Matches

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
betterman
Newbie
Posts: 2
Joined: Wed Aug 20, 2008 5:35 am

Image Recognition: Multiple Matches

Post by betterman » Wed Aug 20, 2008 5:58 am

So I've been messing around with image recognition for a couple days now, I've gotten it to find objects successfully, and click on them, or click relative to the image, or just tell me if the image isn't there at all.

But what I don't know, is what to do when its located multiple images of what i've wanted it to look for. It seems to get confused on exactly which one it wants identify and it seems to stop working after it's found the first match.

Now say they're four red rectangles that I want it to click on and identify for me. I can get it to find the first one, which is always the one closest to the top left corner, so I figure it must be looking for the image starting first at the 0,0 mark. If this is the case, is there a way that I could make it start looking for the image at other parts of the screen first? For instance, the center instead and maybe branch out from their in a clockwise search pattern or something similar?

Is it posable to make it look at only certain parts of the screen? For instance, say i want it to locate a certain amount of numbers that might be located in one of the corners of the screen that have a specific value. Now i can't ask it to just look for any numbers on the screen because those same values might be represented somewhere else on the screen and mean something completely different. So how would I go about that?

example code would be much appreciated, so I have something to compare my code to when I find that something doesn't work right.

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

Post by Marcus Tettmar » Wed Aug 20, 2008 7:20 am

FindImagePos returns an array of all matches, starting at 0,0. So all you need to do is loop through the array clicking on each one:

Code: Select all

FindImagePos>needle,SCREEN,0,1,XPos,YPos,NumFound
Let>k=0
Repeat>k
  Let>k=k+1
  MouseMove>XPos_%k%,YPos_%k%
  LClick
  Wait>0.5
Until>k=NumFound
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

poopstamper
Newbie
Posts: 3
Joined: Mon Feb 09, 2009 1:56 pm

Post by poopstamper » Mon Feb 16, 2009 9:04 am

I am trying this

Code: Select all

Repeat>k
  Let>k=k+1
  MouseMove>XPos_%k%,YPos_%k%
  Wait>2.5
  LClick
  Wait>0.5
Until>k=NumFound
but it has a problem. it finds for example a K=6 (found matches). then it goes trough the loop until it reaches k=6. the find image position actually start pinpointing from zero so the last position will be 5 (6 matches starting from 0). So I get a error on the mousemove command. How do you fix this?

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

Post by Marcus Tettmar » Mon Feb 16, 2009 9:25 am

Yes, so my mistake. Start your loop at zero:

Code: Select all

Let>k=0
Repeat>k
  MouseMove>XPos_%k%,YPos_%k%
  Wait>2.5
  LClick
  Wait>0.5
  Let>k=k+1
Until>k=NumFound
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

oinquer
Newbie
Posts: 7
Joined: Thu Jan 07, 2010 9:15 pm

Post by oinquer » Sat Jan 09, 2010 9:52 pm

does this script works for anyone?

i used it and its only getting the first time,
in watch window i get YPOS_%K%=232 and after that value is not updated...

Aynone can give me an update?


forget it...clean script and its working...thanks

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

Post by Marcus Tettmar » Mon Jan 11, 2010 10:20 am

oinquer wrote:does this script works for anyone?

i used it and its only getting the first time,
in watch window i get YPOS_%K%=232 and after that value is not updated...

Aynone can give me an update?


forget it...clean script and its working...thanks
What is the value of NumFound? Are you using my corrected code in my most recent response (start the counter at zero)?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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