我是靠谱客的博主 害怕钻石,最近开发中收集的这篇文章主要介绍openni+nite体感鼠标模拟,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

        最近在学openni,所以做一个体感鼠标练练。主要功能,就是一只手负责定位鼠标在屏幕的位置,一只手进行点击或者其他的操作,并且可以通过一些特定方式进行左右手切换等操作。

第一步就是设置鼠标以及屏幕等的参数,为了方便,我们使用ini文档进行配置,主要包含:屏幕尺寸,帧数,左右击键等配置。

[Setting]
ScreenRes_X=1440
ScreenRex_Y=900
nFPS=30
LeftClickDownSpeed=600
LeftClickUpSpeed=600
RightClickSpeed=600
PushSpeed=1000
MouseMove_Xsize=600
MouseMove_Ysize=400
angle=30
Touch=250
off_ZSpeed=150
on_ZSpeed=130
nSteadyDelayTime_MouseClick=1000
fSteadyMaxVelocity_MouseClick=0.01
fNotSteadyMinVelocity_MouseClick=1.000

配置好之后,利用下面函数进行配置文件里的数据读取操作。

void GetSettingValue()
{
ScreenRes_X=GetPrivateProfileInt(L"settings",L"ScreenRes_X",1440,L".\settings.ini");
ScreenRes_Y=GetPrivateProfileInt(L"settings",L"ScreenRes_Y",900,L".\settings.ini");
MouseMove_Xsize=GetPrivateProfileInt(L"settings",L"MouseMove_Xsize",600,L".\settings.ini");
MouseMove_Ysize=GetPrivateProfileInt(L"settings",L"MouseMove_Ysize",400,L".\settings.ini");
nFPS=GetPrivateProfileInt(L"settings",L"nFPS",30,L".\settings.ini");
PushSpeed=GetPrivateProfileInt(L"settings",L"PushSpeed",1000,L".\settings.ini");
RightClickSpeed=GetPrivateProfileInt(L"settings",L"RightClickSpeed",1000,L".\settings.ini");
LeftClickDownSpeed=GetPrivateProfileInt(L"settings",L"LeftClickDownSpeed",600,L".\settings.ini");
LeftClickUpSpeed=GetPrivateProfileInt(L"settings",L"LeftClickUpSpeed",600,L".\settings.ini");
angle=GetPrivateProfileInt(L"settings",L"angle",30,L".\settings.ini");
Touch=GetPrivateProfileInt(L"settings",L"Touch",250,L".\settings.ini");
off_ZSpeed=GetPrivateProfileInt(L"settings",L"off_ZSpeed",150,L".\settings.ini");
on_ZSpeed=GetPrivateProfileInt(L"settings",L"on_ZSpeed",20,L".\settings.ini");
}
接下来对整个程序中需要使用的一些基本生产节点和上下文结构进行初步的初始化。

void InitPS()
{
GetSettingValue();
XnStatus eResult=XN_STATUS_OK;
xn::EnumerationErrors errors;
eResult=g_Context.Init();
CHECK_RC(eResult,"context initialize");
eResult=g_Context.InitFromXmlFile("Sample-Tracking.xml");
CHECK_RC(eResult,"xml open");
g_DepthGenerator.Create(g_Context);
g_UserGenerator.Create(g_Context);
g_GestureGenerator.Create(g_Context);
g_GestureGenerator.AddGesture("Wave",NULL);
XnCallbackHandle hHandle;
g_GestureGenerator.RegisterGestureCallbacks(GestureRecognized,GestureProgress,NULL,hHandle);
XnCallbackHandle hUserCB;
g_UserGenerator.RegisterUserCallbacks(NewUser,LostUser,NULL,hUserCB);
SkeletonCapability mSC=NULL;
mSC=g_UserGenerator.GetSkeletonCap();
mSC.SetSkeletonProfile(XN_SKEL_PROFILE_UPPER);
XnCallbackHandle hCalibCB;
mSC.RegisterCalibrationCallbacks(CalibrationStart,CalibrationEnd,&g_UserGenerator,hCalibCB);
mSC.SetSmoothing(0.1f);
XnCallbackHandle hPoseCB;
g_UserGenerator.GetPoseDetectionCap().RegisterToPoseCallbacks(PoseDetected,NULL,&g_UserGenerator,hPoseCB);
g_Context.StartGeneratingAll();
HANDLE hThread_ReadDepthMap=NULL;
hThread_ReadDepthMap=CreateThread(0,0,ReadDepthMapThread,0,0,0);
if (!hThread_ReadDepthMap)
{
printf("thread create failed!");
return;
}
}
初始化所有用到的资源,并进行某些生产节点的回调函数注册。

void XN_CALLBACK_TYPE GestureRecognized(xn::GestureGenerator &generator,const XnChar *strGesture,const XnPoint3D *pIDposition,const XnPoint3D *pEndPosition,void *pCookie)
{
printf("GRecognized");
}
void XN_CALLBACK_TYPE GestureProgress(xn::GestureGenerator &generator,const XnChar *strGesture,const XnPoint3D *pPOsition,XnFloat fProgress,void *pCookie)
{
printf("GProgress");
}
void XN_CALLBACK_TYPE NewUser(xn::UserGenerator &generator,XnUserID user,void* pCookie)
{
printf("NewUser:%dn",user);
generator.GetPoseDetectionCap().StartPoseDetection("Psi",user);
}
void XN_CALLBACK_TYPE LostUser(xn::UserGenerator &generator,XnUserID user,void* pCookie)
{
printf("LostUser:%dn",user);
}
void XN_CALLBACK_TYPE CalibrationStart(xn::SkeletonCapability& skeleton,XnUserID user,void* pCookie)
{
printf("Calibration start for user:%dn",user);
}
void XN_CALLBACK_TYPE CalibrationEnd(xn::SkeletonCapability& skeleton,XnUserID user,XnBool bSuccess,void* pCookie)
{
printf("Calibration complete for user:%dn",user);
if (bSuccess)
{
printf("Calibration success");
skeleton.StartTracking(user);
}
else
{
printf("Calibration failure");
((xn::UserGenerator*)pCookie)->GetPoseDetectionCap().StartPoseDetection("Psi",user);
}
}
void XN_CALLBACK_TYPE PoseDetected(xn::PoseDetectionCapability& poseDetection,const XnChar* strPose,XnUserID user,void* pCookie)
{
printf("Pose %s,detected for user%d",strPose,user);
((xn::UserGenerator*)pCookie)->GetSkeletonCap().RequestCalibration(user,FALSE);
poseDetection.StopPoseDetection(user);
}
这样,我们就完成了,第一步,前期的一些资源的获取工作,后面我们一步一步利用这些资源进行手势的控制。



最后

以上就是害怕钻石为你收集整理的openni+nite体感鼠标模拟的全部内容,希望文章能够帮你解决openni+nite体感鼠标模拟所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部