opencv 图片通过按键保存图片

int take_photos(char *left, char *right)
{      
//定义和初始化变量
int i = 0;
IplImage* img = 0;
char image_name[13];


CvCapture* capture1 = cvCreateCameraCapture( 0 );
    CvCapture* capture2 = cvCreateCameraCapture( 1 );


    double w = 320, h = 240; 
    cvNamedWindow( "Camera_1", CV_WINDOW_AUTOSIZE );
    cvNamedWindow( "Camera_2", CV_WINDOW_AUTOSIZE );


    IplImage* frame1;
    IplImage* frame2;
  while(1)
  {
   
frame1 = cvQueryFrame( capture1 );
if( !frame1 )
{
MessageBox(NULL,TEXT("1号设备没有打开"),TEXT("出错了"),0);


break;
}
frame2 = cvQueryFrame( capture2 );
if( !frame2 )
{
MessageBox(NULL,TEXT("1号设备没有打开"),TEXT("出错了"),0);


break;
}  
     char key_board=cvWaitKey(10);
 if ( key_board == 'w')

sprintf(image_name, "%s%d%s", left, i, ".jpg");//保存的图片名
cvSaveImage( image_name, frame1);   //保存一帧图片
   sprintf(image_name, "%s%d%s", right, i, ".jpg");//保存的图片名
cvSaveImage( image_name, frame2);   //保存一帧图片
    cout<<"成功保存图片:"<<".jpg"<     i++;

else if ( key_board == 'q')
{  cout<<"成功退出"< break;
 }



cvShowImage( "Camera_2", frame2 );
cvShowImage( "Camera_1", frame1 );

  }
return 1;  
}  

你可能感兴趣的:(c++)