Image recognition and IF statements

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
llorenc
Newbie
Posts: 4
Joined: Wed Aug 11, 2021 9:01 am

Image recognition and IF statements

Post by llorenc » Wed Aug 11, 2021 9:28 am

Hi everyone,

I am just started to learn the software and I have few doubts.

I am using Macro Scheduler to automate the upload of multiple images to a website, (on which needs to be done one by one following a series of "steps" through about 3 different web pages from the same site, such as upload, write a description, etc ). I already made the automation, about 200 lines but and works well until there are internet problems, the page doesn't load at 100% or the external server fail.
I am using the Image recognition wizard to detect some parts of the screen in some of the steps, so I am sure that the page is loaded before following the next step. It takes about 2 seconds to recognise the image (a button in most cases). I am using 2 screens, and for some reason doesn't work well when I select only one part of the screen.

- If I use only one screen or a smaller screen, will be faster the image recognition process?

The other question I have is about how to work with IF statements.
So, sometimes the web server shows me errors when uploading and appears a red cross on the screen which stops all the upload process until I press on this cross.
So I want to write a IF statement to say " If there is a red cross, click on it, else, continue with the process.
I repeat the process because sometimes happens before or after to put the name of the picture

...START OF THE CODE...

//Find and RED CROSS
FindImagePos>%BMP_DIR%\image_35.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick

else

//Go to NEXT BUTTON AND CLICK
MouseMove>1936,725
Wait>0.1
LClick
Wait>0.4
SendText>PICTURE NAME
Wait>0.4

ENDIF

//Find and RED CROSS
FindImagePos>%BMP_DIR%\image_35.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick

else

....REST OF THE CODE....

ENDIF


Sometimes I still have errors, does its statement is correct?


Also Is there any tricks that could help to optimise the image recognition process?

Thanks!

llorenc
Newbie
Posts: 4
Joined: Wed Aug 11, 2021 9:01 am

Re: Image recognition and IF statements

Post by llorenc » Wed Aug 11, 2021 10:32 am

Also, does the type of image and the size of it affects the speed of image recognition?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Image recognition and IF statements

Post by Dorian (MJT support) » Wed Aug 11, 2021 11:30 am

Certainly speed can vary depending on a few factors. And the larger the area you're scanning, the slower it's likely to be.

And EXACT is faster than CCOEFF.

See this page :
CCOEFF is more intelligent and more tolerant but is slower and will return only one match. EXACT is faster and can return multiple matches but is precise and therefore less portable and will not cope with changes
EXACT can only work with bitmap files. CCOEFF can work with Bitmaps and PNGs.

Personally I tend to use CCOEFF alongside "search inside this window" so it's only searching where necessary. Of course if the location can be predicted you can search within a specific rectangular area.

I just ran a few scenarios and using two 4k monitors, these were my speed test results :

//CCOEFF 0.7 top left (2 screens)
//Seconds elapsed: 2.895

//EXACT top left (2 screens)
//Seconds elapsed: 2.895


//CCOEFF 0.7 bottom right (2 screens)
//Seconds elapsed: 2.615

//CCOEFF 0.7 select window - small
//Seconds elapsed: 0.29

//CCOEFF 0.7 select window - large
//Seconds elapsed: 0.67

//CCOEFF 0.7 select window - maximized 1 screen
//Seconds elapsed: 1.753

//EXACT select window - small
//Seconds elapsed: 0.025

//EXACT select window - maximized 1 screen
//Seconds elapsed: 0.305

//EXACT select window - stretched across 2 screens
//Seconds elapsed: 0.32

As you can see, EXACT with selecting a specific window was the fastest.

Your If/Else/Endif looks fine :

Code: Select all

FindImagePos>%BMP_DIR%\image_10.bmp,WINDOW:redstar small.png ‎- Photos,0,1,XArr,YArr,NumFound,EXACT
If>NumFound>0
  ..do this
  
  else
  
  ..do that
Endif
So :

Code: Select all

Let>this=1
If>this=1
	mdl>yes it's 1
  else
	mdl>no it wasn't 1
Endif
Helpfile link
Yes, we have a Custom Scripting Service. Message me or go here

llorenc
Newbie
Posts: 4
Joined: Wed Aug 11, 2021 9:01 am

Re: Image recognition and IF statements

Post by llorenc » Sun Aug 15, 2021 9:22 pm

Thanks for the reply, I just been doing some tests with the screens and indeed changes the recognition speed.

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