/// <summary> /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader /// </summary> /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param> /// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param> public GestureDetector(KinectSensor kinectSensor, GestureResultView gestureResultView) { if (kinectSensor == null) { throw new ArgumentNullException("kinectSensor"); } if (gestureResultView == null) { throw new ArgumentNullException("gestureResultView"); } this.GestureResultView = gestureResultView; this.ClosedHandState = false; // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor. this.vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0); // open the reader for the vgb frames this.vgbFrameReader = this.vgbFrameSource.OpenReader(); if (this.vgbFrameReader != null) { this.vgbFrameReader.IsPaused = true; } // load all gestures from the gesture database using (var database = new VisualGestureBuilderDatabase(this.gestureDatabase)) { this.vgbFrameSource.AddGestures(database.AvailableGestures); } //Initialize the gestures to a set sequence: TODO set from the UI setGestures("Stop_Left", "Stop_Right", "ThumbUp_Left"); }
/// <summary> /// Opens the serial and connects to the Arduino /// </summary> public RobotControl(GestureResultView view, string kinectAxis) { this.gestureResultView = view; this.KinectAxis = kinectAxis; beginSerial(9600, KinectSecuritySystem.Properties.Settings.Default.COMPort); makeConnection(); }
/// <summary> /// Initializes a new instance of the MainWindow class /// </summary> public MainWindow() { // initialize the MainWindow this.InitializeComponent(); // only one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // open the reader for the color frames this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader(); // wire handler for frame arrival this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; // create the colorFrameDescription from the ColorFrameSource using Bgra format FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); // create the bitmap to display this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); // open the sensor this.kinectSensor.Open(); // set the initial status text this.UpdateKinectStatusText(); // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // initialize the BodyViewer object for displaying tracked bodies in the UI this.kinectBodyView = new KinectBodyView(this.kinectSensor); // initialize the GestureDetector object this.gestureResultView = new GestureResultView(false, false, false, false, -1.0f, false, 0, 3, false, false, false, false, false); this.gestureDetector = new GestureDetector(this.kinectSensor, this.gestureResultView); this.robotControl = new RobotControl(this.gestureResultView, this.kinectAxis); // set data context objects for display in UI this.DataContext = this; this.kinectBodyViewbox.DataContext = this.kinectBodyView; this.gestureResultGrid.DataContext = this.gestureResultView; this.outputGrid.DataContext = this.gestureResultView; this.ArmGrid.DataContext = this.gestureResultView; this.updateTimer.Start(); }