[英]c++ How to put the video sequence into a vector<Mat> in OpenCV?
I am a new learner in c++. 我是c ++的新学习者。 I read a video and I want to save the image sequence of the video into a vector called vector frame.
我读了一个视频,我想将视频的图像序列保存到一个称为矢量帧的矢量中。 The following is my code, please help me correct it if someone could, thank you a lot!
以下是我的代码,请帮助我纠正,如果有人可以,非常感谢你!
#include <cv.h>
#include <highgui.h>
#include <iostream>
#include <vector>
using namespace std;
using namespace cv;
int main()
{
VideoCapture capture("/home/P1030.MOV");
int totalFrameNumber = capture.get(CV_CAP_PROP_FRAME_COUNT);
vector<Mat> frame;
namedWindow("Display", WINDOW_AUTOSIZE);
for(int i=0; i < totalFrameNumber; i++)
{
frame.push_back(Mat());
imshow("Display", frame);
}
return 0;
}
You can do it as follows, although it is not recommended to load whole video in the memory at a single time. 您可以按照以下方式执行此操作,但不建议一次将整个视频加载到内存中。
int main()
{
VideoCapture capture("/home/P1030.MOV");
int totalFrameNumber = capture.get(CV_CAP_PROP_FRAME_COUNT);
Mat currentFrame;
vector<Mat> frames;
namedWindow("Display", WINDOW_AUTOSIZE);
for(int i=0; i < totalFrameNumber; i++)
{
capture>>currentFrame;
frames.push_back(currentFrame.clone());
imshow("Display", currentFrame);
waitKey(10);
}
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.