Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyopencv_from crash while calling Py_INCREF (opencv 4.1.2 python binding with cv2.cpp) #3

Open
ErhanOnur opened this issue Feb 28, 2023 · 1 comment

Comments

@ErhanOnur
Copy link

Hello,

I am doing a python binding for a function that returns opencv mat object. so I used pyopencv_from for that as below:

static PyObject *method_convertLeaf2Mat(PyObject *self, PyObject *args) {
    /* inner details....*/
    const cv::Mat& m = i_leaf->getCvMat(cmd_context);
    return pyopencv_from(m);
}

But when pyopencv_from is called, the program crashes. If I remove "Py_INCREF(o);" part from pyopencv_from function then I got following result:

>>> x = mod_imgproc.convertLeaf2Mat(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: <built-in function convertLeaf2Mat> returned NULL without setting an error

Here is the pyopencv_from function definition:

template<>
PyObject* pyopencv_from(const Mat& m)
{
    if( !m.data )
        Py_RETURN_NONE;
    Mat temp, *p = (Mat*)&m;
    if(!p->u || p->allocator != &g_numpyAllocator)
    {
        temp.allocator = &g_numpyAllocator;
        ERRWRAP2(m.copyTo(temp));
        p = &temp;
    }
    PyObject* o = (PyObject*)p->u->userdata;
    Py_INCREF(o);
    return o;
}

I am using opencv 4.1.2. Which part could be wrong?

Thank you

@ErhanOnur
Copy link
Author

Hi
It is working now. Can you please delete this issue?
I started using gen.py.
gen.py was not creating the wrapper function. So I did some changes on it, then it started creating the wrapper functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant