Skip to content

Commit

Permalink
First commit. Working speech. Gestures not working yet?
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode committed Aug 16, 2011
0 parents commit ad2ee87
Show file tree
Hide file tree
Showing 25 changed files with 1,839 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
KinectPresenter/bin/
KinectPresenter/obj/
20 changes: 20 additions & 0 deletions KinectPresenter.sln
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KinectPresenter", "KinectPresenter\KinectPresenter.csproj", "{B598224F-A499-4A1E-9347-323F2C0ACF25}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B598224F-A499-4A1E-9347-323F2C0ACF25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B598224F-A499-4A1E-9347-323F2C0ACF25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B598224F-A499-4A1E-9347-323F2C0ACF25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B598224F-A499-4A1E-9347-323F2C0ACF25}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added KinectPresenter.suo
Binary file not shown.
50 changes: 50 additions & 0 deletions KinectPresenter/CueStore.cs
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KinectPresenter
{
public class CueStore
{
Dictionary<int, List<string>> store;

private CueStore()
{
store = new Dictionary<int, List<string>>();
}

public string Get(int slideId, int step)
{
if (step >= store[slideId].Count)
{
return null;
}
else
{
return store[slideId][step];
}
}

public HashSet<string> Flatten()
{
List<string> list = new List<string>();

foreach(KeyValuePair<int, List<string>> pair in store)
{
list.AddRange(pair.Value);
}

return new HashSet<string>(list);
}

public static CueStore Deserialize()
{
return new CueStore();
}

public void Serialize()
{
}
}
}
26 changes: 26 additions & 0 deletions KinectPresenter/ErrorHandler.cs
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KinectPresenter
{
public class ErrorHandler
{
private static string KINECT_NOT_FOUND_MESSAGE = "KINECT_NOT_FOUND_MESSAGE";
private static string KINECT_NOT_FOUND_CAPTION = "KINECT_NOT_FOUND_CAPTION";

private static string SLIDE_SHOW_MODE_KINECT_NOT_FOUND_MESSAGE = "SLIDE_SHOW_MODE_KINECT_NOT_FOUND_MESSAGE";
private static string SLIDE_SHOW_MODE_KINECT_NOT_FOUND_CAPTION = "SLIDE_SHOW_MODE_KINECT_NOT_FOUND_CAPTION";

public static void ShowKinectNotFoundDialog()
{
System.Windows.Forms.MessageBox.Show(KINECT_NOT_FOUND_MESSAGE, KINECT_NOT_FOUND_CAPTION, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
}

public static void ShowSlideShowModeKinectNotFoundDialog()
{
System.Windows.Forms.MessageBox.Show(SLIDE_SHOW_MODE_KINECT_NOT_FOUND_MESSAGE, SLIDE_SHOW_MODE_KINECT_NOT_FOUND_CAPTION, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
}
}
}
89 changes: 89 additions & 0 deletions KinectPresenter/Gesture.cs
@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.Kinect.Nui;

namespace KinectPresenter
{
public interface IGesture
{
GestureType GestureType { get; }
GestureSubType GestureSubType { get; }
GestureHandType HandsUsed { get; }
double Confidence { get; }
}

public enum GestureType
{
SingleHandedSwipe
}

public enum GestureSubType
{
LeftHandedSwipeFromLeftToRight,
LeftHandedSwipeFromRightToLeft,
LeftHandedSwipeFromTopToBottom,
LeftHandedSwipeFromBottomToTop,
RightHandedSwipeFromLeftToRight,
RightHandedSwipeFromRightToLeft,
RightHandedSwipeFromTopToBottom,
RightHandedSwipeFromBottomToTop
}

public enum GestureHandType
{
LeftHand,
RightHand,
BothHands
}

public interface IGestureRecognizer
{
void MatchFrame(SkeletonFrame frame);
event EventHandler<GestureRecognizedEventArgs> GestureRecognized;
}

public class GestureRecognizedEventArgs : EventArgs
{
public readonly IGesture Result;

public GestureRecognizedEventArgs(IGesture result)
{
Result = result;
}
}

public class Point
{
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }

public bool Is3D { get; private set; }

public Point(Vector v)
{
X = v.X;
Y = v.Y;
Z = v.Z;
}

public Point(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}

public float DistaceFrom(Point other)
{
return DistanceBetween(this, other);
}

public static float DistanceBetween(Point a, Point b)
{
return (float)Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2) + Math.Pow(a.Z - b.Z, 2));
}
}
}
67 changes: 67 additions & 0 deletions KinectPresenter/GestureCommandDetector.cs
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KinectPresenter
{
class GestureCommandDetector : ISlideShowCommandDetector
{
public event EventHandler<SlideShowCommandDetectedEventArgs> SlideShowCommandDetected;

// TODO: read from settings on start
private const GestureSubType GESTURE_COMMAND_NEXT = GestureSubType.RightHandedSwipeFromRightToLeft;
private const GestureSubType GESTURE_COMMAND_PREVIOUS = GestureSubType.LeftHandedSwipeFromLeftToRight;

private SlideShowController slideShowController;
private GestureEngine gestureEngine;

public GestureCommandDetector(SlideShowController controller, GestureEngine engine)
{
slideShowController = controller;
gestureEngine = engine;
}

public void Initialize()
{
gestureEngine.Initialize();
}

public void Start()
{
List<IGestureRecognizer> gestures = new List<IGestureRecognizer>();
// TODO: this should be generic - add a GestureRecognizerFactory or something
gestures.Add(new SingleHandedSwipeGestureRecognizer(GESTURE_COMMAND_NEXT));
gestures.Add(new SingleHandedSwipeGestureRecognizer(GESTURE_COMMAND_PREVIOUS));

gestureEngine.GestureRecognized += OnGestureRecognized;
gestureEngine.Start(gestures);
}

public void Stop()
{
gestureEngine.Stop();
gestureEngine.GestureRecognized -= OnGestureRecognized;
}

private void OnGestureRecognized(object sender, GestureRecognizedEventArgs e)
{
if (SlideShowCommandDetected != null)
{
SlideShowCommandDetectedEventArgs args = null;

switch (e.Result.GestureSubType)
{
case GESTURE_COMMAND_NEXT:
args = new SlideShowCommandDetectedEventArgs(SlideShowCommandType.Next);
break;
case GESTURE_COMMAND_PREVIOUS:
args = new SlideShowCommandDetectedEventArgs(SlideShowCommandType.Previous);
break;
}

SlideShowCommandDetected(this, args);
}
}
}
}
109 changes: 109 additions & 0 deletions KinectPresenter/GestureEngine.cs
@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Research.Kinect.Nui;

