How to manually update the image cache?

Asked by mike wang on 2017-03-02

In my application, I call region.find() repeatedly in a loop, and the image is continuously changing.
But sometimes the find function return a location that just moved.
If I try to increase the scan rate, it is improved, but the problem is still there.

I guess maybe just because the find function is using a old image cache.
To avoid this problem, it is better to force the image cache update.

How to do?

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
mike wang
Last query:
Last reply:
RaiMan (raimund-hocke) said : #2

... but I think your problem might as well be the "first check if still there feature":
in the standard, an image is first searched, where it was found the last time.

You might switch that off:
Settings.CheckLastSeen = False

mike wang (cn.mike) said : #3

I tried, add it before the loop:
Settings.CheckLastSeen = False

But the problem is still there.
In fact, the image cache I mentioned above is refer to the screen(or region) image catch, not the pattern image.

So in my opinion, it is better to add one more function like:

Then if it is needed, I can call it before find().
The problem can be solved.

RaiMan (raimund-hocke) said : #4

if you have the latest 1.1.1 and this does not solve your problem, then this is not the reason.

Screen or Region do not have an image cache, only the lastMatch is remembered, but overwritten with every find.

So the only reason left, is timing:
the search is faster, than you expect/observe visually.

Make the search region as small as possible and update the region together with the movement of your target.
Be aware: a search of a small visual in a small region might still take some 10 milliseconds, so a scan rate above 10 to 20 does not add any effect anymore.

mike wang (cn.mike) said : #5

Thanks, Raiman.

I found the root cause: it just because the Screen or Region is still changing when I call find().
If I wait until the area is a little stable, then call find(), it is OK now.

Thank you very much.