Finder object does not reload image when reinstantiated after the image is modified

Asked by cal on 2019-09-22

I have a code to perform analysis on a local image using Finder object.
The local image (temporary file) is generated from multiple screen capture, overwriting previous one once analysis is done.

I did not have problem in overwriting temporary image, however the analysis function gives always the same value, unchanging from initial image generated.
It seems the file is stored in memory and does not update when new image file is copied and overwritten by new file, even Finder.destroy() runs each time.

Simple code to replicate(tested on openJDK 12.0.2, sikulix: 2019-09-17_07:10 Build 381):

# -*- coding: utf-8 -*-

import shutil
import os
from sikuli import *

def countPatternFromFile(imgFile,pattern):
    addImagePath("C:/tmp/")
    dest = shutil.copy(imgFile, "C:/tmp/temp.png")
    checkImgFile = Finder("C:/tmp/temp.png")
    print(imgFile)
    checkImgFile.findAll(pattern)
    matches=[]
    if checkImgFile.hasNext():#if the result is found
        while checkImgFile.hasNext(): # loop as long there is a first and more matches
            matches.append(checkImgFile.next()) # access next match and add to matches
            print checkImgFile.hasNext() # is False, because f is empty now
    checkImgFile.destroy()
    os.remove("C:/tmp/temp.png")
    removeImagePath("C:/tmp/")
    return len(matches)

if __name__ == "__main__":
    addImagePath("C:/src/")
    stars = ["C:/src/3stars.png",
            "C:/src/5stars.png",
            "C:/src/0stars.png"]
    for starimg in stars:
        count=countPatternFromFile(starimg,"C:/src/star.png")
        print(count)

This code worked in past build (around build 200~), but not in recent build.
Was there a change in behaviour?
Can there be some method to explicitly reload a file for Finder object?

Thank you.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
masuo
Solved:
2019-09-23
Last query:
2019-09-23
Last reply:
2019-09-23
Best masuo (masuo-ohara) said : #1

There is a similar question.
https://answers.launchpad.net/sikuli/+question/483025
It may be helpful.

cal (calcal) said : #2

Thank you!
Adding
    Image.reload("C:/tmp/temp.png")
before instantiating Finder object
    checkImgFile = Finder("C:/tmp/temp.png")
fixed the issue and my script runs as intended.

cal (calcal) said : #3

Thanks masuo, that solved my question.