Unity Kinect添加自定义姿势识别
Unity Kinect添加自定义姿势识别前言自定义姿势识别添加自定义姿势枚举添加自定义姿势的逻辑创建监听脚本并挂载添加动作监听前言文中使用插件为KinectForUnity百度云 https://pan.baidu.com/s/1dAEhJgXbXL0_ZtQdWd-ATA提取码 3nsv自定义姿势识别添加自定义姿势枚举打开KinectGestures脚本,找到Gestures枚举。添加自己的动
前言
文中使用插件为KinectForUnity
百度云 https://pan.baidu.com/s/1dAEhJgXbXL0_ZtQdWd-ATA
提取码 3nsv
如要支持Unity2019或更高需自行升级插件请相关参考 https://blog.csdn.net/a71468293a/article/details/117084439
自定义姿势识别
添加自定义姿势枚举
打开KinectGestures脚本,找到Gestures枚举。
添加自己的动作,本文为MoveLeft。
添加自定义姿势的逻辑
找到CheckForGesture方法,在switch中增加以下代码
case Gestures.MoveLeft:
switch (gestureData.state)
{
case 0: // gesture detection - phase 1
//判断保持直立
if (jointsTracked[shoulderCenterIndex] && jointsTracked[hipCenterIndex] &&
Mathf.Abs(jointsPos[shoulderCenterIndex].x - jointsPos[hipCenterIndex].x) < 0.1f )
{
SetGestureJoint(ref gestureData, timestamp, shoulderCenterIndex, jointsPos[shoulderCenterIndex]);
gestureData.progress = 0.5f;
}
break;
case 1:
// gesture phase 2 = complete 手势阶段2=完成
//timestamp 当前时间 gestureData 为记录参数
//gestureData.timestamp 记录时间
//当前时间-记录时间 < 1.5s 进行判断,如果超出时间则动作失败
if ((timestamp - gestureData.timestamp) < 1.5f)
{
//jointsPos[shoulderCenterIndex].x 是最新数据
//gestureData.jointPos.x 是1.5s之前的数据
bool isInPose = jointsTracked[shoulderCenterIndex] &&
//(jointsPos[shoulderCenterIndex].x - gestureData.jointPos.x) > 0.2f &&
(gestureData.jointPos.x - jointsPos[shoulderCenterIndex].x) > 0.2f &&
Mathf.Abs(jointsPos[shoulderCenterIndex].y - gestureData.jointPos.y) < 0.1f;
if (isInPose)
{
Vector3 jointPos = jointsPos[gestureData.joint];
CheckPoseComplete(ref gestureData, timestamp, jointPos, isInPose, 0f);
}
}
else
{
// cancel the gesture 取消手势
SetGestureCancelled(ref gestureData);
}
break;
}
break;
创建监听脚本并挂载
创建GestureController脚本,使其继承自GestureListenerInterface。
在KinectManager预制体上挂载KinectGestures脚本与GestureController脚本。
添加动作监听
在GestureController中的GestureCompleted方法内判断动作是否完成。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)