您当前的位置: 首页 >  Python

柳鲲鹏

暂无认证

  • 0浏览

    0关注

    4642博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C向Python正确传递数组的代码

柳鲲鹏 发布时间:2018-11-02 17:04:54 ,浏览量:0

  • 关键在于 import_array(),否则必然崩溃。
#include 
#include 

//必须这样写!
void init_numpy()
{
    import_array();
}

int fext_python_init(const char* pPath)
{
  PyObject *pArgs = NULL;

  Py_Initialize();
  init_numpy();


  PyObject* pArgs = PyTuple_New(1);

  //将c的img数组数据转换成pyobject类型的数组数据
  npy_intp dims[1] = {pImage->clip.width * pImage->clip.height * 4};

  //给定维度信息
  PyObject *pPyArray = PyArray_SimpleNewFromData(1, dims, NPY_CHAR, pImage->buffer.data); 
  PyTuple_SetItem(pArgs, 1, pPyArray);

……

}

 

关注
打赏
1665724893
查看更多评论
立即登录/注册

微信扫码登录

0.0528s