我正在尝试使用 boost 库中的 thread_group 来操作 openCV 库中的矩阵对象(该程序是用 C++ 编写的)。 但是,当我再次加入主线程后尝试保存矩阵时,矩阵不包含任何数据。 谁能举例说明如何使用 boost thread_group 操作矩阵? (我真的需要多线程,否则计算需要几天时间)
这是我目前使用的代码:
Mat myMatrix;
// Start threads
boost::thread_group threadGroup;
threadGroup.create_thread(boost::bind(&manipulateMatrixFunction,myMatrix));
threadGroup.join_all();
矩阵只在主线程中声明。行数、列数和数据类型的初始化发生在“manipulateMatrixFunction”内部。 (也许这是问题的一部分?)
最佳答案
通过引用传递 Mat
实例:
#include <boost/ref.hpp>
//...
threadGroup.create_thread(boost::bind(&manipulateMatrixFunction,boost::ref(myMatrix)));
//...
但要确保这个实例比线程长。
关于c++ - Boost thread_group 返回空矩阵(openCV),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22143239/