Я прочитал видео и сохранил все кадры в векторе. Теперь я хочу сшить первые 50 кадров, которые хранятся в векторе, и сохранить результат, после этого сшить следующие 50 кадров, сохранить результат и так далее. Это связано с тем, что класс сшивания opencv не обрабатывает большое количество кадров одновременно и выдает ошибку: недостаточно памяти. Я не могу реализовать правильный лог c. Пожалуйста, помогите мне исправить код. Спасибо. Мой код выглядит следующим образом:
int main(int argc, char const *argv[])
{
std::string video_file;
// Read video file
if (argc > 1)
{
video_file = argv[1];
}
else
{
video_file = "vid/xyz.mp4";
}
VideoCapture inputVideo(video_file);
if (!inputVideo.isOpened())
cerr << "Error opening video file\n";
double totalFrames(inputVideo.get(CV_CAP_PROP_FRAME_COUNT));
double frameRate(inputVideo.get(CV_CAP_PROP_FPS));
double timeInterval = 0.5; // in sec
int sizeReduction = 4;
int num = 1;
vector<Mat> frames;
vector<Mat> frames1;
Mat frame;
for (int num = 0; num < totalFrames; num++)
{
num = num + round(frameRate * timeInterval);
inputVideo.set(1, num);
inputVideo >> frame;
if (frame.empty())
continue;
cv::Size sz = frame.size();
cv::resize(frame, frame, sz / sizeReduction);
frames.push_back(frame); // vector 'frames' have all the frames to be processed
}
Stitcher::Mode mode = Stitcher::SCANS;
string result_name = "xyz.jpg";
vector<Mat> pano1;
Mat pano;
Ptr<Stitcher> stitcher = Stitcher::create(mode);
int f1, f2 = 0;
// need help to correct the code below:
for (f1 = f2; f1 <= frames.size(); f1++) {
int count = 0;
while (count < 50) {
frames1.push_back(frames[f1]); // I want to save first 10 frames in vector 'frames1'
count++;
}
Stitcher::Status status = stitcher->stitch(frames1, pano);
pano1.push_back(pano);
f2 = f2 + count;
}
Stitcher::Status status = stitcher->stitch(pano1, pano);
imwrite(result_name, pano);
cout << "stitching completed successfully\n" << result_name << " saved!";
return EXIT_SUCCESS;
}