How to manually update the image cache?

Asked by mike wang

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

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
mike wang
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1
Revision history for this message
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

Revision history for this message
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:
Region.UpdateCache()

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

Revision history for this message
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.

Revision history for this message
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.