how to compare with two uncertain area

Asked by wong

The requirement is :

first ,I need to capture the screen in flash , and then compare with another picture in a website . all the picture need to be parameterized.

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
Calle Rundgren (c-rundgren) said :
#1

Are you looking for something like this:

image1 = "IMAGE1.png"

App.focus(r"firefox") #browser example
wait(3) #some time for firefox to start
if exists(image1): #check if the image is visible on the website
    print("Image found on website!")

I know this is not a optimized solution, but just to get a clear view of what you are looking for.

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

-- Calle's solution shows the principle.

--- more questions

you say: first ,I need to capture the screen in flash
-- is this done manually or do you want this to be done in the script using capture()?

you say: and then compare with another picture in a website
-- do you expect the 2 pictures to be either identical or not?
-- or might they be partially identical and partially not?

you say: compare with two uncertain area
-- I guess: you know the dimensions of your pictures or it might be possible to get the dimensions from the browser window?

-- should capture and compare take place in the same script?

-- how will your workflow be triggered (manually, defined testcases, ...)

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

One more question:

Will you set this up with Sikuli script (Python) or in Java (or any other Java based (scripting) language like JRuby, Groovy, Scala, ...)?

Revision history for this message
wong (won1112) said :
#4

to Calle Rundgren : I knew this way and sorry this just the half of my question , I need to save this picture and check if it's the same as another windows object just like flash .

to RaiMan :
1. I'm the beginner of using sikuli , for example : picuture A&B , if capture(A) equal capture(B) is ture ,return (there're the same ). Can it make just like this ?
2. there're the almost the same , if not I can make,of cause the dimension I can handle.
3. the workflow should be : do something in flash and then capture A , goto website and capture A' , check . and then repeat.

Revision history for this message
wong (won1112) said :
#5

to Calle Rundgren : I knew this way and sorry this just the half of my question , I need to save this picture and check if it's the same as another windows object just like flash .

to RaiMan :
1. I'm the beginner of using sikuli , for example : picuture A&B , if capture(A) equal capture(B) is ture ,return (there're the same ). Can it make just like this ?
2. there're the almost the same , if not I can make,of cause the dimension I can handle.
3. the workflow should be : do something in flash and then capture A , goto website and capture A' , check . and then repeat.

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

ok, here you are.

In parts it is pseudo code, that has to be adapted to your needs (#!).

switchApp("the-window-containing-the-flash") #!
flashReg = the-screen-area-containing-the-image #!
refImg = capture(flashReg) # this is a temp file name now
ab = App("the-browser-window") #!
ab.focus()
checkWin = ab.window() # the search area
if checkWin.exists(refImg):
   print "the same"
else:
   print "different"

--- if you want to save the screenshots:

# once at the beginning of your script
import shutil
import os.path
imageDir = "path-to-some-existing-directory" #!

# later in your script:
imgFile = capture(some-region) #!
shutil.move(imgFile, os.path.join(imageDir, "you-name-it.png")) #!

Revision history for this message
wong (won1112) said :
#7

Thanks RaiMan, that solved my question.

Revision history for this message
wong (won1112) said :
#8

Thx !!