You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.0 KiB
66 lines
2.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Remoting.Messaging;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Lib;
|
|
using Microsoft.Kinect;
|
|
|
|
namespace KinectUtils
|
|
{
|
|
static class GestureManager
|
|
{
|
|
static private BodyFrameReader bodyFrameReader;
|
|
static private Body[] bodies;
|
|
static event EventHandler GestureRecognized;
|
|
static KinectManager KinectManager { get; set; }
|
|
static List<BaseGesture> KnownGestures { get; set; }
|
|
|
|
static public void AddGestures(IGestureFactory factory)
|
|
{
|
|
KnownGestures = (List<BaseGesture>)factory.CreateGestures();
|
|
}
|
|
static public void AddGestures(params BaseGesture[] gestures)
|
|
{
|
|
foreach (var gesture in gestures)
|
|
{
|
|
KnownGestures.Add(gesture);
|
|
}
|
|
}
|
|
static public void RemoveGesture(BaseGesture gesture)
|
|
{
|
|
KnownGestures.Remove(gesture);
|
|
}
|
|
static public void StartAcquiringFrames(KinectManager kinectManager)
|
|
{
|
|
bodyFrameReader = kinectManager.Sensor.BodyFrameSource.OpenReader();
|
|
bodyFrameReader.FrameArrived += Reader_BodyFrameArrived;
|
|
}
|
|
|
|
static private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
|
|
{
|
|
using (var bodyframe = e.FrameReference.AcquireFrame())
|
|
{
|
|
if (bodyframe != null)
|
|
{
|
|
bodyframe.GetAndRefreshBodyData(bodies);
|
|
foreach (var body in bodies)
|
|
{
|
|
if (body.IsTracked)
|
|
{
|
|
foreach(var gesture in KnownGestures)
|
|
{
|
|
if (gesture.TestGesture(body))
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|