private void OnSensorChanged(KinectSensor oldSensor, KinectSensor newSensor)
        {
            if (oldSensor != null)
            {
                oldSensor.AllFramesReady -= this.OnAllFramesReady;
                this.ResetFaceTracking();
            }

            if (newSensor != null)
            {
                foreach (Faces face in faceList)
                {
                    if (face.kinect.UniqueKinectId == this.Kinect.UniqueKinectId)
                    {
                        idFound = true;
                    }
                }
                if (idFound == false)
                {
                    Faces newFace = new Faces();
                    newFace.kinect = this.Kinect;
                    faceList.Add(newFace);
                    Console.WriteLine("new face object created with id: " + this.Kinect.UniqueKinectId);
                }
                newSensor.AllFramesReady += this.OnAllFramesReady;

            }
        }
 private void ResetAllCount(object sender, RoutedEventArgs e)
 {
     Faces p = new Faces();
     p.people = 0;
     p.people2 = 0;
     p.people3 = 0;
     //set runtime back to 0
     startTime = DateTime.Now;
 }
        private void KinectSensorOnAllFramesReady2(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs)
        {
            using (var colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame())
            {
                if (colorImageFrame == null)
                {
                    return;
                }

                Faces p2 = new Faces();
                pcount2.Content = "Count: " + p2.people2;
                pcount2_Field.Content = "Count: " + p2.people2;
                pcount2_depth.Content = "Count: " + p2.people2;
                // Make a copy of the color frame for displaying.
                var haveNewFormat = this.currentColorImageFormat2 != colorImageFrame.Format;
                if (haveNewFormat)
                {
                    this.currentColorImageFormat2 = colorImageFrame.Format;
                    this.colorImageData2 = new byte[colorImageFrame.PixelDataLength];
                    this.colorImageWritableBitmap2 = new WriteableBitmap(
                        colorImageFrame.Width, colorImageFrame.Height, 96, 96, PixelFormats.Bgr32, null);
                    colorimage2.Source = this.colorImageWritableBitmap2;
                }

                colorImageFrame.CopyPixelDataTo(this.colorImageData2);
                this.colorImageWritableBitmap2.WritePixels(
                    new Int32Rect(0, 0, colorImageFrame.Width, colorImageFrame.Height),
                    this.colorImageData2,
                    colorImageFrame.Width * Bgr32BytesPerPixel,
                    0);
            }

        }
        private void KinectSensorOnAllFramesReady3(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs)
        {
            using (var colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame())
            {
                if (colorImageFrame == null)
                {
                    return;
                }
                Faces p3 = new Faces();

                pcount3.Content = "Count: " + p3.people3;
                pcount3_Field.Content = "Count: " + p3.people3;
                pcount3_depth.Content = "Count: " + p3.people3;
                int totalPeople = p3.people + p3.people2 + p3.people3;
                pcount_tot.Content = "Total Count: " + totalPeople;
                pcount_tot_Field.Content = "Total Count: " + totalPeople;
                pcount_tot_depth.Content = "Total Count: " + totalPeople;
                // Make a copy of the color frame for displaying.
                var haveNewFormat = this.currentColorImageFormat3 != colorImageFrame.Format;
                if (haveNewFormat)
                {
                    this.currentColorImageFormat3 = colorImageFrame.Format;
                    this.colorImageData3 = new byte[colorImageFrame.PixelDataLength];
                    this.colorImageWritableBitmap3 = new WriteableBitmap(
                        colorImageFrame.Width, colorImageFrame.Height, 96, 96, PixelFormats.Bgr32, null);
                    colorimage3.Source = this.colorImageWritableBitmap3;
                }

                colorImageFrame.CopyPixelDataTo(this.colorImageData3);
                this.colorImageWritableBitmap3.WritePixels(
                    new Int32Rect(0, 0, colorImageFrame.Width, colorImageFrame.Height),
                    this.colorImageData3,
                    colorImageFrame.Width * Bgr32BytesPerPixel,
                    0);
            }

        }
        private void KinectSensorOnAllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs)
        {
            using (var colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame())
            {
                if (colorImageFrame == null)
                {
                    return;
                }

                currentTime = DateTime.Now;

                long elapsedTicks = currentTime.Ticks - startTime.Ticks;
                TimeSpan elapsedSpan = new TimeSpan(elapsedTicks);

                runtime.Content = elapsedSpan.Days +" days, "+ elapsedSpan.Hours +" hours, "+ elapsedSpan.Minutes +" minutes, "+ elapsedSpan.Seconds + " seconds";

                Faces p = new Faces();
                humanMapping fMap = new humanMapping();
                //pcount1.Content= "newFace: " + fMap.newFace + "  oldFace: " + fMap.oldFace;
                pcount1.Content = "Count: " + p.people;
                pcount1_Field.Content = "Count: " + p.people;
                pcount1_depth.Content = "Count: " + p.people;
                // Make a copy of the color frame for displaying.
                var haveNewFormat = this.currentColorImageFormat != colorImageFrame.Format;
                if (haveNewFormat)
                {
                    this.currentColorImageFormat = colorImageFrame.Format;
                    this.colorImageData = new byte[colorImageFrame.PixelDataLength];
                    this.colorImageWritableBitmap = new WriteableBitmap(
                        colorImageFrame.Width, colorImageFrame.Height, 96, 96, PixelFormats.Bgr32, null);
                    colorimage.Source = this.colorImageWritableBitmap;
                }

                colorImageFrame.CopyPixelDataTo(this.colorImageData);
                this.colorImageWritableBitmap.WritePixels(
                    new Int32Rect(0, 0, colorImageFrame.Width, colorImageFrame.Height),
                    this.colorImageData,
                    colorImageFrame.Width * Bgr32BytesPerPixel,
                    0);
            }
 
        }