Pointer to Image
Chris Jankowski
cjankowski at hbr-inc.com
Wed Oct 20 14:33:46 EDT 2004
Thomas Heller <theller at python.net> wrote in message news:<d5zesplp.fsf at python.net>...
> cjankowski at hbr-inc.com (Chris Jankowski) writes:
>
> > Hi all,
> > I am still new to using Python, so bare with me. I am trying to call
> > a DLL from my program to use some of it's functions. The only
> > parameter is supposed to be a pointer to an image. I have tried
> > several variations on passing this parameter to the DLL and I am not
> > having much luck. This is going to call other functions later for
> > OCR, but I want to get a simple one working first.
> >
> > Here is my code: (Very basic)
> >
> > from ctypes import *
> > import Image
> >
> > myOcr = windll.LoadLibrary('ocrdll.dll') # my DLL
> >
> > mySize = myOcr.GetImgBitmapSize ## load the function
> >
> > im = Image.open('C:\\chris.tif') ## load the Image
> > print id(im) ## for testing print address of im
> >
> > ##myFile = c_char_p(id(im)) # I have tried several variations of this
> >
> > x = mySize(myFile) ## Actual call to the DLL Function
> > ## documentation only one parameter passed
> > pointer to Image
> > ## Must be DIB Image(Device Independent Bitmap)
> > ## (could this be the problem?)
> > Thanks for the help.
>
> I assume the Image function you import in the code above is from PIL?
> In this case, it cannot work. You cannot take the address (id) of an
> arbitrary Python object, and assume that it points to C compatible data.
> Maybe you should use a function from the dll to load the image data, or
> you can read the file's bytes into python string, and pass that.
>
> Thomas
Here is what I have now.
from ctypes import *
def myOutputHandler(infotype, param):
outputFile.write("outhandler")
if infotype == "OT_TEXT":
print param
## return param
## elif infotype == "OT_ENDL":
## return "\n"
## elif infotype == "OT_ENDZ":
## return "\n\n"
return
#***************************************************************
#* main process *
#* myList - requests *
#* inList - data file *
#***************************************************************
if __name__ == '__main__':
outputFile=open('c:\\newOCR.txt', 'w')
myOcr = cdll.LoadLibrary('C:\\SimpleOCR\\ocrdll.dll')
loadImg = myOcr.LoadMultipleImg
x = loadImg("c:\\chris.tif")
print x
setLanguage = myOcr.SetLanguage
setLanguage('ENGLISH',".")
setOutputMode = myOcr.SetOutputMode
setOutputMode("OM_TEXT")
setOutputHandler = myOcr.OCRSetOutputHandler
z = id(myOutputHandler)
errorx = setOutputHandler(z)
getImage = myOcr.GetImage
img = getImage(x,0)
getNBImages = myOcr.GetNbImages
numImg = getNBImages(x)
processOCR = myOcr.OCR
myTest = processOCR(img) ## it will run without this line.
freeMultipleImage = myOcr.FreeMultipleImg
freeMultipleImage(x)
outputFile.close()
This will not run it abends when I try to call the .OCR function. I
am thinking that it cannot call the procedure to write the file. Any
ideas?
More information about the Python-list
mailing list