Help with image recognition wizard

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Sobysky
Newbie
Posts: 5
Joined: Mon Dec 07, 2015 11:51 pm

Help with image recognition wizard

Post by Sobysky » Mon Dec 07, 2015 11:56 pm

Hello i am very new to this. I am trying to make a very simple macro. It just needs to search for an image and click another image once the first image is found.

So far I can get it to find one image click the image and then move onto the next set of images. The problem is it only does this in the order i programmed it in. if i run the macro in between images it won't start until the first image is found.

How can i make it so that it will find any image no matter the order?

Sobysky
Newbie
Posts: 5
Joined: Mon Dec 07, 2015 11:51 pm

Re: Help with image recognition wizard

Post by Sobysky » Tue Dec 08, 2015 12:21 am

Here is what my test macro looks like. It finds the first image and clicks fine and then will find and click the second image. But if i start the program while the second image is up it will not click that image until the first image shows up.

//Wait for
WaitScreenImage>%BMP_DIR%\image_8.bmp,0.7,CCOEFF

//Find and Left Click Center of
FindImagePos>%BMP_DIR%\image_9.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick
Endif

//Wait for
WaitScreenImage>%BMP_DIR%\image_11.bmp,0.7,CCOEFF

//Find and Left Click Center of
FindImagePos>%BMP_DIR%\image_11.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick
Endif

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

Re: Help with image recognition wizard

Post by Marcus Tettmar » Tue Dec 08, 2015 1:52 pm

You could do it like this:

Code: Select all

Label>WaitForAnImage

Let>FoundAnImage=FALSE
FindImagePos>%BMP_DIR%\image_9.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
  Let>FoundAnImage=TRUE
Else
  FindImagePos>%BMP_DIR%\image_11.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
  If>NumFound>0
    MouseMove>XArr_0,YArr_0
    LClick
    Let>FoundAnImage=TRUE
  Endif
Endif

If>FoundAnImage=FALSE
  //Neither image was found, loop back and look again
  Wait>0.2
  Goto>WaitForAnImage 
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Writesindia
Newbie
Posts: 1
Joined: Wed Dec 09, 2015 11:59 am

Re: Help with image recognition wizard

Post by Writesindia » Wed Dec 09, 2015 12:01 pm

Hello,
Its Useful For me

Sobysky
Newbie
Posts: 5
Joined: Mon Dec 07, 2015 11:51 pm

Re: Help with image recognition wizard

Post by Sobysky » Tue Dec 15, 2015 1:06 am

It works! Thanks for your input. My test macro currently looks like this. Only i need it to find an image and click on a different image. How would I do that?

Code: Select all

Label>WaitForAnImage

//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_4.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
  Let>FoundAnImage=TRUE
Endif

//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_5.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
  Let>FoundAnImage=TRUE
Endif



If>FoundAnImage=FALSE
  //Neither image was found, loop back and look again
  Wait>0.2
  Goto>WaitForAnImage
Endif

Label>WaitForAnImage
  // do something here
Goto>WaitForAnImage



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

Re: Help with image recognition wizard

Post by Marcus Tettmar » Tue Dec 15, 2015 10:38 am

Just put another FindImagePos inside the If .. Endif of your first one. So it looks for an image and IF found then looks for the second and clicks on THAT ONE ... e.g. *PSUEDO CODE*

Code: Select all

//Find FIRST image
FindImagePos>Image1,SCREEN,bla,bla
If>NumFound>0
  //If FIRST image found, get position of image TWO and click on THAT
  FindImagePos>Image2,SCREEN,bla,bla
  If>Image2Found>0
    MouseMove>Image2_X_0,Image2_Y_0
    LClick
  Endif
Endif
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