Boost thread_group 返回空矩阵 (openCV)

Boost thread_group returns empty Matrix (openCV)

本文关键字:openCV thread group 返回 Boost      更新时间:2023-10-16

我正在尝试使用提升库中的thread_group来操作 openCV 库中的矩阵对象(该程序是用 C++ 编写的)。但是,当我再次加入主线程后尝试保存矩阵时,矩阵不包含任何数据。任何人都可以提供如何使用升压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)));
//...

但请确保此实例的寿命超过线程。