1

I want to read around 50 video frames using cv::VideoCapture, then call these 50 images one by one to do some other work. For doing this, I tried using resize and some other method, but still couldn't solved it. For instance, I get images from a video like this:

cv::VideoCapture myCapture(0);
while(true)
{
    cv::Mat inputFrame;
    myCapture>>inputFrame;
}

I want to save the first 50 inputFrame, then call them one-by-one later to do some other work. Processing the current frame first and then reading the next frame is not what I want to do. Also, I don't want to write them first into my hard disk then read them. I want a kind of cell that contains image matrix. Is there any solution?

4

1 回答 1

4

尝试这个:

#include <vector>

std::vector<cv::Mat> frames;
cv::Mat inputFrame;

for(int i=0; i<50; i++){
    myCapture>>inputFrame;
    frames.push_back(inputFrame);
}

它将frames用图像填充矢量。然后,您可以根据需要访问它们。对此的一个轻微变体是实例化这个向量,然后覆盖连续的条目,而不是使用以下push_back方法:

#include <vector>

std::vector<cv::Mat> frames;
frames.resize(50);
cv::Mat inputFrame;

for(size_t i=0; i<frames.size(); i++){
    myCapture>>inputFrame;
    frames[i] = inputFrame;
}
于 2013-09-22T12:25:59.503 回答