Playing Video from WebCam with OpenCV and C++
Playing Video from WebCam with OpenCV and C++
Cross platform video grabbing can sometimes be really painful. Another great thing about OpenCV is that it solves such problems for you with a couple of clean lines of code.
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
using namespace std;
using namespace cv;
int main()
{
VideoCapture cam(0);
if (!cam.isOpened())
return -1;
cv::Mat frame;
while (true)
{
cam.grab();
cam.retrieve(frame);
imshow("Cam:", frame);
cv::waitKey(1);
}
return 0;
}