我想同时展示两个视频。下面的代码正在工作,但不知何故,当视频完成时,它出现了一个错误。如果我只播放一个视频,则不会出现错误。有什么帮助吗?
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
string filename1 = "C:/test_videos/toy_plane_liftoff.avi";
string filename2 = "C:/test_videos/toy_plane_liftoff_stab.avi";
VideoCapture capture1(filename1);
VideoCapture capture2(filename2);
Mat frame1, frame2;
if (!capture1.isOpened())
throw "Error1";
if (!capture2.isOpened())
throw "Error2";
for (int i = 0; i <= min(capture1.get(CV_CAP_PROP_FRAME_COUNT), capture2.get(CV_CAP_PROP_FRAME_COUNT)); i++)
{
capture1 >> frame1;
capture2 >> frame2;
imshow("1", frame1);
imshow("2", frame2);
if (waitKey(30) >= 0)
break;
}
return 0;
}
您可以通过以下方式消除错误
if( !frame1.empty())
imshow("1", frame1);
if( !frame2.empty())
imshow("2", frame2);