T
Tim Williams
Hello all,
I'm trying to use the ctypes module to call functions in a DLL. I've figured out how to modify my path so the library is found, and I can call LoadLibrary on it, but one of the functions expects an array of POINTS. Here is the prototype from the .h file:
TRACKER_API HRESULT InitializeMask(HANDLE pHandle, int nWidth, int nHeight, POINT* ptMasks, int nNumPoints);
I did a
from ctypes.wintypes import *
Here's my test script:
##############
'''
Created on Aug 23, 2012
@author: williams
'''
import os
import numpy as np
import scipy.io
from ctypes import *
from ctypes.wintypes import *
matdata = scipy.io.loadmat(os.path.join(os.environ['userprofile'],'Desktop','S31_f1.mat'))
data = matdata['data']
nHeight,nWidth = data.shape
pth = os.environ['path'].split(';')
pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs'))
os.environ['path'] = ';'.join(pth)
tck=oledll.LoadLibrary('Tracker')
hTrkr = tck.CreateTracker()
maskImage = np.zeros((1024,1280),dtype='int32')
maskImage[300:305,100:105] = True
idx = np.array(maskImage.nonzero())
nPoint = idx.shape[1]
ptMaskType = nPoint * POINT
pts = zip(idx[1,:],idx[0,:])
ptMasks = ptMaskType(*pts)
tck.InitializeMask.argtypes=(HANDLE, c_int, c_int, c_void_p, c_int)
InitMaskResult = tck.InitializeMask(hTrkr, nWidth, nHeight, ptMasks, nPoint)
if __name__ == '__main__':
pass
##############
so I have the POINT class, and I've created the array of POINTs. When I try to call this function, I get this message:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ValueError: Procedure probably called with too many arguments (20 bytes in excess)
This is the first time that I've tried to use the ctypes module, so any help is appreciated.
TIA,
I'm trying to use the ctypes module to call functions in a DLL. I've figured out how to modify my path so the library is found, and I can call LoadLibrary on it, but one of the functions expects an array of POINTS. Here is the prototype from the .h file:
TRACKER_API HRESULT InitializeMask(HANDLE pHandle, int nWidth, int nHeight, POINT* ptMasks, int nNumPoints);
I did a
from ctypes.wintypes import *
Here's my test script:
##############
'''
Created on Aug 23, 2012
@author: williams
'''
import os
import numpy as np
import scipy.io
from ctypes import *
from ctypes.wintypes import *
matdata = scipy.io.loadmat(os.path.join(os.environ['userprofile'],'Desktop','S31_f1.mat'))
data = matdata['data']
nHeight,nWidth = data.shape
pth = os.environ['path'].split(';')
pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs'))
os.environ['path'] = ';'.join(pth)
tck=oledll.LoadLibrary('Tracker')
hTrkr = tck.CreateTracker()
maskImage = np.zeros((1024,1280),dtype='int32')
maskImage[300:305,100:105] = True
idx = np.array(maskImage.nonzero())
nPoint = idx.shape[1]
ptMaskType = nPoint * POINT
pts = zip(idx[1,:],idx[0,:])
ptMasks = ptMaskType(*pts)
tck.InitializeMask.argtypes=(HANDLE, c_int, c_int, c_void_p, c_int)
InitMaskResult = tck.InitializeMask(hTrkr, nWidth, nHeight, ptMasks, nPoint)
if __name__ == '__main__':
pass
##############
so I have the POINT class, and I've created the array of POINTs. When I try to call this function, I get this message:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ValueError: Procedure probably called with too many arguments (20 bytes in excess)
This is the first time that I've tried to use the ctypes module, so any help is appreciated.
TIA,