[Opencv learning] camera acquisition, video recording, and screenshot gadgets

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.