Image recognition with OR & THEN logic command
Moderators: Dorian (MJT support), JRL
Image recognition with OR & THEN logic command
Just started using it today, and while I'm in no great hurry to lern it, I do stumble on some basics.
the job is:
1. MS should scan the section of the screen for an image
2. It should look for several images. There is no order in which they show up, and it only shows one error at a time
3. Once it recognize the image, it should press on it and then look for another image to press on it
4. loop, back to step 1
Logically it looks something like "Look for 1,2,3 or 4, press on it, then once you see it look for 5 (different section of screen), press on it, start over".
RIght now I used image recognition wizard which is very straightforward (good job on that!), but I'm wondering how to make it use OR command (find picture A, 2 or 3). Second problem is how to "prolong it" or make use of then, after it click on picture 1,2, 3 or 4 it need to look for and click on picture 5 before going back on step 1 again.
I know it might sound I want you do the work for me, but I don't mind if you point me exactly where to find an answer. I looked into some guides but I didn't mange to find an answer and resolve my problem.
the job is:
1. MS should scan the section of the screen for an image
2. It should look for several images. There is no order in which they show up, and it only shows one error at a time
3. Once it recognize the image, it should press on it and then look for another image to press on it
4. loop, back to step 1
Logically it looks something like "Look for 1,2,3 or 4, press on it, then once you see it look for 5 (different section of screen), press on it, start over".
RIght now I used image recognition wizard which is very straightforward (good job on that!), but I'm wondering how to make it use OR command (find picture A, 2 or 3). Second problem is how to "prolong it" or make use of then, after it click on picture 1,2, 3 or 4 it need to look for and click on picture 5 before going back on step 1 again.
I know it might sound I want you do the work for me, but I don't mind if you point me exactly where to find an answer. I looked into some guides but I didn't mange to find an answer and resolve my problem.
Re: Image recognition with OR & THEN logic command
Hi teyoh,
I *think* I've understood your requirement - this code will look for one of the first 4 images and once it finds any one of them it will skip to look for the 5th image. The use of Goto and Label are key and probably what you're needing to do what you want.
In this example I used the wizard and this forum page to construct the code hence the window naming.
Hope it helps,
Paul.
I *think* I've understood your requirement - this code will look for one of the first 4 images and once it finds any one of them it will skip to look for the 5th image. The use of Goto and Label are key and probably what you're needing to do what you want.
In this example I used the wizard and this forum page to construct the code hence the window naming.
Hope it helps,
Paul.
Code: Select all
Label>Start
//Look For Image 1
//Find and Left Click Center of
FindImagePos>%BMP_DIR%\image_2.bmp,WINDOW:Image recognition with OR & THEN logic command :: Macro Scheduler and Windows Automation :: Mac - Windows Internet Explorer pro,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick
Goto>LookForImage5
Else
//Look For Image 2
//Find and Left Click Center of
FindImagePos>%BMP_DIR%\image_3.bmp,WINDOW:Image recognition with OR & THEN logic command :: Macro Scheduler and Windows Automation :: Mac - Windows Internet Explorer pro,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick
Goto>LookForImage5
Else
//Look For Image 3
//Find and Left Click Center of
FindImagePos>%BMP_DIR%\image_4.bmp,WINDOW:Image recognition with OR & THEN logic command :: Macro Scheduler and Windows Automation :: Mac - Windows Internet Explorer pro,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick
Goto>LookForImage5
Else
//Look For Image 4
//Find and Left Click Center of
FindImagePos>%BMP_DIR%\image_5.bmp,WINDOW:Image recognition with OR & THEN logic command :: Macro Scheduler and Windows Automation :: Mac - Windows Internet Explorer pro,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick
Goto>LookForImage5
Else
MDL>Couldn't find any of the first 4 images. Aborting.
Exit>1
EndIf
EndIf
EndIf
Endif
Label>LookForImage5
//Find and Left Click Center of
FindImagePos>%BMP_DIR%\image_6.bmp,WINDOW:Image recognition with OR & THEN logic command :: Macro Scheduler and Windows Automation :: Mac - Windows Internet Explorer pro,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick
Else
MDL>Unable to find image 5
EndIf
Goto>Start
Re: Image recognition with OR & THEN logic command
It seams to work on my first test I made (just did a small one where it detects 2 possibilities and react with 3rd). It looks very simple and logical, yet something that would take me long time to figure out. Thank you very much for your help.
Else and goto commands are pretty simple, dunno why I haven't figured to use them (maybe my not so good understanding of english could be blamed).
I don't understand the part when you put a line
If Exit was 0 it would mean it would stop the script (at least what I learned from help), and 1 not to but to continue? If so why is there even need to tell it not to exit?
Else and goto commands are pretty simple, dunno why I haven't figured to use them (maybe my not so good understanding of english could be blamed).
I don't understand the part when you put a line
Code: Select all
Exit>1
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Image recognition with OR & THEN logic command
See:
http://www.mjtnet.com/manual/exit.htm
The number is unimportant here. It's only use is when used in a compiled macro and you want to set the exit code to return to the calling process. But whatever the value it will halt the script.
http://www.mjtnet.com/manual/exit.htm
The number is unimportant here. It's only use is when used in a compiled macro and you want to set the exit code to return to the calling process. But whatever the value it will halt the script.
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?
Re: Image recognition with OR & THEN logic command
So Exit will made the process get out of all those "if"s it's written in?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Image recognition with OR & THEN logic command
Yes, it literally terminates the script. Doesn't matter where it is. It STOPS the script DEAD.
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?
Re: Image recognition with OR & THEN logic command
Ah, sorry, it was my fault, I already removed Exit command when I tested it and though somehow script still continues with in it.
Re: Image recognition with OR & THEN logic command
If I need a pause after it finds pic 1-4, Is there any difference where I put a wait command?
For example this should make a pause before it start searching for picture 5
or this
Which should make a pause before it starts to click (after it found picture 5). Will one be more efficient then the other?
Second question is If a FINDIMAGEPOS line could have both %TEMP_DIR%\SCREENRECT.BMP and WINDOW: comands (combine both to click in only one window and only in specific area)?
For example this should make a pause before it start searching for picture 5
Code: Select all
Label>LookForImage5
Wait>0.2
//Find and Left Click Center of
Code: Select all
If>NumFound>0
Wait>0.2
MouseMove>XArr_0,YArr_0
LClick
Endif
Second question is If a FINDIMAGEPOS line could have both %TEMP_DIR%\SCREENRECT.BMP and WINDOW: comands (combine both to click in only one window and only in specific area)?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Image recognition with OR & THEN logic command
It depends. On what you want to do. On what happens when. On the application being automated. Use trial and error.
More often than not this is needed:
Sometimes the app needs time between the cursor moving and the click.
More often than not this is needed:
Code: Select all
Wait>0.2
MouseMove>XArr_0,YArr_0
Wait>0.2
LClick
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?
Re: Image recognition with OR & THEN logic command
Hey Marcus that is very helpful and explain a lot of stuff I was experiencing!
Re: Image recognition with OR & THEN logic command
Marcus what about my second question?
Also in FINDIMAGEPOS when you got something like 0.7,1 I learned it means 0.7 correlation and 1 as a code for where to click on the picture. In help it says "Tolerance should be given a value between 0 and 1 where 1 is a precise match and 0 is the least precise". So how come when in wizard you pick Exact Match option it switches tolerance to 0 (and also put that number in script too once you finish it)?Second question is If a FINDIMAGEPOS line could have both %TEMP_DIR%\SCREENRECT.BMP and WINDOW: comands (combine both to click in only one window and only in specific area)?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Image recognition with OR & THEN logic command
No. As stated in the help file the options are:
http://www.mjtnet.com/manual/findimagepos.htm
For any finer control you will have to use ScreenCapture and capture the portion of the screen you are interested in. You can use GetWindowPos and GetWindowSize to determine the position of a window, you can also get positions of objects with e.g. FindObject and UIGetValues. So there are plenty of ways you can determine screen portions and capture them to bitmaps if that's what you need to do.
Most of the time I just use SCREEN but I appreciate your needs may be unusual.
Look in the FindImagePos topic in the help file or the online version of the help file here:haystack can be set to one of the following values:
1. A bitmap/png file (e.g. %SCRIPT_DIR%\haystack.bmp) (see MatchAlgorithm type below for supported image types).
2. SCREEN - this causes the entire screen to be scanned
3. WINDOW:title where title is a window title (e.g. WINDOW:Untitled - Notepad)
http://www.mjtnet.com/manual/findimagepos.htm
For any finer control you will have to use ScreenCapture and capture the portion of the screen you are interested in. You can use GetWindowPos and GetWindowSize to determine the position of a window, you can also get positions of objects with e.g. FindObject and UIGetValues. So there are plenty of ways you can determine screen portions and capture them to bitmaps if that's what you need to do.
Most of the time I just use SCREEN but I appreciate your needs may be unusual.
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?