Created
December 15, 2013 21:56
-
-
Save FabienArcellier/7978729 to your computer and use it in GitHub Desktop.
Capture gesture with Intel Perceptual Computing SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CaptureGestureIntelSDK | |
{ | |
using System; | |
using System.Threading; | |
class Program | |
{ | |
public static bool EndRequested = false; | |
static void Main(string[] args) | |
{ | |
// Chargement de l environnement | |
PXCMSession session; | |
pxcmStatus sts = PXCMSession.CreateInstance(out session); | |
if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) | |
{ | |
throw new TypeLoadException("Fail to instanciate PXCM Session"); | |
} | |
Console.Out.WriteLine("Press any key to start capture"); | |
Console.ReadKey(true); | |
Console.Out.WriteLine("Press ESC to end capture"); | |
// Ce thread permet de capturer l appui sur ESCAPE par l utilisateur | |
// pour arreter le programme | |
Thread KeyListener = new Thread(new ThreadStart(ListenEscape)); | |
KeyListener.Start(); | |
// Chargement du flux d une webcam. Voir la classe en bas du fichier source SimpleGestureUtilMPipeline | |
// On surcharge UtilMPipeline | |
using (var pp = new SimpleGestureUtilMPipeline()) | |
{ | |
// Fonction lambda pour afficher le resultat des captures des gestes dans la console | |
pp.OnGestureCaptured += (o, e) => | |
{ | |
Console.WriteLine(String.Format("{0} - {1} - confidence {2}", e.body.ToString(), e.label.ToString(), e.confidence)); | |
}; | |
pp.Init(); | |
do | |
{ | |
// Capture une image, si vous ne le faites pas, le moteur de gesture ne | |
// s activera pas | |
if (!pp.AcquireFrame(true)) break; | |
if (!pp.ReleaseFrame()) break; | |
} while (!EndRequested); | |
} | |
session.Dispose(); | |
Console.Out.WriteLine("End of capture, press any key to quit the program"); | |
Console.ReadKey(true); | |
} | |
static void ListenEscape() | |
{ | |
do | |
{ | |
if (Console.ReadKey(true).Key == ConsoleKey.Escape) | |
{ | |
EndRequested = true; | |
} | |
Thread.Sleep(50); | |
} while (!EndRequested); | |
} | |
} | |
/// <summary> | |
/// Surcharge de la classe UtilMPipeline pour activer le capture des gestures | |
/// </summary> | |
public class SimpleGestureUtilMPipeline : UtilMPipeline | |
{ | |
public event EventHandler<PXCMGesture.Gesture> OnGestureCaptured; | |
public SimpleGestureUtilMPipeline() | |
: base() | |
{ | |
// On a besoin de la camera de profondeur pour capturer les gestes | |
this.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH, 320, 240); | |
this.EnableGesture(); | |
} | |
public override void OnGesture(ref PXCMGesture.Gesture data) | |
{ | |
if (OnGestureCaptured != null) | |
this.OnGestureCaptured(this, data); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment