c python 总结1

1.Init

    由于存在numpy的数据结构,除了Py_Initialize(); 还需要import_array();

    PyRun_SimpleString("import sys");

    std::string chdir_cmd = std::string("sys.path.append(\"" + python_rely_path + "\")");

2.import module and function

    pModule = PyImport_ImportModule(pypath.c_str());

    pLoadFunc = PyObject_GetAttrString(pModule, "init_facenet");//init_model

3 pass Argc

    pArgs_7_2 = PyTuple_New(7);
    pFaceNeedSaveIntoLib = PyList_New(0);
    PyList_Append(pFaceNeedSaveIntoLib, Py_BuildValue("s", sImgPath.c_str()));
    PyTuple_SetItem(pArgs_7_2, 0, pFaceNeedSaveIntoLib);
    PyTuple_SetItem(pArgs_7_2, 1, pnet);
    PyTuple_SetItem(pArgs_7_2, 2, rnet);
    PyTuple_SetItem(pArgs_7_2, 3, onet);
    PyTuple_SetItem(pArgs_7_2, 4, net_sess);
    PyTuple_SetItem(pArgs_7_2, 5, mtcnn_graph);
    PyTuple_SetItem(pArgs_7_2, 6, facenet_graph);

 4 call function

        pAddReturn = PyEval_CallObject(pFunc, pArgs_7_2);

5 convert to arrary

    pyAarryFaceslib = (PyArrayObject*)pReturn;

6 python arrary to Carrary

        for (Index_m = 0; Index_m < Rows; Index_m++) {
        for (Index_n = 0; Index_n < columns; Index_n++) {
            CArrays[Index_m][Index_n] = *(float *)(((PyArrayObject*)pReturn)->data + Index_m *((PyArrayObject*)pReturn)->strides[0] + Index_n * ((PyArrayObject*)pReturn)->strides[1]);
            //std::cout << CArrays[Index_m][Index_n] << std::endl;
        }

    }

7 Carrary to python arrary

   pReturn = PyArray_SimpleNewFromData(2, Dims, NPY_DOUBLE, CArrays);

8. analyze

    PyArg_ParseTuple(pLoadReturn, "O|O|O|O|O|O", &pnet, &rnet, &onet, &net_sess, &mtcnn_graph, &facenet_graph);

     i = _PyLong_AsInt(pReturn_2);

8 others

    npy_intp Dims[2];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值