Wrap OpenCV Mat as numpyarray hangs ?

asked 2019-03-08 05:03:18 -0600

RPH gravatar image

updated 2019-03-08 05:09:40 -0600

Hi, I am using opencv v3.4.2 with QT Creator IDE in C++.

I am trying to wrap an OpenCV matrix (Mat) as a numpyarray (PyObject *) so that I can pass it to a python script for processing. I am using the built-in wrapper functions from here: opencv/cv2.cpp. In particular this function:

PyObject* pyopencv_from(const Mat& m)
    if( !m.data )
    Mat temp, *p = (Mat*)&m;
    if(!p->u || p->allocator != &g_numpyAllocator)
        temp.allocator = &g_numpyAllocator;
        p = &temp;
    PyObject* o = (PyObject*)p->u->userdata;
    return o;

So I have something like this:

Mat frame;
/*frame is populated*/
PyObject* pMat = opencv_from(frame);

The code compiles fine but when I call the function it hangs on m.copyTo(temp).

Does anyone have any advice on why this is not working ? Thanks.

edit retag flag offensive close merge delete



error msg missing here ?

berak gravatar imageberak ( 2019-03-08 05:07:10 -0600 )edit

@berak There is no error message. It just sits there and doesn't go past that point. The program does not crash either.

RPH gravatar imageRPH ( 2019-03-08 05:08:34 -0600 )edit