代码如下:
void call(char* data, int data_size) { PyObject* pPyArgs = PyTuple_New(4); //char 数组 npy_intp dims[1] = {data_size}; PyObject* pPyArray = PyArray_SimpleNewFromData(1, dims, NPY_CHAR, data); PyTuple_SetItem(pPyArgs, 0, pPyArray); //int 数组 PyTuple_SetItem(pPyArgs, 1, Py_BuildValue("[i,i,i,i,i,i]", width, height, id1, id2, id3, id4)); //text PyTuple_SetItem(pPyArgs, 2, Py_BuildValue("s", pInputData->save_path)); //list PyObject* pPyList = PyList_New(pInputData->element_count); for (int i=0; i<pInputData->element_count; i++) { Element* pElement = &(pInputData->elements[i]); PyList_SetItem(pPyList, i, Py_BuildValue("[i,i,i,i,i,i]", pElement->width, pElement->height, pElement->id1, pElement->id2, pElement->id3, pElement->id4 )); } PyTuple_SetItem(pPyArgs, 3, pPyList); PyObject* pPyResult = PyObject_CallObject(m_pPythonFunctions[0], pPyArgs); Py_DECREF(pPyArgs); }