}//end UpdateDepth() #endregion #region Display Depth Map /// <summary> /// This method gets executed when the window loads. In it, we initialize our connection with Kinect /// and set up the timer which will update our depth image. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { try { // Initialize the context from the configuration file this.context = new Context(@"..\..\data\openniconfig.xml"); // Get the depth generator from the config file. this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (this.depth == null) { throw new Exception(@"Error in Data\openniconfig.xml. No depth node found."); } MapOutputMode mapMode = this.depth.GetMapOutputMode(); this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // Initialize Matrixes this.depthMatrix = new Matrix <Double>(480, 640); this.depthMatrixROI = new Matrix <Double>(480, 640); this.depthMatrixROIByte = new Matrix <Byte>(480, 640); this.backgroundDepthMatrix = new Matrix <Double>(480, 640); // Initialize Images this.depthMatrixImage = new Image <Gray, double>(640, 480); this.depthMatrixROIImage = new Image <Gray, byte>(640, 480); this.backgroundDepthImage = new Image <Gray, double>(640, 480); this.trackingImage = new Image <Bgr, byte>(640, 480, new Bgr(0, 0, 0)); // Initialize Blob Tracking Components // Blob Tracking Parameter blobParam = new Emgu.CV.VideoSurveillance.BlobTrackerAutoParam <Gray>(); blobParam.BlobTracker = new Emgu.CV.VideoSurveillance.BlobTracker(Emgu.CV.CvEnum.BLOBTRACKER_TYPE.CC); blobParam.BlobDetector = new Emgu.CV.VideoSurveillance.BlobDetector(Emgu.CV.CvEnum.BLOB_DETECTOR_TYPE.CC); //blobParam.FGDetector = new Emgu.CV.VideoSurveillance.FGDetector<Gray>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD); //blobParam.FGTrainFrames = 10; // Blob Tracking initialization blobTracker = new Emgu.CV.VideoSurveillance.BlobTrackerAuto <Gray>(blobParam); progressBar1.Minimum = 0; progressBar1.Maximum = ((Convert.ToInt16(textBoxLifespan.Text) * 4) / _tickDuration); } catch (Exception ex) { MessageBox.Show("Error initializing OpenNI."); MessageBox.Show(ex.Message); this.Close(); } // Set the timer to update teh depth image every 10 ms. DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, _tickDuration); dispatcherTimer.Start(); Console.WriteLine("Finished loading"); }
/// <summary> /// This method gets executed when the window loads. In it, we initialize our connection with Kinect /// and set up the timer which will update our depth image. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { try { // Initialize the context from the configuration file this.context = new Context(@"..\..\data\openniconfig.xml"); // Get the depth generator from the config file. this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (this.depth == null) throw new Exception(@"Error in Data\openniconfig.xml. No depth node found."); MapOutputMode mapMode = this.depth.GetMapOutputMode(); this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // Initialize Matrixes this.depthMatrix = new Matrix<Double>(480, 640); this.depthMatrixROI = new Matrix<Double>(480, 640); this.depthMatrixROIByte = new Matrix<Byte>(480, 640); this.backgroundDepthMatrix = new Matrix<Double>(480, 640); // Initialize Images this.depthMatrixImage = new Image<Gray,double>(640,480); this.depthMatrixROIImage = new Image<Gray, byte>(640, 480); this.backgroundDepthImage = new Image<Gray, double>(640, 480); this.trackingImage = new Image<Bgr, byte>(640, 480, new Bgr(0, 0, 0)); // Initialize Blob Tracking Components // Blob Tracking Parameter blobParam = new Emgu.CV.VideoSurveillance.BlobTrackerAutoParam<Gray>(); blobParam.BlobTracker = new Emgu.CV.VideoSurveillance.BlobTracker(Emgu.CV.CvEnum.BLOBTRACKER_TYPE.CC); blobParam.BlobDetector = new Emgu.CV.VideoSurveillance.BlobDetector(Emgu.CV.CvEnum.BLOB_DETECTOR_TYPE.CC); //blobParam.FGDetector = new Emgu.CV.VideoSurveillance.FGDetector<Gray>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD); //blobParam.FGTrainFrames = 10; // Blob Tracking initialization blobTracker = new Emgu.CV.VideoSurveillance.BlobTrackerAuto<Gray>(blobParam); progressBar1.Minimum = 0; progressBar1.Maximum = ((Convert.ToInt16(textBoxLifespan.Text) * 4) / _tickDuration); } catch (Exception ex) { MessageBox.Show("Error initializing OpenNI."); MessageBox.Show(ex.Message); this.Close(); } // Set the timer to update teh depth image every 10 ms. DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, _tickDuration); dispatcherTimer.Start(); Console.WriteLine("Finished loading"); }