how to import multiple image libraries in sikuli?

Asked by joe fu

Hi,

Sikuli-X provides the way to import another Sikuli script and image library into the main sikuli script. It only works on 1 image library importing.
What if I want to import multiple image libraries into the same sikuli script?

I've tried to do that, it won't work on the 2nd import, even it didn't complain anything. It just couldn't find the image and will time out.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

After the second import you can inspect the image search path
print getImagePath()

The second imported .sikuli should be in the list.

Are you sure, there are no naming conflicts? Sikuli takes the first image found with the matching file name found in image path.

Revision history for this message
joe fu (jfu-yahoo) said :
#2

Hi RaiMan,

I've tried to print out the image search path by getImagePath(), it looks like this, does it look right to you?

array(java.lang.String, [u'C:\\GUITest\\GUITest.sikuli\\objectData/imgs.sikuli:C:\\GUITest\\GUITest.sikuli\\projects\\DesktopDirector\\objectData/imgs_desktopDirector.sikuli\\'])

the 2nd imported images will not be recognized by Sikuli. But if I removed the 1st import, the 2nd import will work fine.

I'm using these codes to import the images from 2 libraries....

projectImgsLabPath1="C:\\GUITest\\GUITest.sikuli\\objectData"
if not projectImgsLabPath1 in sys.path: sys.path.append(projectImgsLabPath1)
from imgs import *

projectImgsLabPath2="C:\\GUITest\\GUITest.sikuli\\projects\\DesktopDirector\\objectData"
if not projectImgsLabPath2 in sys.path: sys.path.append(projectImgsLabPath2)
from imgs_desktopDirector import *

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

Yes everything looks fine.

What exactly are your problems/symptoms? What are the errors you get?

I tested a situation like yours in my environment and it worked fine.

Are you really sure, that there are no duplicate image file names (look into the .sikuli folders) or variable/function names, that prevent the usage from the second import?

Revision history for this message
Tsung-Hsiang Chang (vgod) said :
#4

@joe, the returned array of getImagePath should have two elements instead of one, and
this looks like a bug of Sikuli on Windows. Can you report this as a bug? We will fix it in the next release.

Revision history for this message
Tsung-Hsiang Chang (vgod) said :
#5

@joe, btw, this bug only exists in the import statement.
if you manually use addImagePath(path1) and addImagePath(path2), they should work fine.

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

@ joe fu
Sorry, for having been that blind. I should have seen that too :-((

Revision history for this message
joe fu (jfu-yahoo) said :
#7

Hi, I've created a bug for the issue of multiple import of image libraries.
I've tried to manually use addImagePath(path1) and addImagePath(path2), but sitll not working for me.
could you tell me how to exactly use addImagePath?

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

I just made some tests.

the best you can do is the following:

- make all your imports as if the problem was not there
this will leave the Image Path in the not usable way

- then (taking your example above) do the following:
if not projectImgsLabPath1+"\\imgs.sikuli\\" in getImagePath(): # to avoid double action in IDE
    removeImagePath(getImagePath()[0]) # removes the wrong entry, remove it if it makes problems
    addImagePath(projectImgsLabPath1+"\\imgs.sikuli")
    addImagePath(projectImgsLabPath2+"\\imgs_desktopDirector.sikuli"

got the idea?? the trailing \\ in the if is needed, since the internal logic adds it with addImagePath()

Revision history for this message
joe fu (jfu-yahoo) said :
#9

Thanks RaiMan, that solved my question.

Revision history for this message
joe fu (jfu-yahoo) said :
#10

Hi RaiMan,

does the RC2 resolve this issue of importing multiple image libraries in sikuli?

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

yes it does.

have fun with it.

Revision history for this message
Iole (markiole-saberon) said :
#12

Hi Raiman,

I downloaded the lates sikuli. version 1.1.0. But this issue still exists. When i call the first imageloader, it will run as expected however whne calling the second imagelibrary. it just could not find the image and will also time out.

Revision history for this message
Iole (markiole-saberon) said :
#13

imagelibrary*

Revision history for this message
Iole (markiole-saberon) said :
#14

same scenario, one script for two imagelibrary. Just depends on the parameters that will pass down at start up for sikuli knows what imagelibrary to look at.

Can you help with this problem?

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

To post a message you must log in.