资源描述:
《opencv中响应鼠标消息》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、OpenCV中响应鼠标消息程序代码如下:#include#include#includevoidonMouse(intevent,intx,inty,intflags,void*param);intmain(intargc,char**argv){CvCapture*capture;IplImage*frame;capture=cvCaptureFromCAM(0);cvNamedWindow("Webcam",0);cvSetMouseCallback("Webcam",onMouse,NULL);
2、while(true){frame=cvQueryFrame(capture);cvShowImage("Webcam",frame);if(cvWaitKey(10)>=0){break;}otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganizat
3、ion,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand}cvReleaseCapture(&c
4、apture);cvDestroyWindow("Webcam");return0;}voidonMouse(intEvent,intx,inty,intflags,void*param){printf("(%d,%d)",x,y);printf("TheEventis:%d",Event);printf("Theflagsis:%d",flags);printf("Theparamis:%d",param);}这边每当鼠标在视讯窗口接口点击一下的时候,都会有固定三个动作1.点击(Click)2.放开(Down)3.滑动(move)因此,程序执行鼠
5、标在点击的时候onMouse()都会连续跑三次,代表鼠标在点击的时候连续的三个事件,而voidonMouse(intEvent,intx,inty,intflags,void*param)子程序的自变量分成四个不同的分类,分别为1.事件回传代号(intEvent)2.坐标(intx,inty)3.flags代号(intflags)4.Mouse事件的代号名称(param)Event代表的是鼠标回传的事件号码,每当鼠标有动作,Event就会回传一个整数讯息到onMouse(),也顺便回传鼠标移动的坐标,flags代表的是拖曳事件,param则是自己定义o
6、nMouse()事件的ID,就跟GUI接口的窗口接口ID一样(cvGetWindowHandle()),不过这边是自己给的编号,而窗口接口的ID则是系统自动随机分配的ID,而鼠标事件的执行可以细分的分类为Event:#defineCV_EVENT_MOUSEMOVE0 滑动#defineCV_EVENT_LBUTTONDOWN1 左键点击#defineCV_EVENT_RBUTTONDOWN2 右键点击#defineCV_EVENT_MBUTTONDOWN3 中键点
7、击#defineCV_EVENT_LBUTTONUP4 otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofth
8、elongMarch,hehasbeentheNorthwestOfficeoftheFede