I am a new learner in 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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With