[ OPENCV ] 同時儲存兩個USB視訊畫面
// 產生校正影像
// Generate calibration images.
#include <highgui.h>
#include <cv.h>
#include <stdio.h>
void main()
{
IplImage* capimg0;
IplImage* capimg1;
CvCapture* capture0;
CvCapture* capture1;
int loop = 1;
int file_idx_left = 0;
int file_idx_right = 0;
int key;
char filename[256];
char fileidx_left[10];
char fileidx_right[10];
//img = cvLoadImage( img_file_name, 1 );
capture0 = cvCaptureFromCAM(0);
capture1 = cvCaptureFromCAM(1);
if( ! capture0 )
{
fprintf( stderr, "unable to create camera \n" );
exit( 1 );
}
cvNamedWindow( "camera0", 1 );
cvNamedWindow( "camera1", 1 );
while(loop)
{
cvSetCaptureProperty(capture0,CV_CAP_PROP_FRAME_WIDTH,1280);
cvSetCaptureProperty(capture0,CV_CAP_PROP_FRAME_HEIGHT,720);
cvSetCaptureProperty(capture1,CV_CAP_PROP_FRAME_WIDTH,1280);
cvSetCaptureProperty(capture1,CV_CAP_PROP_FRAME_HEIGHT,720);
capimg0=cvQueryFrame(capture0);
cvShowImage( "camera0", capimg0 );
capimg1=cvQueryFrame(capture1);
cvShowImage( "camera1", capimg1 );
key = cvWaitKey( 5 );
if( key == 27 )
{
loop = 0;
}
else if(key =='s' || key=='S' )
{
sprintf( fileidx_left, "%03d" ,file_idx_left++ );
strcpy( filename, "SAVE_IMG_LEFT_" );
strcat( filename, fileidx_left );
strcat( filename, ".bmp" );
cvSaveImage( filename, capimg0 );
printf("Image file %s saved.\n", filename);
sprintf( fileidx_right, "%03d" ,file_idx_right++ );
strcpy( filename, "SAVE_IMG_right_" );
strcat( filename, fileidx_right );
strcat( filename, ".bmp" );
cvSaveImage( filename, capimg1 );
printf("Image file %s saved.\n", filename);
}
}
cvDestroyWindow( "camera0" );
cvReleaseCapture(&capture0);
cvDestroyWindow( "camera1" );
cvReleaseCapture(&capture1);
};