VideoCapture cap(1); // try to open the USB camera const string windowName = "Realtime Image"; bool isRunning = true; if (!cap.isOpened()) // check if we succeeded { cap.open(0);// try to open the default camera if USB camera failed if (!cap.isOpened()) { cout << "No Camera Found!" << endl; return -1; } } Mat frame; cap >> frame; if (frame.empty()) { cout << "The frame is empty !!!" << endl; return -1; } namedWindow(windowName, 1); while (isRunning) { Mat frame; cap >> frame; // get a new frame from camera imshow(windowName, frame); int key = waitKey(1000); switch (key) { case 27: isRunning = false; break; default: break; } }
OpenCV - 摄像头读取图像
猜你喜欢
转载自blog.csdn.net/baishuo8/article/details/80664589
今日推荐
周排行