I have two cameras that I need to display video from at the same time, either in separate windows or in the same window. However, using the following code, only one of the camera feeds (camera(1)) displays. Could someone point out what needs to be changed in my code, or link to other code that would achieve the desired effect?
N.B. This is NOT for stereo vision.
int main()
{
//initialize and allocate memory to load the video stream from camera
CvCapture *capture1 = cvCaptureFromCAM(0);
if( !capture1 ) return 1;
//create a window with the title "Video1"
cvNamedWindow("Video1");
while(true) {
//grab and retrieve each frames of the video sequentially
IplImage* frame1 = cvQueryFrame( capture1 );
if( !frame1 ) break;
//show the retrieved frame in the "Video1" window
cvShowImage( "Video1", frame1 );
//wait for 40 milliseconds
int c = cvWaitKey(40);
//exit the loop if user press "Esc" key (ASCII value of "Esc" is 27)
if((char)c==27 ) break;
}
//initialize and allocate memory to load the video stream from camera
CvCapture *capture2 = cvCaptureFromCAM(1);
if( !capture2 ) return 1;
//create a window with the title "Video2"
cvNamedWindow("Video2");
while(true) {
//grab and retrieve each frames of the video sequentially
IplImage* frame2 = cvQueryFrame( capture2 );
if( !frame2 ) break;
//show the retrieved frame in the "Video2" window
cvShowImage( "Video2", frame2 );
//wait for 40 milliseconds
int c = cvWaitKey(40);
//exit the loop if user press "Esc" key (ASCII value of "Esc" is 27)
if((char)c==27 ) break;
}
//destroy the opened window
cvDestroyWindow("Video1");
cvDestroyWindow("Video2");
//release memory
cvReleaseCapture( &capture1 );
cvReleaseCapture( &capture2 );
return 0;
//VideoCapture1();
//VideoCapture2();
}