Convert opencv Mat to PyObject*

岁酱吖の 提交于 2020-03-03 09:09:11

问题


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

来源:https://stackoverflow.com/questions/57533462/convert-opencv-mat-to-pyobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!