kinect连接unity文献翻译(二)

文中的“姿势”可根据需要换成“动作”。

原文

 

How to Use Gestures or Create Your Own Gestures

There are two ways to add gesture detection to your Unity-project. The first one is easier and utilizes the

KinectManager a component of the KinectController-game object in the example scenes. It has a list-

setting called “Player Common Gestures”. Here you can put the gestures that will be detected for each user

during the entire game, or the gestures that you need to test quickly.

The second way is to specify user or scene-specific gestures programmatically. You need to create a script

that implements KinectGestures.GestureListenerInterface and use its methods for gesture initialization and

gesture detection processing. As an example, look at the KinectScripts/Samples/SimpleGestureListener.cs-

script. Here is a short description of the GestureListenerInterface’s  methods:

·

·

UserDetected() invoked when a new user is detected. It can be used to start the gesture detection.

UserLost() invoked when a user is lost. It can be used to clean up or free the allocated resources.

You don’t need to stop explicitly the detection of gestures added in UserDetected().

GestureInProgress() - invoked when a gesture start is detected, but the gesture is not yet completed

or cancelled. Can be used to report the gesture progress or to process continuous gestures (that

never get completed), like for instance zooming, leaning, walking or running.

GestureCompleted() - invoked when the gesture is completed. You can process the gesture

detection here, and decide whether to reset the gesture (i.e. restart its detection) or not.

GestureCancelled() - invoked, if the gesture gets cancelled. The gesture gets automatically cancelled,

when it is not completed within the allowed time frame. You can decide, whether to reset the

gesture (i.e. restart its detection) or not.

Currently Recognized Gestures

The following gestures are currently recognized:

·

RaiseRightHand / RaiseLeftHand left or right hand is raised above the shoulder and the user stays

in this pose for 1.0 seconds (pose).

Psi both hands are raised above the shoulder and the user stays in this pose for 1.0 seconds (pose).

Tpose the hands are to the sides, perpendicular to the body (T-pose), for 1.0 seconds (pose).

Stop right hand is down and left hand is slightly to the side, but below the waist, or left hand is

down and right hand is slightly to the side, but below the waist (pose).

Wave right hand is waved left and then back right, or left hand is waved right and then back left.

SwipeLeft right hand swipes left.

SwipeRight left hand swipes right.

SwipeUp / SwipeDown swipe up or down with the left or right hand

ZoomIn - left and right hands are to the front and put together at the beginning, then the hands

move apart in different directions (continuous gesture, reports zoom-factor).

ZoomOut - left and right hands are to the front and at least 0.7 meter apart at the beginning, then

the hands move closer to each other (continuous gesture, reports zoom-factor)

Wheel - left and right hands are to the front and shoulder size apart at the beginning, then the hands

keep the distance and move as if they turn an imaginary wheel counter clockwise, which returns

positive angle, or clockwise - negative angle (continuous gesture, reports wheel angle).

Jump the hip center gets at least 10 cm above its last position within 1.5 seconds.

Squat - the hip center gets at least 10 cm below its last position within 1.5 seconds

Push push forward with the left or right hand within 1.5 seconds.

Pull - pull backward with the left or right hand within 1.5 seconds.

ShoulderLeftFront move the left shoulder to the front.

ShoulderRightFront move the right shoulder to the front.

LeanLeft - lean left with the whole body (continuous gesture, reports lean angle).

LeanRight lean right with the whole body (continuous gesture, reports lean angle).

KickLeft move the left foot to the front.

KickRight move the right foot to the front.

Run checks if the left knee is at least 10cm above the right knee, then if the right knee is at least

10 cm above the left knee, then back to the left knee check (continuous gesture, reports progress).

·

·

·

How to Add Your Own Gestures

Here are some hints on how to add your own gestures to the Kinect gesture-detection procedure. You need

some C# coding skills and a bit of basic understanding on how the sensor works. It reports the 3d-coordnates

of the tracked body parts in the Kinect coordinate system, in meters.

