//Program to display a video from attached default camera device
#include
#include
using namespace std;
using namespace cv;
char *window_name = "Video";
int main()
{
VideoCapture cap(0); //此处默认USB摄像头
if (!cap.isOpened())
{
cerr << "webCam could't be opened successfully" << endl;
return EXIT_FAILURE;
}
namedWindow(window_name);
while (char(waitKey(1)) != 'q'&&cap.isOpened())
{
Mat frame;
cap >> frame;
if (frame.empty())
{
cout << "Video over" << endl;
break;
}
imshow(window_name, frame);
}
}
我为什么打不开摄像头呢?