Looking for an Image within an Image

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

Looking for an Image within an Image

Post by theonex » Thu Jan 08, 2015 11:59 am

hi

is it possible to look for a part of the screen and then within that part click on a button.

example

//Look for Image_A using the entire screen
FindImagePos>c:\Image_A.bmp,SCREEN,0.7,1,X,Y,NumFound,CCOEFF
If>NumFound>0
MouseMove>X_0,Y_0

//If Image_A is found look for Image_B within Image_A and Click on Image_B
FindImagePos>c:\Image_B.bmp,c:\Image_A.bmp,0.7,1,X,Y,NumFound,CCOEFF
If>NumFound>0
MouseMove>X_0,Y_0
LClick
EndIf

Else
wait>0.5

EndIf

any help would be appreciated.

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

Re: Looking for an Image within an Image

Post by Marcus Tettmar » Thu Jan 08, 2015 1:07 pm

Yes. You can look within an existing image file, or use ScreenCapture to capture a portion of the screen and then look within that. Just remember to calculate your offsets to get the mouse coordinates right. I.e. if you are looking in an image which represents part of the screen starting at position 100,150 then you'll need to add 100 and 150 to your X and Y positions of the match in order to get back to screen positions for your mouse click.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

Re: Looking for an Image within an Image

Post by theonex » Thu Jan 08, 2015 1:17 pm

thanks for the reply marcus

the one issue i have is that the, the position of the images change every time IE is refreshed.
so i can't set any coordinates. is there a work around this.

thanks

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

Re: Looking for an Image within an Image

Post by Marcus Tettmar » Thu Jan 08, 2015 1:21 pm

The whole point of image recognition is that you don't need to know where something is - it's purpose is to TELL you by finding it.

So perhaps I don't really understand what you are trying to accomplish. If you want to capture a portion of the screen and then look WITHIN that portion you need to be able to define that portion first. Maybe you'd do that with image recognition first?

What is the reason for only wanting to look in a specific portion? Scanning the entire screen is very fast and you can also specify just a window - e.g. the internet explorer window.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

Re: Looking for an Image within an Image

Post by theonex » Thu Jan 08, 2015 1:46 pm

here is what i am trying to do.

am trying to answer question 2 and question 3.
q1.png
the questions are different but the multiple choice answers are the same

bellow is an image of the correct answers
a1.png
what ends up happening is that the mouse click for question 2's answer is being clicked on the answer list for question 3.

question 2 & answers = Image_A
answer for question 2 = Image_B

look for Image_A in the SCREEN
if Image_A is found

look for Image_B in Image_A
and click on Image_B


question 3 & answers = Image_C
answer for question 3 = Image_D

look for Image_C in the SCREEN
if Image_C is found

look for Image_D in Image_C
and click on Image_D


i hope this makes sense

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

Re: Looking for an Image within an Image

Post by Marcus Tettmar » Mon Jan 12, 2015 4:43 pm

Use EXACT matching. You will then get an array of ALL matches on the screen and can then loop through the array and click each one.

The default CCOEFF method only returns one match - the most statistically likely. So it will be only one of them.
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