求助各位大神,刚开始接触openCV,目前使用VS2013,openCV2.4.8。用openCV捕获USB摄像头,程序编译没报错,就是弹出一个窗口然后立马消失,命令行窗口提示摄像头打开失败,不知道什么原因,网上的帖子各种说法,终究没有解决
```#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "stdlib.h"
#include "windows.h"
#include "iostream"
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
cvNamedWindow("camera",CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateCameraCapture(-1);
if (!capture)
{
cout << "camera failed" << endl;
}
IplImage* frame;
Sleep(2000);
while (1)
{
frame = cvQueryFrame(capture);
if (!frame)
{
break;
}
cvShowImage("camera", frame);
char c = cvWaitKey(33);
if (c == 27)
{
break;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("camera");
return 0;
}