I want to capture video from webcam, but window disappears after capturing one frame
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;
}
show your code, please. also if there are any messages, those, too !
@berak This is the link (https://gist.github.com/kartikeygupta/69b675d96829f52880dcb952c7a544c5 (https://gist.github.com/kartikeygupta...)).
It just displays one still image and that's it. The guy who wrote the code promised that it'll display a live, moving video stream.