June 2019
Intermediate to advanced
348 pages
8h 28m
English
We have gotten the information of the webcams in the preceding section, so let's capture and play the video feed from a chosen webcam using OpenCV.
It is very easy to capture a video using OpenCV. The following is an example:
#include <iostream> #include "opencv2/opencv.hpp" using namespace std; using namespace cv; int main() { VideoCapture cap(0); if(!cap.isOpened()) { return -1; } while(1) { Mat frame; cap >> frame; if (frame.empty()) break; imshow( "Frame", frame ); char c = (char)waitKey(25); if(c==27) // ESC break; } cap.release(); destroyAllWindows(); return 0; }
In the preceding code, first, we create an instance of VideoCapture with the index of the default webcam, and then test whether the camera is successfully ...
Read now
Unlock full access