[request] FindBest(); return if image is not found on Disk or on Screen

Asked by Chetan

enhancement tracked on GitHub: https://github.com/RaiMan/SikuliX1/issues/425

we use findBest() to pass mulitple images. now there may be instance where image may not be present on disk( like missed to checked in)
or there may be a case findbest did not find it on screen
is there a way to know these with findbest?
one of the way is we check in each of the image path before calling findBest.
is there any better approach?

sample code
def searchImage(name=[],SearchRegion=SCREEN):
    logInfo("Method: **searchImage***")
    logInfo("Search Path: "+str(getImagePath()))
    logInfo("Image Names: " + str(name))
        logInfo("No Object Found")

        logInfo("Object Found at Index:" + str(ctrl.getIndex()))
        return ctrl

    logInfo("No Image Match. Check if image is present in repo and on screen")
    return None

Question information

English Edit question
SikuliX Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :

ok, understood.

... but:
image-not-on-disk is a pre-find condition. this check is currently only available with the single find ops (find, wait, ...) as handleImageMissing feature.
I will add this for the multi-find features, but only later in version 2.0.6

image-not-found-on-screen is a post-find condition. for the single find ops we have the FindFailed and handleFindFailed features.
with the multi-find features this has to be checked with the returned matches.
For findBest: if nothing is found, then you have a FindFailed-for-all-givenImages, which has to be handled (you have it in your script)

So IMHO only the pre-find condition is problematic for you in the moment.

a workaround is possible with the preparation of the name[] list you give to findBest().
Instead of just giving the filename to findBest() use
someImage = Image.create(filename)
for every name and test
for True/False

False means, that the image is not on disk or not useable.

Revision history for this message
Chetan (cshamdas) said :

Thanks Raiman for your inputs. we would use the workaround for now.
please add this to 2.0.6 build so we can use it in future
also we are waiting for the 2.0.5 on 1 march. hopefully it is on track as it has inportant fixes for us

Revision history for this message
Chetan (cshamdas) said :

Thanks RaiMan, that solved my question.