//// Main. CPP // opencv3 // created by PKU on 14-9-16. // copyright (c) 2014 PKU. all rights reserved. // # include <opencv2/opencv. HPP> using namespace CV; using namespace STD; int main () {cvcapture * capture = cvcapturefromcam (-1); cvvideowriter * Video = NULL; iplimage * frame = NULL; int N; if (! Capture) // if the camera cannot be opened, a warning is given {cout <"can not open the camera. "<Endl; Return-1;} else {frame = cvqueryframe (capture); // first obtain a frame of Video = cvcreatevideowriter (" camera. avi ", cv_fourcc ('M', 'J', 'P', 'G'), 32, cvsize (frame-> width, frame-> height )); // create a cvvideowriter object and allocate space. // The saved file name is camera. avi: the encoding should be selected when the program is running. The size is the video size of the camera, and the frame frequency is 32 If (video) // If the cvvideowriter object can be created, it indicates that {cout <"videowriter has created is successful. "<Endl;} CV Namedwindow ("camera video", 1); // create a window while (1) {frame = cvqueryframe (capture); // obtain a frame from cvcapture if (! Frame) {cout <"can not get frame from the capture. "<Endl; break;} n = cvwriteframe (video, frame); // determines whether the write is successful. If 1 is returned, the write is successful. <n <Endl; cvshowimage ("camera video", frame); // If (cvwaitkey (1)> 0) break of the image displaying the video content; // other keyboard responses are available, exit} cvreleasevideowriter (& Video); cvreleasecapture (& capture); cvdestroywindow ("camera video");} return 0 ;}
Opencv open the camera to get the video program