creating an image lib

Asked by Sander on 2018-07-31

Hi there,

I've been using sikulix for some time on a windows machine and worked perfectly.
Now I am using a iOS and finished setting up sikulix again and runs ok.

What I am trying to do is capturing images save them in a folder and trying to give them proper names.
This is what I did:
from sikuli import *
from sikuli.Sikuli import *

class testImages():

 imgDict = {}

 def __init__(self):
  self.imgDict = {}

  self.addImage("someTestImage", "someTestImage.png")
                #and like to extend this list with images

        def addImage(self, name, img):
            self.imgDict[name] = img

        def getImage(self, name):
            return self.imgDict[name]

Than created the following:
from sikuli import *
from testImages import *
from sikuli.Sikuli import *


[error] RunTimeIDE: ImageMissing: someTestImage

Using Windows, saving the class testImages(), it would create me a .py, .html and a py.class
Now when I save the testImages class on my iOS it only creates a .sikuli file.

When I capture images using the EDI the scripts runs ok, but the images captured do have this 3495374599345.png as filename (and not sure where they are stored)

Could you please help me out here?

So basically I want to save images manually with a proper name and create them only once.

Thanks in advance.

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

iOS ????

do you mean macOS?

Sander (sander-helsloot) said : #2

Hi RailMan, sorry yes, just using my MacBook Pro. (Was already late yesterday evening) :-)
If you need more info, please let me know.

RaiMan (raimund-hocke) said : #3

general suggestions:
- use 1.1.2 or even 1.1.3 nightly
- have a look at the ImagePath feature

BTW: macOS is my primary work system ;-)

Sander (sander-helsloot) said : #4

Thanks RailMan,

I'll take a look, yesterday I tried to figure out for view hours how this works, I'll try tonight again, and let you know if I could get it to work.

Thanks for pointing this out.

Got to go now.

macOS rocks! :-)

RaiMan (raimund-hocke) said : #5

--- I tried to figure out for view hours how this works

... rather simple:

- make a script somewhere and name it e.g. MyImages.sikuli

- use the IDE, to capture and name the images

- save the script

- in your script simply say at the beginning:
setBundlePath(<absolute path to your MyImages.sikuli>)

**** For automatic naming of images there is a nice goody in the IDE:

- make line like so
image1 =

- place the cursor somewhere at the end of the line after the =

- take a shot

the shot will be named image1.png and will keep the same name when recaptured

then there are 2 usage scenarios:

1. image path
- use setBundlePath()
- reference the images as Strings like

2. import
from MyImages.sikuli import *
find(image1) # ref using the assigned variable.
... be careful with possible name clashes - have a naming convention.

RaiMan (raimund-hocke) said : #6

One more thing:
I guess you have a Retina display:
Do not try to capture images with the Mac capture tool, since they will not work with SikuliX (each pixel is converted to 4 pixels, hence the image has double width and double height).
... always use the SikuliX IDE or the SikuliX capture features programmatically.

Sander (sander-helsloot) said : #7

Hi RaiMan, thanks for the prompt reply.

Good to know about the goodie, that works perfectly, thanks for that.
I prefer to use the variable name (less typing) and looks nice when looking at the script.

But it is not working yet, this is what I did:

from sikuli import *

image1 = image1.png
image2 = image2.png


from sikuli import *
from someImages import *


[error] script [ executableTestsPostNLBagage ] stopped with error in line 2
[error] ImportError ( No module named sikuli )

Hope you could help me with the last bit, cheers!

Manfred Hampl (m-hampl) said : #8

The lines

image1 = image1.png
image2 = image2.png

are definitely wrong, they have to be

image1 = "image1.png"
image2 = "image2.png"

Sander (sander-helsloot) said : #9

Hi Manfred,

Thanks for coming back on this. You are correct. That is my mistake editing this answer.
But the actual problem is, is that is returns an error for the import.

I've tried what Raiman suggested but it gives an:

[error] script [ executableTests] stopped with error in line 2
[error] ImportError ( No module named sikuli )

from sikuli import *

image1 = "image1.png"
image2 = "image2.png"


# executableTests
from sikuli import *
from someImages import *


[error] script [ executableTests ] stopped with error in line 2
[error] ImportError ( No module named sikuli )

RaiMan (raimund-hocke) said : #10

--1. the main script (the one, that is run) does not need
from sikuli import *

--2. when using import for the script, that contains the images,
is not needed
… an imported script is automatically added to the imagepath

--3. a script, that only contains image references like
imageXXX = "imageWhatever.png"
does not need a
from sikuli import *
This is only needed in imported scripts, that use SikuliX features.

If you get the error
[error] ImportError ( No module named sikuli )
when running a script, then you have to revise your setup.
Running a script in a correctly setup SikuliX IDE will never produce such errors.
This only happens in setups, where you try to run SikuliX scripts with other means: Jython from commandline, other IDE's like NetBeans/PyDev, PyCharm.

Sander (sander-helsloot) said : #11

Hi Raiman,

It works, it does recognise the images :-)

For the someImages.sikuli I've removed all import statements
The executable script I've used: from someImages import *. (otherwise it is not working)

Thanks for the help!
I do see see some other issues I have, but I'll raise this in a separate ticket.

Thanks for the help!