HowTo: Find one image out of a list of given images

Asked by Alex

Hi all!
I understand that the question is simple. I have a database of images. I need to look for several pictures at once. When one of the images on the screen will be found, I need to know which of the images was found. Thank you!

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

  • by Alex
Revision history for this message
Alex (d051a) said :
#1

My Sikuli on Python :)

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

use SikuliX 1.1.1 and use:

imgs = (img, img1, img2, ...) # see comment
found = os.path.split(findBest(imgs).getImageFilename())[1]
popup("%s is #%d" % (found, imgs.index(found)))

comment: (img, img1, img2, ...) is a list (tuple) of image filenames.
This might be programmatically constructed as a list [...] of image file names

the feature Region.findBest() is not yet documented. the listed images are searched in parallel at the same time and the match with the highest score is returned. To identify the index of the found image in the list you have to find the match's image filename in the list of images.

Revision history for this message
Alex (d051a) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
Alex (d051a) said :
#4

in the cycle for me, it works this way:

while True:
    try:
        found = os.path.split(findBest(imgs).getImageFilename())[1]
        popup("%s is #%d" % (found, imgs.index(found)))
        break
    except:
        continue

Revision history for this message
Alex (d051a) said :
#5

tell me how to change the code in the case of the dictionary:

imgs = {'1':"1481019400547.png",'2': "1481019416947.png"}

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

if you want to do some more complex things, you have to learn some Python scripting !

dimgs = {'1':"1481019400547.png",'2': "1481019416947.png"}
imgs = dimgs.values()

... but your construct does not have any advantage over the simple list:
imgs = ["1481019400547.png","1481019416947.png"]

it is even more difficult to find out, which one matched - just try it ;-)
imgs.index(found)
will not help any longer.

Can you help with this problem?

Provide an answer of your own, or ask Alex for more information if necessary.

To post a message you must log in.