第一种方式:(适合单个姿势识别,多个场景多个姿势等复杂检测也可以实现,但是可能需要多创建几个类似脚本)
添加你要识别的内置姿势即可
KinectManager 增加用户时添加个调用
PoseDetector.Instance.UserWasAdded(userId, uidIndex);
随便放哪里,这里识别的 必须在面板上添加你要识别的姿势,这里才能判断出来
using com.rfilkov.kinect;
using System.Collections.Generic;
using UnityEngine;
public class PoseDetector : MonoBehaviour
{
[Tooltip("List of the gestures to detect.")]
public List<GestureType> detectGestures = new List<GestureType>();
public static PoseDetector Instance;
private void Awake()
{
Instance = this;
}
KinectGestureManager gestureManager;
KinectManager manager;
private void Start()
{
manager = KinectManager.Instance;
gestureManager = KinectManager.Instance.gestureManager;
}
public void UserDetected(ulong userId, int userIndex)
{
foreach (GestureType gesture in detectGestures)
{
gestureManager.DetectGesture(manager.GetPrimaryUserID(), gesture);
}
}
void Update()
{
if (manager.IsUserDetected(0))
{
// 伸手
bool bPush = gestureManager.IsGestureComplete(manager.GetPrimaryUserID(), GestureType.Push, true);
if (bPush)
{
Debug.Log("bPush");
}
}
}
internal void UserWasAdded(ulong userId, int uidIndex)
{
UserDetected(userId, uidIndex);
}
}
第二种方式:(推荐用这种)
需要内置的SimpleGestureListener.cs 脚本,你不用去考虑这个脚本是干啥的,怎么实现的(原理跟我第一种方式是同理,只是我把它简化了,删掉了无用的代码),只要在GestureCompleted()该方法中添加委托(该脚本一直运行,无需任何隐藏之类的操作)
public Action<GestureType> action;
// invoked when a (discrete) gesture is complete.
public bool GestureCompleted(ulong userId, int userIndex, GestureType gesture,
KinectInterop.JointType joint, Vector3 screenPos)
{
if (userIndex != playerIndex)
return false;
if (progressDisplayed)
return true;
string sGestureText = gesture + " detected";
Debug.Log(sGestureText);
if (gestureInfo != null)
{
gestureInfo.text = sGestureText;
}
action?.Invoke(gesture);
return true;
}
在你需要的地方,监听委托即可 文章来源:https://www.toymoban.com/news/detail-702507.html
using com.rfilkov.components;
using com.rfilkov.kinect;
using UnityEngine;
//[RequireComponent(typeof(SimpleGestureListener))]
public class GestureActionTest : MonoBehaviour
{
public SimpleGestureListener gestureListener;
void Start()
{
gestureListener.action += GestureHandle;
}
private void GestureHandle(GestureType type)
{
switch (type)
{
case GestureType.None:
break;
case GestureType.SwipeLeft:
Debug.Log("SwipeLeft");
break;
case GestureType.SwipeRight:
Debug.Log("SwipeRight");
break;
case GestureType.Push:
Debug.Log("Push");
break;
default:
break;
}
}
}
文章来源地址https://www.toymoban.com/news/detail-702507.html
到了这里,关于Azure Kinect 内置姿势识别 两种方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!