- images.push_back(img);
- images.push_back(img.clone());
视频转换为图片的例子:
-
- #include <opencv2/opencv.hpp>
- #include <sstream>
- using namespace cv;
- using namespace std;
- int main()
- {
- VideoCapture cap("Sample.avi");
- if (!cap.isOpened())
- {
- cout << "Can't open input video file" << endl;
- return -1;
- }
- Mat img;
- vector<Mat> images;
- int count = 0;
- while (cap.read(img))
- {
- if (img.empty())
- {
- cout << "Stop" << endl;
- break;
- }
- // 实验需要在这里通过count来限制只取100帧
- if (count < 100)
- {
- // images.push_back(img);
- images.push_back(img.clone());</span>
- }
- count++;
- }
- int n = 0;
- vector<Mat>::iterator it = images.begin();
- while (it != images.end())
- {
- Mat tmp = *it;
- stringstream ss;
- ss << n;
- n++;
- imwrite(ss.str() + ".jpg", tmp);
- imshow("tmp", tmp);
- it++;
- waitKey(10);
- }
- return 0;
- }