Unity + Kinect 获取彩色图像和深度图像(四)

1.新建一个空物体 KinectController 添加脚本 Kinect Manager 修改下图两个属性

2.创建两个RawImage 用来显示获取的彩色图像和红外线图像,添加一个脚本组件名字为GetUsesClrTex,将两个RawImage拖曳进去

3.效果图如下:

GetUsesClrTex.cs

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GetUsesClrTex : MonoBehaviour
{
    public bool isAngetKinect;
    // 获取人的彩色图
    public RawImage UserTexture;
    // 获取人的红外线图
    public RawImage UsersLblTex;

    void Update()
    {
        //判断设备是否准备好
        isAngetKinect = KinectManager.Instance.IsInitialized();

        if (isAngetKinect)
        {
            if (UserTexture.texture == null)
            {
                //获取彩色数据
               Texture2D texture = KinectManager.Instance.GetUsersClrTex();
                UserTexture.texture = texture;

                //获取深度数据
                Texture2D texture1 = KinectManager.Instance.GetUsersLblTex();
                UsersLblTex.texture = texture1;
            }
            //判断是否检测到玩家
            if (KinectManager.Instance.IsUserDetected())
            {
                //获取玩家的ID
                long userId = KinectManager.Instance.GetPrimaryUserID();
                //获取右手
                int jointType = (int)KinectInterop.JointType.HandRight;
                //获取左手
                int LeftType = (int)KinectInterop.JointType.HandLeft;

                //KinectInterop.JointType 可以获取人物身上的任意骨骼点需要什么直接获取就行

                //追踪到关节点
                if (KinectManager.Instance.IsJointTracked(userId, jointType))
                {
                    //获取右手位置
                    Vector3 rightHandpos = KinectManager.Instance.GetJointKinectPosition(userId, jointType);
                    Debug.Log("----------------->" + rightHandpos);
                }
            }
        }
    }
}

评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值