I've tried to convert OpenCV Mat to PyObject* with this code :
PyObject* MatToList_Float(const cv::Mat& mat) {
int listSize = mat.size().height * mat.size().width;
PyObject* listObj = PyList_New(listSize);
if (!listObj) throw logic_error("Unable to allocate memory for Python list");
for (unsigned int i = 0; i < listSize; i++) {
PyObject *num = PyFloat_FromDouble(mat.data[i]);
if (!num) {
Py_DECREF(listObj);
throw logic_error("Unable to allocate memory for Python list");
}
PyList_SET_ITEM(listObj, i, num);
}
return listObj;
}
but always raise this exception at PyList_SET_ITEM
line :
Exception thrown at 0x00007FF68E6DE178 in EmbededPython.exe: 0xC0000005: Access violation writing location 0x0000000000000001.
In the beginning of my code I used :
Py_Initialize();
PySys_SetArgv(argc,(wchar_t**)argv);
User contributions licensed under CC BY-SA 3.0