To add detection of custom gesture, open Assets/KinectScripts/KinectGestures.cs. Then:

1.    Find the Gestures-enum. First you need to add the name of your gesture at the end of this enum.

2.    Find the CheckForGesture()-function. There is a long switch() there, and its cases process the

detection of each gesture, defined in the Gestures-enum. You need to add a case for your gesture at

the end of this switch(), near the end of the script. There you will implement the gesture detection.

3.    For an example on how to do that, look at the processing of some simple gestures, like

RaiseLeftHand, RaiseRightHand, SwipeLeft or SwipeRight.

4.    As you see, each gesture has its own internal switch() to check and change the gesture’s current

state. Each gesture is like a state machine with numerical states (0, 1, 2, 3…). Its current state along

with other data, is stored in an internal structure of type GestureData. This data-structure is created

for each gesture that needs to be detected in the scene.

5.    The initial state of each gesture is 0. At this state, the code needs to detect if the gesture is starting

or not. To do this, it checks and stores the position of a joint, usually the left or right hand. If the

joint position is suitable for a gesture start, it increments the state. At the next state, it checks if the

joint has reached the needed position (or distance from the previous position), usually within a time

interval, let’s say within 1.0 - 1.5 seconds.

6.    If the joint has reached its target position (or distance) within the time interval, the gesture is

considered completed. Otherwise - it is considered cancelled. Then, the gesture state may be reset

back to 0 and the gesture-detection procedure will start again.


To add detection of your own gestures, first try to understand how relatively simple gestures, like RaiseHand

or Swipes, work. Then find a gesture similar to the one you need. Copy and modify its code, as to your needs.

Update-v2.8: The KinectGestures-class is an extendable component now. This means you have to add it to

the scenes, where you need gesture recognition. You can also extend the class, when you want to add

recognition of your own gestures. This will prevent overwriting your code, when the Kinect-scripts are

updated after a new version release.

Support, Examples and Feedback

Web:  http://rfilkov.com/2015/01/25/kinect-v2-tips-tricks-examples/

E-mail:  rumen.filkov@gmail.com

Twitter: roumenf


译文

怎样使用姿势或者创建你自己的姿势


有两种方法在你的unity项目中加入姿势检测,第一种更容易一些,是


运用KinectManager--是在示例场景中 KinectController游戏对象的一


个部件,它有一个设置列表叫“Player Common Gestures”,现在你可


以加入姿势,会被游戏中的每一个用户所检测到的姿势,或者是你需要


快速测试的姿势。


第二种是以编程的方式对特殊用户或者场景专属姿势才有的,你需要创


建一个脚本,实现 KinectGestures.GestureListenerInterface 接口


并且使用其姿势初始化的方法和姿势检测程序。作为例子看 


KinectScripts/Samples/SimpleGestureListener.cs-
script这个脚本文件。
以下是GestureListenerInterface接口的一些方法


UserDetected()当一个新的用户被检测到的时候发出询问,他可以用


来做姿势检测的开始。 
  UserLost()当一个用户消失的时候发出提醒,它可以用来释放分配的


资源,在这个方法中你不需要主动停止姿势检测。
  GestureInProgress() 当检测到一个开始姿势但该姿势还没有完成或


取消的时候发出提醒,可用于报告手势进度或处理连续手势(尚未完成


的),例如像伸展,倾斜,走或者跑等动作。
  GestureCompleted()当姿势完成时发出提醒,在这里你可以处理姿势


检测,并且决定是否重置姿势。
  GestureCancelled()如果姿势取消发出提醒,当姿势没有在允许的时


间框架内完成会自动取消。你可以决定是否重置姿势。
  


  目前可识别的手势


以下姿势是目前可识别的姿势


举起左手或者右手,左手或者右手举起超过肩膀并且维持这个姿势一秒



