线程 'Win32 线程' (0xad4) 已退出,返回值为 -1 (0xffffffff)。
线程 'Win32 线程' (0x1250) 已退出,返回值为 -1 (0xffffffff)。
线程 'Win32 线程' (0xbd0) 已退出,返回值为 -1 (0xffffffff)。
程序“[168] CameraTest.exe: 本机”已退出,返回值为 -1 (0xffffffff)。
代码如下
#include
#include
int main()
{
char title[128];
IplImage *img = 0;
int key = 0;
CvCapture* capture = cvCaptureFromCAM(-1);
// If no compatible camera detected, print message and exit.
if (capture == NULL) {
printf("No camera detected!\n");
exit(-1);
}
// query frame and generate window title
img = cvQueryFrame(capture);
if (img == NULL) {
printf("Camera detected, but grab image error!\n");
exit(-1);
}
sprintf(title, "Camera Testing (%dx%d)", img->width, img->height);
// create a window at the top-left corner
cvNamedWindow(title, CV_WINDOW_AUTOSIZE);
cvMoveWindow(title, 0, 0);
while(1)
{
img = cvQueryFrame(capture);
// show the frame in the window created
cvShowImage(title, img);
key = cvWaitKey(20); // wait 20 ms
if ( key == 's' || key == 'S')
{
cvSaveImage("test.jpg", img);
continue;
}
if ( key > 0)
break;
}
// destroy the window and release the capture
cvDestroyWindow(title);
cvReleaseCapture( &capture );
return 0;
}