namespace KinectPresenter
{
public class GestureEngine
{
public event EventHandler<GestureRecognizedEventArgs> GestureRecognized;

private Mutex engineLock;
private Thread engineHost;
private List<IGestureRecognizer> recognizers;
private bool initialized;

public GestureEngine()
{
initialized = false;
}

public void Initialize()
{
if (initialized)
{
return;
}

// test Kinect
Runtime runtime = new Runtime();
runtime.Initialize(RuntimeOptions.UseSkeletalTracking);
runtime.Uninitialize();

initialized = true;
}

public void Start(List<IGestureRecognizer> gestures)
{
if (!initialized)
{
return;
}

if (engineLock != null)
{
Stop();
}

recognizers = gestures;

engineLock = new Mutex(true);
engineHost = new Thread(EngineWorker);
engineHost.Start();
}

public void Stop()
{
if (engineLock != null)
{
engineLock.ReleaseMutex();
engineHost.Join();
}

engineLock = null;
engineHost = null;
}

private void OnSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
foreach (IGestureRecognizer recognizer in recognizers)
{
recognizer.MatchFrame(e.SkeletonFrame);
}
}

private void OnGestureRecognized(object sender, GestureRecognizedEventArgs e)
{
if (GestureRecognized != null)
{
GestureRecognized(this, e);
}
}

private void EngineWorker()
{
Runtime engine = new Runtime();

foreach (IGestureRecognizer recognizer in recognizers)
{
recognizer.GestureRecognized += OnGestureRecognized;
}

engine.SkeletonFrameReady += OnSkeletonFrameReady;
engine.Initialize(RuntimeOptions.UseSkeletalTracking);

engineLock.WaitOne();

engine.Uninitialize();
engine.SkeletonFrameReady -= OnSkeletonFrameReady;

foreach (IGestureRecognizer recognizer in recognizers)
{
recognizer.GestureRecognized -= OnGestureRecognized;
}
}
}
}

0 comments on commit ad2ee87

Please sign in to comment.