I would like to compare an image to the screen

Asked by Nikki

I am very new with Sikuli. I would like to compare an image to what is shown on the screen to make sure they are the same.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Hi,

Could you please describe more generally what you want to achieve?

Revision history for this message
Nikki (nikikimnm) said :
#2

I would like to compare a pic with a on screen list and have a popup if the screen matches but I can not get the compare section correct. It always popups the screen matches even if it does not.

if exists("1442408970638.png"):
    popup("Screen matches!")
else:
    popup("Screen does not match.")

Is there another method I could use instead of exists to compare the screen to the picture?

Revision history for this message
masuo (masuo-ohara) said :
#3

You need to specify whether to determine a match with how the degree of similarity .

http://sikulix-2014.readthedocs.org/en/latest/pattern.html

excerpts from pattern.html:
Sikuli searches the region using a default minimum similarity of 0.7. This default value can be changed in Settings.MinSimilarity.
 The IDE supports adjusting the minimum similarity of captured images using the Preview Pane (internally in the script, the images are turned into a pattern object automatically).

example1(minimum similarity of 0.95):
if exists(Pattern("1442408970638.png").similar(0.95)):
    popup("Screen matches!")

example2(minimum similarity of 0.99):
if exists(Pattern("1442408970638.png").exact()):
    popup("Screen matches!")

Revision history for this message
Nikki (nikikimnm) said :
#4

What you suggested did not work so i tried this:

focusWindow = App.focusedWindow()
regionImage = capture(focusWindow)
img2=(regionImage)
file=open(r"C:\Sikuli\Test.txt",'a')
file.write(img2 + "\n")
img = (Pattern("1442500840276.png").similar(0.66))
if img == img2:
    file.write('Structures rolled correctly.\n')
    file.close()
else:
    file.write("Structure screen doesn't match.\n")
    file.close()

Even thought the images are exactly the same I still receive: ("Structure screen doesn't match.\n")
I want to capture what is on screen(img2) and compare it to a saved image(img).

Revision history for this message
masuo (masuo-ohara) said :
#5

Finder feature is helpful for this question.

http://sikulix-2014.readthedocs.org/en/latest/finder.html

Revision history for this message
masuo (masuo-ohara) said :
#6

capture is here:

http://sikulix-
2014.readthedocs.org/en/latest/screen.html#capturing

Can you help with this problem?

Provide an answer of your own, or ask Nikki for more information if necessary.

To post a message you must log in.