【Unity】使用KinectManager的一般流程

来源:互联网 发布:管家婆软件工贸版 编辑:程序博客网 时间:2024/05/17 01:38

想要从Kinect读取到数据,然后使用数据,通常是以下流程:

using UnityEngine;using System.Collections;/// <summary>/// 使用KinectManager的一般流程。/// </summary>public class UseKinectManager : MonoBehaviour {    KinectManager _manager;    // Use this for initialization    void Start () {    }    // Update is called once per frame    void Update () {        if (_manager == null) {            _manager = KinectManager.Instance;        }        // 是否初始化完成        if (_manager && _manager.IsInitialized()) {             // 是否人物被检测到            if (_manager.IsUserDetected()) {                // 获取用户ID                long userId = _manager.GetPrimaryUserID();                // 获取目标关节点的索引(以左手为例)                int jointIndex = (int)KinectInterop.JointType.HandLeft;                // 判断目标关节点是否被追踪                if (_manager.IsJointTracked(userId, jointIndex)) {                    // 获取目标关节点在Kinect坐标系的位置                    Vector3 leftHandPos = _manager.GetJointKinectPosition(userId, jointIndex);                    // todo:其他逻辑                    // ...                    Debug.Log(leftHandPos);                    // ...                }            }        }    }}
0 0
原创粉丝点击