解决方案
20
可以试试opencv的imencode函数
10
#include <iostream>
#include <vector>
#include <string>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
using namespace std;
using namespace cv;
int main() {
string fname("E:\Videos\tree.avi");
VideoCapture capture(fname);
if (!capture.isOpened())
return 1;
vector<Mat> frames;
cout << "Frame Count: " << capture.get(CV_CAP_PROP_FRAME_COUNT) << endl;
while (true) {
Mat frame;
if (!capture.read(frame))
break;
imshow("frame", frame);
char key = waitKey(25);
if (key == 27)
break;
frames.emplace_back(frame);
cout << "frame --> " << frames.size() << endl;
}
destroyWindow("frame");
capture.release();
cout << "vector size: " << frames.size() << endl;
for (auto it = frames.begin(); it != frames.end(); ++it) {
imshow("vector", *it);
waitKey(27);
}
return 0;
}
#include <iostream>
#include <vector>
#include <string>
#include <memory>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
using namespace std;
using namespace cv;
int main() {
string fname("E:\Videos\tree.avi");
VideoCapture capture(fname);
if (!capture.isOpened())
return 1;
vector<shared_ptr<Mat>> frames;
cout << "Frame Count: " << capture.get(CV_CAP_PROP_FRAME_COUNT) << endl;
int width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
int height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
while (true) {
Mat* frame = new Mat;
if (!capture.read(*frame)) {
delete frame;
break;
}
imshow("frame", *frame);
waitKey(25);
frames.push_back(shared_ptr<Mat>(frame));
}
destroyWindow("frame");
capture.release();
cout << "vector size: " << frames.size() << endl;
for (auto it = frames.begin(); it != frames.end(); ++it) {
imshow("vector", **it);
waitKey(27);
}
}
