Import other python Modules

Asked by Komarue

Ok,

Sorry for asking so many questions but this is pretty cool stuff.

I am attempting to use PIL + some OCR with my Sikuli script but the normal imports don't work.
I have a python script that works great but I want to mesh it with Sikuli for targeting
-------------------------------
from pytesser import *
from PIL import ImageOps, ImageGrab

#want to use SIkuli to find the appropriate region & get the coordinates for the screen shot + OCR
#Capture image on screen at these coordinates
bbox = [0,0,100,100]
im = ImageGrab.grab(bbox)
#make image grayscale
gsIM = ImageOps.grayscale(im)
#invert image (the text is white on black, needs to be black on white for the OCR algorithm)
inIM = ImageOps.invert(gsIM)
print image_to_string(inIM)
----------------------------------
My Sikuli script looks like
target = find(1272918449246.png)
targetleft = target.left(25)
print str(targetleft.getX()) + "," + str(targetleft.getY())
-----------------------------------
What I want is to combine them so that:
bbox = [targetleft.getX(),targetleft.getY(),100,100]
run OCR on that bad boy

So the question then becomes, do I keep things in the Sikuli IDE or try to set up my python scripts to be able to run Sikuli stuff outside of the IDE (which I'm aware how to in a Java program but am unsure in a python environment)

I did try the below in an attempt to import things / run things using python, but the imports failed with "ImportError: No module named pytesser " or any other python module I was trying. Any suggestions or pointers would be helpful and appreciated.

exec open("C:\\Users\\User\\Documents\\pytesser\\temp.py").read()

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
Kakha Kakhidze (kakhak) said :
#1

Copy pytesser.py on you sikuli Lib instalation path e.g. "c:\Program Files\Sikuli\Lib\"

Revision history for this message
Kakha Kakhidze (kakhak) said :
#2

Also you have to append PIL lib in your python path e.g:
sys.path.append("D:\\Python26\\Lib\\site-packages\\PIL")

Revision history for this message
Mike Lee (m-lee) said :
#3

Did you get it working..I'm considering the same sort of addition ?

Can you help with this problem?

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

To post a message you must log in.