【问题标题】:Converting PyObject* to C++ Object将 PyObject* 转换为 C++ 对象
【发布时间】:2016-01-18 08:37:20
【问题描述】:

我有一个共享库 (util.so),它将以下内容返回给 python:

cv::Mat toCvMat(PyObject *ndArrayObj) {
    // return cv::Mat
}

我从我的 python 脚本调用该方法,使用:

Python:

testMat = util.toCvMat(orig_frame_gray_img)

当我将它传递给我的其他测试库 (test_library.so) 时,它作为 PyObject* 传递,我如何访问我的 test_library.so 中的 cv::Mat?:

Python:

test_library.process(testMat)

C++

bool TestLibrary::Process( PyObject* pTestImg)
{
// How to get cv::Mat from pTestImg?
}

目前,我的 test_library 没有与 util 链接,它们是单独的 .so 文件。

【问题讨论】:

    标签: python c++ type-conversion boost-python pyobject


    【解决方案1】:

    基于http://yati-sagade.github.io/2013/05/11/numpy-boost-python/

    NDArrayConverter cvt;
    cv::Mat m;
    m = cvt.toMat(pTestImg);
    

    需要的NDArrayConverter可以从https://github.com/yati-sagade/opencv-ndarray-conversion找到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      相关资源
      最近更新 更多