我是c++的新手。我读了一个视频,我想把视频的图像序列保存到一个叫做 vector 帧的 vector 中。以下是我的代码,如果有人可以帮我改正,非常感谢!
#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;
}
最佳答案
您可以按如下方式进行,但不建议一次将整个视频加载到内存中。
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;
}
关于c++如何将视频序列放入OpenCV中的vector <Mat>中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22345715/