您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 手势识别代码以及部分原理
ͼÏñ´¦Àí£¬Ä¿±êʶ±ð£¬Ä¿±ê¸ú×Ù£¬Ä£Ê½Ê¶±ðOpenCVѧϰ¡ª¡ªÀûÓÃHandVu½øÐÐÊÖ²¿¶¯×÷ʶ±ð·ÖÎö£¨×ª£©2011-04-0617:29:26|·ÖÀࣺĬÈÏ·ÖÀà|±êÇ©£ºopencvÊÖ²¿Ê¶±ð|¾Ù±¨|×ֺŶ©ÔÄ/***HandVu-alibraryforcomputervision-basedhandgesture*recognition.*Copyright(C)2004MathiasKolsch,matz@cs.ucsb.edu**Thisprogramisfreesoftware;youcanredistributeitand/or*modifyitunderthetermsoftheGNUGeneralPublicLicense*aspublishedbytheFreeSoftwareFoundation;eitherversion2*oftheLicense,or(atyouroption)anylaterversion.**Thisprogramisdistributedinthehopethatitwillbeuseful,*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe*GNUGeneralPublicLicenseformoredetails.**YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense*alongwiththisprogram;ifnot,writetotheFreeSoftware*Foundation,Inc.,59TemplePlace-Suite330,*Boston,MA02111-1307,USA.**$Id:hv_OpenCV.cpp,v1.152006/01/0321:44:15matzExp$**/#ifdefWIN32#includewindows.h#endif#includestdio.h#includecv.h#includehighgui.h#includectype.h#includetime.h#includeHandVu.hIplImage*capture_image=0;IplImage*display_image=0;boolasync_processing=false;intnum_async_bufs=30;IplImage*m_async_image=0;intm_async_bufID=-1;boolsync_display=true;CvPointorigin;intselect_object=0;intsel_area_left=0,sel_area_top=0,sel_area_right=0,sel_area_bottom=0;boolcorrect_distortion=false;voidOnMouse(intevent,intx,inty,int/*flags*/,void*/*params*/){if(!capture_image)return;if(capture_image-origin)y=capture_image-height-y;if(select_object){sel_area_left=MIN(x,origin.x);sel_area_top=MIN(y,origin.y);sel_area_right=sel_area_left+CV_IABS(x-origin.x);sel_area_bottom=sel_area_top+CV_IABS(y-origin.y);sel_area_left=MAX(sel_area_left,0);sel_area_top=MAX(sel_area_top,0);sel_area_right=MIN(sel_area_right,capture_image-width);sel_area_bottom=MIN(sel_area_bottom,capture_image-height);if(sel_area_right-sel_area_left0&&sel_area_bottom-sel_area_top0)hvSetDetectionArea(sel_area_left,sel_area_top,sel_area_right,sel_area_bottom);}switch(event){caseCV_EVENT_LBUTTONDOWN:origin=cvPoint(x,y);sel_area_left=sel_area_right=x;sel_area_top=sel_area_bottom=y;select_object=1;break;caseCV_EVENT_LBUTTONUP:select_object=0;break;}}voidshowFrame(IplImage*img,hvActionaction){if(action==HV_DROP_FRAME){//HandVurecommendsdroppingtheframeentirely//printf(HandVuFilter:droppingframe\n);return;}elseif(action==HV_SKIP_FRAME){//HandVurecommendsdisplayingtheframe,butnotdoinganyfurther//processingonit-keepgoing//printf(HandVuFilter:supposedtoskipframe\n);}elseif(action==HV_PROCESS_FRAME){//fullprocessingwasdoneandisrecommendedforfollowingsteps;//keepgoing//printf(HandVuFilter:processedframe\n);}else{assert(0);//unknownaction}hvStatestate;hvGetState(0,state);cvShowImage(HandVu,img);}voiddisplayCallback(IplImage*img,hvActionaction){if(sync_display){cvCopy(img,display_image);}else{showFrame(img,action);}}intmain(intargc,char**argv){CvCapture*capture=0;if(argc2){printf(youneedtospecifyaconductorfileasfirstargument\n);printf(forexample:../config/default.conductor\n);return-1;}stringconductor_fname(argv[1]);//ÉùÃ÷ÅäÖòÎÊýµÄ¶ÔÏóprintf(willloadconductorfromfile:\n%s\n,conductor_fname.c_str());//ÆÁÏÔÌáʾ/*ÊÇ·ñÉ趨Ìض¨µÄÉãÏñÍ·£¬²¢³õʼ»¯ÉãÏñÍ·*/if(argc==2||argc==3){intnum=0;if(argc==3){num=atoi(argv[2]);}capture=cvCaptureFromCAM(num);if(!capture){capture=cvCaptureFromAVI(argv[2]);}}if(!capture){fprintf(stderr,CouldnotinitializecapturingthroughOpenCV.\n);return-1;}/*ÆÁÏÔÌáʾ*/printf(Hotkeys:\n\tESC-quittheprogram\n\tr-restartthetracking\n\t0-3-settheoverlay(verbosity)level\nusethemousetoselecttheinitialdetectionarea\n);//É趨²É¼¯Í¼Ïñ´óСintp=0;//accordingtodocs,thesecallsdon'tworkinOpenCVbeta4yetp=cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH,640);p=cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT,480);//»ñÈ¡Ò»Ö¡capture_image=cvQueryFrame(capture);if(!capture_image){fprintf(stderr,CouldnotretrieveimagethroughOpenCV.\n);return-1;}/*allocateallthebuffers*/CvSizesize=cvGetSize(capture_image);hvInitialize(size.width,size.height);//³õʼ»¯Òª·ÖÎöµÄͼÏñ´óСhvLoadConductor(conductor_fname);//×°ÔزÎÊýhvStartRecognition();//¿ªÊ¼Ê¶±ðhvSetOverlayLevel(2);//ÉèÖÃʶ±ðµÄ¸²¸ÇÇø¼¶±ð/*ÉèÖÃͬ²½£¯Ò첽ʶ±ð*/if(async_processing){hvAsyncSetup(num_async_bufs,displayCallback);if(sync_display)display_image=cvCloneImage(capture_image);}/*ÉèÖÃÊó±êʼþµÄ»Øµ÷²ÎÊý*/cvSetMouseCallback(HandVu,OnMouse);/*ÉèÖô°¿Ú*/intsuccess=cvNamedWindow(HandVu,1);if(success!=1){printf(can'topenwindow-didyoucompileOpenCVwithhighguisupport?);return-1;}fprintf(stderr,initializedhighgui\n);hvStartGestureServer(1394,10);for(;;){intc;if(async_processing){//asynchronousprocessinginHandVuif(sync_display)cvShowImage(HandVu,display_image);//-------mainlibrarycall---------hvAsyncGetImageBuffer(&m_async_image,&m_async_bufID);cvCopy(capture_image,m_async_image);hvAsyncProcessFrame(m_async_bufID);//-------}else{//Inthecondition´ÓÕâ¸ö·ÖÖ§×ß//synchronousprocessinginHandVu//-------mainlibrarycall---------hvActionaction=HV_INVALID_ACTION;action=hvProcessFrame(capture_image);//-------showFrame(cap
本文标题:手势识别代码以及部分原理
链接地址:https://www.777doc.com/doc-4544228 .html