资源简介

使用OpenNI类库实现。在Kinect的支持下,通过对手势的识别和跟踪,来代替鼠标移动和点击。该程序使人能够徒手控制PC,如用Firefox浏览网页,玩水果忍者等等。

资源截图

代码片段和文件信息

/*************************************
KinectHandGesture - Mouse Control
Author: Xin Chen 2011.8
Blog: http://blog.csdn.net/chenxin_130
*************************************/

#include “stdafx.h“
#include “AppMessage.h“
#include “mmsystem.h“

#pragma comment(lib“winmm.lib“)

//Location and move angle last time for each userId(Hand Id)
CvPoint lastLocation[MAX_HAND_NUM];

int isHandTracking[MAX_HAND_NUM]={0};
int isClickDown=0;

void addTrackingId(int userId)
{
isHandTracking[userId]=1;
}

void removeTrackingId(int userId)
{
isHandTracking[userId]=0;
}

CvPoint getLastLocation(int userId)
{
return lastLocation[userId];
}

void messageHandler(CvPoint &location int userIdint flag)
{
//initialize the lastLocation from the location obtained by the first time
if(lastLocation[userId].x==0&&lastLocation[userId].y==0)
{
lastLocation[userId].x=location.x;
lastLocation[userId].y=location.y;
}
if(flag==REAL_MOUSE_CLICK)
{
if(!isClickDown)
{
mouse_event(MOUSEEVENTF_LEFTDOWN0000);
}
else {
mouse_event(MOUSEEVENTF_LEFTUP0000);
}
isClickDown=1-isClickDown;
}
else if(flag==REAL_MOUSE_MOVE)
{
int firstHandId=-1;
for(int i=0;i {
if(isHandTracking[i]!=0)
{
if(firstHandId==-1)
{
firstHandId=i;
break;
}
}
}
if(abs(location.x-lastLocation[userId].x)<5)
{
location.x=lastLocation[userId].x;
}
if(abs(location.y-lastLocation[userId].y)<5)
{
location.y=lastLocation[userId].y;
}

if(userId==firstHandId)
{
//mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE
//(location.x-320)*65536/640*2location.y*65536/480*200);//右手右方操控
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE
(location.x-160)*65536/640*2(location.y-120)*65536/480*200);
}
}
lastLocation[userId].x=location.x;
lastLocation[userId].y=location.y;

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-08-21 19:58  KinectMouse\
     文件        1997  2011-08-19 17:14  KinectMouse\AppMessage.cpp
     文件         472  2011-08-19 17:14  KinectMouse\AppMessage.h
     目录           0  2011-08-21 19:57  KinectMouse\Debug\
     文件         248  2011-08-18 13:17  KinectMouse\KinectGesture.h
     文件        6646  2011-08-19 17:15  KinectMouse\KinectGestureMain.cpp
     文件        2377  2011-08-18 13:17  KinectMouse\KinectHandGesture.cpp
     文件         753  2011-08-18 13:17  KinectMouse\KinectHandGesture.h
     文件        4468  2011-08-18 15:54  KinectMouse\KinectHandGesture.rc
     文件        5925  2011-08-21 16:20  KinectMouse\KinectHandGesture.vcproj
     文件        2978  2011-08-18 13:17  KinectMouse\KinectHandGestureDlg.cpp
     文件         873  2011-08-18 13:17  KinectMouse\KinectHandGestureDlg.h
     文件         899  2011-08-21 16:20  KinectMouse\KinectMouse.sln
     目录           0  2011-08-21 19:55  KinectMouse\res\
     文件       21630  2005-08-12 16:37  KinectMouse\res\KinectHandGesture.ico
     文件         408  2011-07-27 14:29  KinectMouse\res\KinectHandGesture.rc2
     文件         551  2011-08-18 13:20  KinectMouse\resource.h
     文件         217  2011-07-27 14:29  KinectMouse\stdafx.cpp
     文件        2809  2011-08-18 13:16  KinectMouse\stdafx.h

评论

共有 条评论