# include & lt; Opencv2/opencv. Hpp>
#include
Using the namespace CV;
using namespace std;
String name="I";
Int main ()
{
VideoCapture capture; Video//statement read in class
The capture. Open (0);//read in from the camera video 0 means from the camera to read
if (! The capture. IsOpened ())//to judge whether to open the camera
{
Cout & lt; <"Can not open";
cin.get();
return -1;
}
NamedWindow (name);
While (1) {
Mat cap;//define a Mat variable, used to store each frame image
The capture & gt;> Cap;//read the current frame
if (! Cap. Empty ())//whether the current frame capture success * * this is a very important step
Imshow (name, cap);//if the current frame capture success, according to
The else
Cout & lt; <"Can not";
WaitKey (30);//30 milliseconds latency
}
Return 0;
}
CodePudding user response:
# include "CV. H"
# include "highgui. H"
Int main (int arg c, char * * argv) {
CvNamedWindow (" OpenCVideoWindows ");
CvCapture * capture=cvCreateCameraCapture (0);
IplImage * frame;
While (1) {
Frame=cvQueryFrame (capture);
if(! Frame) break;
CvShowImage (" win ", frame);
Char c=cvWaitKey (50);
If (c==27) break;
}
CvReleaseCapture (& amp; The capture);
CvDestroyWindow (" OpenCVideoWindows ");
Return 0;
}
CodePudding user response:
# include "CV. H"
# include "highgui. H"
Int main (int arg c, char * * argv) {
CvNamedWindow (" OpenCVideoWindows ");
CvCapture * capture=cvCreateCameraCapture (0);
IplImage * frame;
While (1) {
Frame=cvQueryFrame (capture);
if(! Frame) break;
CvShowImage (" OpenCVideoWindows, "frame);
Char c=cvWaitKey (30);
If (c==27) break;
}
CvReleaseCapture (& amp; The capture);
CvDestroyWindow (" OpenCVideoWindows ");
Return 0;
}