Comparing 2 images for similarity??

Asked by Sikuli User

Hi.

I am wondering if we can compare two images in Sikuli. Do we have this functionality in Sikuli?

Can we do something like this?

if image1 = image 2 .. do something...else do something else..

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Sikuli User
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

not with current version 0.9.9

In upcoming 0.10 it will be possible to try to find an image in another image file. So this feature may make possible what you want.

Revision history for this message
Sikuli User (hidden-hidden) said :
#2

Thanks. That will be great!

Revision history for this message
Sikuli User (hidden-hidden) said :
#3

Thanks. That will be great!

Revision history for this message
surfdork (surfdork) said :
#4

Can I compare images with 0.10.2?

If image is not black then pass, continue with test or if image is black then fail and print to file fail

can this be included in a while not exists?

I'm confused regarding the implementation

while not exists (green window, 0):
   wait(1)
# waiting for a green window, I know the syntax ia incorrect

I want to catch oif there is a window and if it's not green

Thank You

Revision history for this message
RaiMan (raimund-hocke) said :
#5

This is a typical situation in a Sikuli workflow:
--- wait for one or more visual objects to come up
--- find out what the situation is, when one comes up
--- decide if you want to continue with your workflow or if you still have to wait

(this is the situation where observe() could come in, but it is still buggy in windows and generally not very convenient)

the best way is to use a <while True:> loop, that checks the situation inside the loop and uses break and continue, to leave the loop or go on with it. Since the decisions you have to make are mostly based on the existence or absence of visual objects, the most convenient function is exists(img, 0) (look: https://answers.launchpad.net/sikuli/+question/123366)

example:

you have clicked a button and now you expect a window to come up, that you want to recognize with img1, but it should contain an img2, If not, you will click another button and go on waiting for the correct window (could be a workflow, where you use an app's search function and check the content of the result window)

while True:
   if not exists(img1, 0):
      wait(1)
      continue # go on waiting for image 1
   if exists(img2, 0):
      break # we have what we are looking for, so leave the loop
   click(button) # the loop will continue

This is for the more complex cases.
If you only want to wait for one visual object, that surely will come up, and then just go on with your workflow a

while not exists(img, 0):
   wait(1) # will wait forever, if img fails to come up

is sufficient, but if you know a maximum waiting time, in this cases a

wait(img, 300)
may be better, since after 300 seconds you will get a FindFailed (which is ok in this case, since something happens, that you did not expect - makes no sense, to go on)