2

I am trying to convert some of my MATLAB files to Python. I generated C code using the MATLAB Coder, then compiled everything in a library. I am now trying to make the wrapping for Python.

It looks as follows: data_in is an image and the output of the makePyramid function is a structure of length level with 3 fields img, gradX and gradY.

def TestEmxAPI(data_in):

    #class Opaque(ctypes.Structure):
    #    pass

    sz = (data_in.shape)

    class Pyr(ctypes.Structure): 
        _fields_ = [('img', (ctypes.c_double*sz[0])*sz[1]),
                    ('gradX', (ctypes.c_double*sz[0])*sz[1]),
                    ('gradY', (ctypes.c_double*sz[0])*sz[1])] 

    nrows = ctypes.c_int(sz[0])
    ncols = ctypes.c_int(sz[1])
    level = 1
    blur = -1
    win = np.array([10.,10.,10.])
    winc = (ctypes.c_double *3)(*win)

    pp=Pyr()

    in_emx = EMX.emxCreateWrapper_real_T(ctypes.c_int(data_in.ctypes.data), 
                                         nrows, ncols) 

    EMX.emxCreateWrapper_struct0_T.argtypes = (ctypes.POINTER(Pyr), 
                                               ctypes.c_int,
                                               ctypes.c_int)
    EMX.emxCreateWrapper_struct0_T.restype = ctypes.POINTER(Pyr)
    ou_emx = EMX.emxCreateWrapper_struct0_T(pp,sz[0], sz[1])

    EMX.makePyramid_2D(in_emx, 
                       ctypes.c_double(level), 
                       ctypes.c_double(blur), 
                       winc, 
                       ou_emx)

    return pp

I now get a nasty error:

WindowsError: exception: access violation reading 0x0000000000000014

How can I make this work?

3
  • Use the debugger to identify the line causing the problem. Commented Nov 2, 2019 at 15:16
  • stackoverflow.com/questions/24640817/… covers examples of doing this. You can also use a wrapper generator like SWIG to generate the wrappers. Here's a repo of examples showing how to use SWIG with MATLAB Coder Commented Nov 2, 2019 at 20:11
  • Thanks Ryan for your comment. I got very much inspired by the solution proposed by the stakoverflow link you sent. I thus wanted to use the wrapper already generated by the matlab coder. But I guess I am using it in a wrong way. Just in case the project with all the details can be found here: github.com/heleneayari/testmatcpython/tree/master Commented Nov 3, 2019 at 14:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.