双手均举过肩膀并且维持这个姿势一秒。
T姿势,两只手水平伸展在身体两侧,并且维持这个姿势一秒。
停止姿势,右手向下,左手稍向一侧,但在腰部以下。或者左右手交换
左右挥动,右手或者左手左右挥动。
向左挥动,右手向左挥动。
向右挥动,左手向右挥动。
上下挥动,左手或者右手向下挥动。
放大,左右手在开始时放在一起在前面,然后双手在不同的方向上分开


(继续姿势,报告缩放参数。)
缩小(这里原文是大写的o,意为焦距调整,但是根据姿势个人觉得应


该是缩小,具体等到测试的时候试一下。)左右手在开始时是向前的,


至少相隔0.7米,然后双手互相靠拢。(继续姿势,报告缩放参数。)


转,左右手在开始时是在前面和肩分开的,然后手保持距离并移动,好


像在转动一个想象中的轮子一般,正角是顺时针转动,负角是逆时针转


动。(继续姿势,报告旋转角度。)
跳跃,1.5秒内胯部高于它的初始位置至少10cm。
蹲,1.5秒内胯部低于它的初始位置至少10cm。
推,1.5秒内胯部前于它的初始位置至少10cm。
拉,1.5秒内胯部后于它的初始位置至少10cm。
左肩向前。
右肩向前。
向左倾斜,整个身体向左倾斜(继续姿势,报告倾斜角度。)。
向右倾斜,整个身体向右倾斜(继续姿势,报告倾斜角度。)。
左脚向前
右脚向前
跑,检测左膝盖是否比右膝盖向前至少10cm,之后检测右膝盖是否比左


膝盖向前至少10cm,如果是回退到检测左膝盖,(继续姿势,报告进程



怎样加入你自己的姿势



这里有一些提示关于怎样在Kinect姿势检测程序中加入你自己的姿势。


你需要一些c#程序技术和一点儿传感器工作的姿势。它报告了Kinect坐


标在跟踪身体部位的3D坐标以米为单位。




为了加入用户姿势检测,打Assets/KinectScripts/KinectGestures.cs
然后:
1.找到姿势的枚举列表(Gestures-enum),首先你需要在枚举列表的


最后加入你的姿势名称。
2.找到CheckForGesture()方法,这有一个 long switch() ,它的案例


处理每个姿势的检测,定义在Gestures-enum里。你需要在switch()


末尾为你的姿势添加一个案例,挨着脚本末尾,然后你就完成了姿势的


检测。
3.举个怎样做的例子,注意一些简单姿势的处理过程,像举起左手或者


右手,向左挥动或者向右挥动。
4.如你所见,每个姿势有其自己的内部switch()来检查或者改变姿势


的当前状态。每一个姿势就像一个状态机器有着数字化的状态(0, 1, 


2, 3…)它的当前状态还伴随着其他数据,储存在一个内部GestureData


类型的结构中,这种数据结构是为每个需要在场景里检测的姿势而创建


的。
5.每个姿势的初始状态是0,在这个状态,代码需要检测出姿势是否开


始,它检测并储存一个关节的位置,经常是左手或者右手,如果关节符


合开始姿势,他将递增状态。在下一个状态,它检测关节是否重新到达


需要的位置(或者与之前的位置有一小段距离),通常是在一段间隔时


间内,1-1.5秒。
6.如果在间隔时间内关节已经到了他的目标位置(或者与之前的位置有


一小段距离),这个动作就被认为是完成了。否则,就被认为是取消。


之后,这个姿势的状态可能被重置回0并且姿势检测程序重启。


为了增加你自己姿势的检测,首先试着去理解简单的姿势像拒收或者挥


手是怎样相对工作的。之后找到一个一个与你需要的姿势类似的的姿势


。根据你的需要复制并修改他的代码。




v2.8的更新:KinectGestures类现在是一个可拓展的部件。这意味着你


不得不将他加入到你的姿势需要被识别的场景中去,你也可以拓展这个


类,当你想要为你的姿势添加识别的时候。这将防止你的代码当Kinect


脚本在新版本更新后被重写。



  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值