【问题标题】:Boost thread_group returns empty Matrix (openCV)Boost thread_group 返回空矩阵(openCV)
【发布时间】:2014-03-03 09:42:47
【问题描述】:

我正在尝试使用 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”内。 (也许这是问题的一部分?)

【问题讨论】:

  • 好的,我自己检查了 :)。因此,必须先初始化矩阵,然后才能在线程中对其进行操作。我仍然想在函数“manipulateMatrixFunction”中初始化矩阵。有什么建议吗?

标签: c++ multithreading opencv boost matrix


【解决方案1】:

通过引用传递Mat 实例:

#include <boost/ref.hpp>

//...
threadGroup.create_thread(boost::bind(&manipulateMatrixFunction,boost::ref(myMatrix)));
//...

但要确保这个实例比线程长。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 1970-01-01
    • 2012-04-11
    • 2013-10-01
    • 2014-09-18
    相关资源
    最近更新 更多