using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UseKinectManager : MonoBehaviour {
public RawImage kinectImg;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
bool isInit = KinectManager.Instance.IsInitialized(); //檢測設備可用
if (isInit) {
//設備準備好了 可以讀取了
if(kinectImg.texture == null)
{
Texture2D kinectPic = KinectManager.Instance.GetUsersClrTex(); //從設備獲取彩色數據
// Texture2D kinectPic = KinectManager.Instance.GetUsersLblTex(); //獲取深度數據量
kinectImg.texture = kinectPic; //把彩色數據給控件顯示
}
if (KinectManager.Instance.IsUserDetected())
{
//檢測到玩家
long userId = KinectManager.Instance.GetPrimaryUserID(); //獲取用戶id
Vector3 userPos = KinectManager.Instance.GetUserPosition(userId); //獲取用戶離Kinect的距離信息
//print("x = " + userPos.x + " y = " + userPos.y + " z = " + userPos.z);
int jointType = (int)KinectInterop.JointType.HandLeft;
if (KinectManager.Instance.IsJointTracked(userId,jointType))
{
//關節點被追蹤到
Vector3 leftHandPos = KinectManager.Instance.GetJointKinectPosition(userId, jointType);
//Vector3 leftHandPos = KinectManager.Instance.GetJointPosition(userId, jointType); //y軸輸出不一樣
// print("x = " + leftHandPos.x + " y = " + leftHandPos.y + " z = " + leftHandPos.z);
KinectInterop.HandState leftHandState = KinectManager.Instance.GetLeftHandState(userId); //獲取左手姿勢
if (leftHandState == KinectInterop.HandState.Closed)
{
print("左手握拳");
}else if (leftHandState == KinectInterop.HandState.Open)
{
print("左手張開");
}else if (leftHandState == KinectInterop.HandState.Lasso)
{
print("yes手勢");
}
}
}
}
}
}
Kinect for Unity V2 代碼示例(一)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.