2016-08-05 6 views
0

私は同時に2つのビデオを提示したいと思います。次のコードは動作していますが、ビデオが終了するとエラーが発生します。 1つのビデオしか再生しない場合、エラーは発生しません。どんな助け?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); 
次の方法でエラーを取り除きます
関連する問題