Hi. I'm trying to capture video from my webcam via OpenCV C++. The program works fine, but the window terminates after displaying just one frame. I've tried Python examples as well on my computer, and they work as advertised. Help please.
1 | initial version |
Hi. I'm trying to capture video from my webcam via OpenCV C++. The program works fine, but the window terminates after displaying just one frame. I've tried Python examples as well on my computer, and they work as advertised. Help please.
2 | No.2 Revision |
Hi. I'm trying to capture video from my webcam via OpenCV C++. The program works fine, but the window terminates after displaying just one frame. I've tried Python examples as well on my computer, and they work as advertised. Help please.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
VideoCapture stream1(0); //0 is the id of video device.0 if you have only one camera.
if (!stream1.isOpened())//check if video device has been initialised
cout << "cannot open camera";
//unconditional loop
while (true)
{
Mat cameraFrame;
stream1.read(cameraFrame);
imshow("cam", cameraFrame);
if (waitKey(0) >= 0)
break;
}
return 0;
}