2016-08-05 113 views
0

我想同时演示两个视频。以下代码正在工作,但不知何故,当视频完成时发生错误。如果我只播放一个视频,则不会发生错误。任何帮助?OpenCV同时播放2个视频

#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; 
} 

回答

1

你得到下列方式

if(!frame1.empty()) 
    imshow("1", frame1); 
    if(!frame2.empty()) 
    imshow("2", frame2); 
摆脱错误的