使用std :: async调用返回std :: vector的成员函数

时间:2016-01-27 23:25:58

标签: c++ multithreading opencv c++11 asynchronous

我知道,伙计们,关于std::async的帖子很多,但是我不能自己弄清楚(为了我的辩护,我可以说今天是我第一天看到整个多线程& async thing ...)。 这就是我拥有的和我想要它做的事情 - 我有一台相机和一台投影机,我想要同步它们。它们连接在一起,因此投影仪信号触发图像采集。然而,在我开始通过投影仪显示图像之前,我必须要求获取。我使用OpenCV作为图像处理/处理lib。

class Camera
{
public::
    //this one captures images till vector reaches given count of images (while loop)
    std::vector<cv::Mat> captureSetOfFrames(uint count = 10)
    {
         std::vector<cv::Mat> vect;
         while(vect.size() < count) { /*try to capture and append to vect */ };
    }
};
class Projector
{
public:
    void start();
    void stop();
}
int main()
{
    Projector *proj = new Projector();
    Camera *cam = new Camera();
    std::vector<cv::Mat> recvimgs;
    recvimgs.reserve(10);
    auto f = std::async(&Camera::captureSetOfFrames, cam, PATTERN_10);
    proj->start();
    while(recvimgs.size() < 10)
        recvimgs = f.get();
    proj->stop();
}

我收到错误:

3   IntelliSense: no operator "=" matches these operands
            operand types are: std::vector<cv::Mat, std::allocator<cv::Mat>> = std::vector<cv::Mat, std::allocator<cv::Mat>> (unsigned short)   
  1. 错误结束时此unsigned short来自哪里??
  2. 我怎样才能实现这种行为? (如果代码示例不够清楚,我想首先通过调用Camera::captureSetOfFrames()来准备抓取,然后同时调用Projector::start()但是知道相机已准备好捕获,最后通过调用Projector::stop()来终止显示拍摄所有图像)
  3. 希望你能搞清楚!

    PS:基本帖子向我提出了这个(不工作)解决方案How to, in C++11, use std::async on a member function?

0 个答案:

没有答案
相关问题