资源简介

使用OpenNI类库实现。在Kinect的支持下,通过对手势的识别和跟踪,来代替鼠标移动和点击。该程序使人能够徒手控制PC,如用Firefox浏览网页,玩水果忍者等等。此程序为非MFC版本。开发教程:http://blog.csdn.net/chenxin_130/article/details/6693390

资源截图

代码片段和文件信息

/*************************************
Kinect Skeleton
Author: Xin Chen 2011
Blog:http://blog.csdn.net/chenxin_130
**************************************/
#include “AppMessage.h“
#include 

/*
#pragma comment (lib“user32“)
*/

//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-10-20 22:47  KinectMouseControl\
     目录           0  2011-10-20 22:48  KinectMouseControl\KinectMouseControl\
     文件        1945  2011-10-20 22:44  KinectMouseControl\KinectMouseControl\AppMessage.cpp
     文件         443  2011-10-20 22:41  KinectMouseControl\KinectMouseControl\AppMessage.h
     文件         219  2011-10-20 22:41  KinectMouseControl\KinectMouseControl\KinectGesture.h
     文件        6242  2011-10-20 22:44  KinectMouseControl\KinectMouseControl\KinectGestureMain.cpp
     文件        4166  2011-10-19 20:32  KinectMouseControl\KinectMouseControl\KinectMouseControl.vcproj
     文件         920  2011-10-19 20:26  KinectMouseControl\KinectMouseControl.sln
     文件       16896  2011-10-20 22:47  KinectMouseControl\KinectMouseControl.suo
     目录           0  2011-10-20 22:48  KinectMouseControl\Release\
     文件       17920  2011-10-20 22:44  KinectMouseControl\Release\KinectMouseControl.exe

评论

共有 条评论