我正在尝试在 python 和 c++ 之间进行通信。这是我正在使用的主要源代码的链接:https://github.com/rajatsaxena/pyImageListToVectorMatcpp主要灵感来自这里https://github.com/Algomorph/pyboostcvconverter .我希望能够在 python 端获取一个 numpy 数组元组(OpenCV 图像),c++ 中的过程,然后最终返回一个 numpy 数组元组(OpenCV 图像)。
但是我开始收到这个错误:
In function ‘PyObject* pbcvt::getStitchingParams(PyObject*)’:
/home/**/pyImageListToVectorMatcpp/src/python_module.cpp:96:69: error: cannot convert ‘std::vector<cv::Mat>’ to ‘PyObject* {aka _object*}’ for argument ‘1’ to ‘std::vector<cv::Mat> pbcvt::fromTupleToVector(PyObject*)’
vector<Mat> InputImage = pbcvt::fromTupleToVector(InputImage);
^
/home/**/pyImageListToVectorMatcpp/src/python_module.cpp: In function ‘void pbcvt::init_module_pbcvt()’:
/home/**/pyImageListToVectorMatcpp/src/python_module.cpp:459:34: error: too few arguments to function ‘std::vector<cv::Mat> pbcvt::fromTupleToVector(PyObject*)’
pbcvt::fromTupleToVector();
^
In file included from /home/**/pyImageListToVectorMatcpp/src/python_module.cpp:4:0:
/home/**/pyImageListToVectorMatcpp/include/pyImageListToVectorMatcpp.hpp:73:13: note: declared here
vector<Mat> fromTupleToVector(PyObject* o);
^
make[2]: *** [CMakeFiles/pbcvt.dir/src/python_module.cpp.o] Error 1
make[1]: *** [CMakeFiles/pbcvt.dir/all] Error 2
make: *** [all] Error 2
这是因为我的元组到 vector 转换器脚本 src/pyboost_cv2_converter.cpp
存在一些问题,显然我无法弄清楚。
最佳答案
根据您的代码判断here ,您对 fromTupleToVector 的参数应该是小写字母开头的 inputImage,它是 getStitchingParams 的参数,类型为 PyObject*。
关于python - 将 numpy 数组的 python 元组转换为 cv::Mat cpp 的 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42919209/