if exists(img,0) takes over 10 seconds to execute

Asked by Linda

Hi, I have a script for verifying that a movie is streaming. If the movie have stopped the script will fail.
The problem is that "if exists(img,0)" takes over 10 seconds for me to execute. Why?
The region is the entire screen, since it is a movie playing in full screen. But shouldn't the comparison fail immediately if it can't see similarities? I have tried fiddeling with WaitScanRate and ObserveScanRate without success.

Example:
---------------------------------------------------------------------------------------
app = getRegionOfApp()
duration = 30
time = datetime.datetime.now().time()
endTime = addSecsToTime(time, duration)

img = capture(app)
wait(5)
while datetime.datetime.now().time() < endTime:
    print "time before if: ", datetime.datetime.now().time()

    if exists(img,0):
        assert False
        print "video seems to have stopped"

    print "time after if: ", datetime.datetime.now().time()

    img = capture(app)
    wait(5)
print "video played fine in %s seconds" % (duration)

-----------------------------------------------------------------------------------------
[output]
time before if: 16:02:51.005000
time after if: 16:03:01.772000

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

what Sikuli version?
what system?

Revision history for this message
Linda (linda-nordstrom) said :
#2

Sorry:
SikuliX 1.0.1
Windows 7, 64 bit
8 GB Ram
4 core processor, 2.5ghz

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

I just checked on my Win7 64-Bit / 2.4 GHz / 4GB with a region of 1400 x 900
with 1.0.1 (12Nov2013)

img = capture(reg)
start = time.time()
reg.exists(img, 0)
print time.time() - start

which reveals elapsed times of about 1 second (which is expected), if the image is still there and about 2+ seconds, if the image is not there (which I have to check why)

The behaviour in 1.1.0 is comparable.

So the 10 secs can only be due to a very large monitor.
In this case, you should restrict the region to the middle part of the screen (about 1000 x 800) and try again.

Might be, that even the sequential checking of 2 - 3 spots of 300 x 300 is faster.

Revision history for this message
Linda (linda-nordstrom) said :
#4

Thanks, the screen is not that large.
If I manually take a screenshot and attach the .png to the script, the file is around 1900x1030 with a size of 1200kb.
When I use this attached image in the script it goes a bit faster, around 6-7 seconds when image is not found.
When image is found it only takes around 1 second.

But I followed your advice and shrank the region to 600x600, and it only takes 1.5 - 2 seconds now. So that works for me.
Thanks alot.

Revision history for this message
Linda (linda-nordstrom) said :
#5

Thanks RaiMan, that solved my question.