将numpy.ndarray转换为opencv cv::Mat
Converting numpy.ndarray into opencv cv::Mat
我有用于OpenCv C++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) PY_ARRAY_UNIQUE_SYMBOL应该在调用import_array的位置定义在包含 的其他地方,请使用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();
}
相关文章:
- 将CHW格式的浮点向量转换为cv::Mat
- C++:从GPU内存(cudaMemcpy2D)获取BGR图像(cv::Mat)
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 将 cv::mat 转换为 QImage
- 将 cv::Mat 转换为 std::vector 的通用函数
- 在 QML VideoOutput 中将 cv::mat 显示为 QVideoFrame
- 如何将 cv::Mat 转换为 vtkImageData?
- 如何将 vtkImageData 转换为 cv::Mat?
- 如何总结所有cv::Mat元素
- Qt-工作线程崩溃时将cv::Mat转换为QImage
- 在 cv::Mat 中生成 2D 坐标网格
- 将 cv::Mat 转换为无符号的 int 像素
- OpenCV 分段错误(核心转储)在使用 cv::Mat::at 时
- 如何将多个 cv::Mat 从 c++ dll 传递到 opencvsharp Mat c#?
- 如何在不复制数据的情况下将 cv::Mat 转换为 2d 标准::矢量
- 如何使用 (*mpORBextractorLeft)(im,cv::Mat(),mvKeys,mDescriptors)
- 从数组创建 Mat 时,'cv::Mat' 和 'int' 类型不兼容
- 如何将 cv::mat 对象从 python 模块传递到 c++ 函数并返回返回的 cv::mat 类型为对象?
- 移动语义和 cv::Mat
- OpenCV 错误:断言在 cv::Mat 行 522 中失败