How To compare two screenshots

Asked by thomas

import shutil
import os
wait(5)
dir = os.path.dirname(getBundlePath()) # the folder, where your script is stored
img = capture(SCREEN) # snapshots the screen
shutil.move(img, os.path.join(dir, "shot.png")) # to make it persistent
wait(10)
dir = os.path.dirname(getBundlePath()) # the folder, where your script is stored
img2 = capture(SCREEN) # snapshots the screen
shutil.move(img2, os.path.join(dir, "shot2.png")) # to make it persistent
if img == img2:
    popup("hello")
else:
    popup("hi")

why this is always giving pop up hi not hello... though i haven't changed the screen.

Question information

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

--- why this is always giving pop up hi not hello... t
because img and imgs are 2 different file names, as you would have easily realized with a simple print:

print img, "-- versus --", img2

Revision history for this message
thomas (ramitdas2009) said :
#2

how can i compare this two images to verify whether they are same or not -print img, "-- versus --", img2- this is just printing image name and everything...
help.

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

Now it is finally time, to have a look at the docs.

http://sikuli.org/docx/finder.html#finder
this can be used, to compare 2 images.

or in your script you can just try:
find(img)

which would look for the screen image from 10 seconds before on the current screen.

Revision history for this message
thomas (ramitdas2009) said :
#4

import shutil
import os
wait(5)
click("EMicrosoftEx.png")
type("c", KeyModifier.CTRL)
x = Env.getClipboard()
dir = os.path.dirname(getBundlePath()) # the folder, where your script is stored
img = capture(SCREEN) # snapshots the screen
shutil.move(img, os.path.join(dir, "shot.png")) # to make it persistent
wait(10)
click("1342696730078.png")
dragDrop("1342699917812.png", "1342699925750.png")
click("Yes.png")
f = Finder("shot.png")
f.find(x)
if exists("x"):
    popup("klanti amar khoma koro prabhu")
print x;
#f.next();
if f.next():
    popup("klanti amar khoma koro prabhu")
else:
    popup("Iam quiet near")

its working my friend :) iam happy to see it... was working on this for last 4 hours............

Revision history for this message
thomas (ramitdas2009) said :
#5

Thanks RaiMan, that solved my question.