Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
/** =================================================== ========================================================== =========** Filename: videocapture. CPP ** Description: a program of capture the video camrea this program can be used for camera acquisition, video recording (Key R) and (left mouse button) ** version: 1.0 * created: 02/02/2009 09:48:27 am * revision: none * Compiler: GCC ** Author: futuredaemon (BUPT), gnuhpc@gmail.com * company: bupt_united ** ========================================== ================ =============================================================== */# Include "CV. H "# include" highgui. H "# include iplimage * frame = 0; void mousehandler (INT event, int X, int y, int flags, void * PARAM); int main (INT argc, char ** argv) {cvcapture * capture = 0; int flag = 1; int iscolor = 1; int FPS = 15; int framew = 320; int frameh = 240; int press = 0; cvvideowriter * Writer = cvcreatevideowriter ("out. avi ", cv_fourcc ('D', 'I', 'V', 'x'), FPS, c Vsize (framew, frameh), iscolor); If (argc = 1 | (argc = 2 & strlen (argv [1]) = 1 & isdigit (argv [1] [0]) {capture = cvcapturefromcam (-1);} else if (argc = 2) {capture = cvcapturefromavi (argv [1]);} If (! Capture) {fprintf (stderr, "cocould not initialize capturing... /n "); Return-1;} cvnamedwindow (" Main ", 0); cvsetmousecallback (" Main ", mousehandler, null); (;;) {frame = cvqueryframe (capture); If (! Frame) {break;} If (flag = 0) {cvwriteframe (writer, frame);} cvshowimage ("Main", frame ); if (Press = cvwaitkey (20) = 'R') {If (flag = 1) {printf ("Starting record the video! /N "); flag = 0;} else {printf (" stop the recording! /N "); flag = 1 ;}} else if (Press = 27) {break ;}} cvreleasecapture (& capture); cvdestroywindow (" Main "); return 0;} void mousehandler (INT event, int X, int y, int flags, void * PARAM) {time_t curtime = Time (null ); char * Date = ctime (& curtime); Switch (event) {Case cv_event_lbuttondown: printf ("Get a picrure named % s/n", date + 11); sprintf (date, "2.16s.jpg", date + 11); cvsaveimage (date, frame); break; default: break ;}}
Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/