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.
Image Recognition: Multiple Matches
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 3
- Joined: Mon Feb 09, 2009 1:56 pm
I am trying this
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?
Code: Select all
Repeat>k
Let>k=k+1
MouseMove>XPos_%k%,YPos_%k%
Wait>2.5
LClick
Wait>0.5
Until>k=NumFound
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
What is the value of NumFound? Are you using my corrected code in my most recent response (start the counter at zero)?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
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?