我有两台摄像机,需要同时显示来自不同窗口或同一窗口的视频。但是,使用以下代码,仅显示一个摄像头馈送 (camera(1))。有人可以指出我的代码中需要更改的内容,或者链接到可以达到预期效果的其他代码吗?
注意这不适用于立体视觉。
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();
}