簡體   English   中英

將numpy.ndarray轉換為opencv cv :: Mat

[英]Converting numpy.ndarray into opencv cv::Mat

我有用於C ++ OpenCv的Boost-Python接口。 我從python調用C ++方法時遇到此錯誤:

Boost.Python.ArgumentError: Python argument types in
    Vision.process(Vision, numpy.ndarray, numpy.ndarray)
did not match C++ signature:
    process(python::vision::PythonVision {lvalue}, cv::Mat {lvalue}, cv::Mat {lvalue})

我正在使用python cv2.so模塊。 如何將numpy.ndarray轉換為cv :: mat?

我使用了以下項目: https : //github.com/Algomorph/pyboostcvconverter並靜態鏈接到它。

注意(為避免分段錯誤):

1)應該在調用import_array的位置定義PY_ARRAY_UNIQUE_SYMBOL。在其他位置,請使用NO_IMPORT_ARRAY

#define PY_ARRAY_UNIQUE_SYMBOL PYVISION_ARRAY_API
#include <pyboostcvconverter/pyboostcvconverter.hpp>

2)從BOOST_PYTHON_MODULE調用init_ar

/**
 * @brief Initialize Numpy Array
 */
static void init_ar( )
{
    // initialize
    Py_Initialize();

    // defined in numpy
    import_array();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM