Convert opencv Mat to PyObject*

1

I've tried to convert OpenCV Mat to PyObject* with this code :

PyObject* ConvertMatToPyArray(const cv::Mat& mat) {

    npy_intp dims[3] = { mat.rows, mat.cols, mat.channels() };
    const int ND = 3;
    PyObject *pArray = PyArray_SimpleNewFromData(
        ND, dims, NPY_UINT8, reinterpret_cast<void*>(mat.data));

    return pArray;
}

but always raise this exception :

Exception thrown at 0x00007FF75B5EDF03 in EmbededPython.exe: 0xC0000005: Access violation reading location 0x0000000000000010.

Where I mistake? or How can I convert Mat to PyObject* ?

In the beginning of my code I used :

Py_Initialize();
PySys_SetArgv(argc,(wchar_t**)argv);

But when I want to add import_array() this error occurred:

RuntimeError: _ARRAY_API is not PyCapsule object
python
c++
opencv
pythonanywhere
python-embedding
asked on Stack Overflow Aug 17, 2019 by ali kiani • edited Aug 21, 2019 by ali kiani

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0