capture vidio from 2 cameras
Hi OpenCV. I tryed to capture vidio from 2 cameras but only one camera works, and the other one shows a green screen. Please Help Me!
My system:
#include stdafx.h
#include highgui.h
#include stdio.h
#include dshow.h
int main()
{
CvCapture* capture1 = cvCaptureFromCAM(CV_CAM_ANY);
CvCapture* capture2 = cvCaptureFromCAM(CV_CAM_ANY);
if ( !capture1 )
{
fprintf( stderr, "ERROR: capture1 is NULL \n" );
getchar();
return -1;
}
if ( !capture2 )
{
fprintf( stderr, "ERROR: capture2 is NULL \n" );
getchar();
return -1;
}
cvNamedWindow( "cam1");
cvNamedWindow( "cam2");
while (1)
{
IplImage* frame1 = cvQueryFrame( capture1 );
IplImage* frame2 = cvQueryFrame( capture2 );
if ( !frame1 )
{
fprintf( stderr, "ERROR: frame1 is null...\n" );
getchar();
break;
}
if (!frame2 )
{
fprintf( stderr, "ERROR: frame2 is null...\n" );
getchar();
break;
}
cvShowImage( "cam1", frame1 );
cvShowImage( "cam2", frame2 );
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
cvReleaseCapture( &capture1 );
cvDestroyWindow( "cam1" );
cvReleaseCapture( &capture2 );
cvDestroyWindow( "cam2" );
return 0;
}