opencv怎么打开usb摄像头

2025-04-08 09:30:11
推荐回答(2个)
回答1:

//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);  
    }  
}

回答2:

我为什么打不开摄像头呢?