First, create a new source program file for. CPP, for example,
Gedit Test.cpp
Add the following program to the file:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace CV;
int main (int argc, char** argv) {
Cvnamedwindow ("video");
cvcapture* capture = cvcreatecameracapture (1);
iplimage* frame;
while (1) {
frame = cvqueryframe (capture);
if (!frame) break;
Cvshowimage ("video", frame);
char C = cvwaitkey (+);
if (c==27) break;
}
Cvreleasecapture (&capture);
Cvdestroywindow ("video");
return 0;
}
Save exit. The compilation chain is delivered as an executable file.
g++ test.cpp-o test-i/usr/local/include/opencv-i/usr/local/include/opencv2-l/usr/local/lib/*.so
Insert Camera, run program
./test
Done.
cvcreatecameracapture (), initialize get video from camera
cvcapture* cvcreatecameracapture (int index);
If there is only one camera, the parameter value takes 0. When the parameter is set to-1, OpenCV opens a window for the user to select the camera to use.
cvqueryframe () fetches a frame from the camera or file and then extracts and returns the frame. The returned image can not be released or modified by the user.
iplimage* Cvqueryframe (cvcapture* capture);
Cvshowimage ()that is used to display the image in the specified window.
void Cvshowimage (const char* name, const cvarr* image);