opencv 圖片通過按鍵儲存圖片
阿新 • • 發佈:2019-01-09
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"<<endl;
i++;
}
else if ( key_board == 'q')
{ cout<<"成功退出"<<endl;
break;
}
cvShowImage( "Camera_2", frame2 );
cvShowImage( "Camera_1", frame1 );
}
return 1;
}
{
//定義和初始化變數
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"<<endl;
i++;
}
else if ( key_board == 'q')
{ cout<<"成功退出"<<endl;
break;
}
cvShowImage( "Camera_2", frame2 );
cvShowImage( "Camera_1", frame1 );
}
return 1;
}