How do I display two or more videos using opencv?
How do I display two or more videos with different lenghts (1,2 mins) using opencv?
int main(){
/* Open the Video File for Reading */
VideoCapture cap("CarSurveillance/Video1.avi"); // 00:00:33
VideoCapture cap2("CarSurveillance/Video2.mp4"); // 00:01:12
if (!cap.isOpened()){
cout << "Was not possible to Open the Video" << endl;
cout << "Reasons:" << endl;
cout << "1st: Wrong PATH" << endl;
cout << "2nd: Wrong Extension" << endl;
cout << "3rt: Unknown Reasons" << endl;
system("PAUSE");
exit(EXIT_FAILURE);
}
if (!cap2.isOpened()){
cout << "Was not possible to Open the Video" << endl;
cout << "Reasons:" << endl;
cout << "1st: Wrong PATH" << endl;
cout << "2nd: Wrong Extension" << endl;
cout << "3rt: Unknown Reasons" << endl;
system("PAUSE");
exit(EXIT_FAILURE);
}
namedWindow("Video1", CV_WINDOW_AUTOSIZE);
bool video1WindowDestroyed = false;
bool video2WindowDestroyed = false;
namedWindow("Video2", CV_WINDOW_AUTOSIZE);
double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video
cout << "Video 1 Frame per seconds : " << fps << endl;
fps = cap2.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video
cout << "Video 2 Frame per seconds : " << fps << endl;
Mat frame, frame2;
cap.read(frame); // read a new frame from video
cap2.read(frame); // read a new frame from video
while (true){
if ((video1WindowDestroyed == false) && (cap.read(frame) == true)){
imshow("Video1", frame);
if (cap.read(frame) == false){
destroyWindow("Video1");
video1WindowDestroyed = true;
}
}
if ((video2WindowDestroyed == false) && (cap2.read(frame2) == true)){
imshow("Video2", frame2);
if (cap2.read(frame2) == false){
destroyWindow("Video2");
video2WindowDestroyed = true;
}
}
if (video2WindowDestroyed == true && video2WindowDestroyed == true){
break;
}
waitKey(30);
}
waitKey(0);
system("PAUSE");
return 0;
}
when first video ends he is slow to close the window and pause the second video, two seconds after restart