Exemple #1
0
        /// <summary>
        /// Event handler for Kinect sensor's DepthFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            {
                if (depthFrame != null)
                {
                    // Copy the pixel data from the image to a temporary array
                    depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);
                    // Get the min and max reliable depth for the current frame

                    short[]    depth      = this.depthPixels.Select(pixel => pixel.Depth).ToArray();
                    short[]    depthFixed = DepthFixer.Fix(depth);
                    KinectData kd         = new KinectData(DepthWidth, DepthHeight);
                    kd.SetDepthData(depth, depthFixed, MinDepthRange, MaxDepthRange);
                    //sender matrix

                    if (Frame != null)
                    {
                        fpsController = 0; //reset counter
                        Frame(kd, e);
                    }

                    fpsController++;
                }
            }
        }
Exemple #2
0
        private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame != null)
                {
                    // Copy the pixel data from the image to a temporary array
                    colorFrame.CopyPixelDataTo(this.colorPixels);

                    KinectData kd = new KinectData(ColorWidth, ColorHeight);

                    kd.SetColorData(ImageToBitmap(colorFrame));

                    if (ObjectDetection)
                    {
                        List <DetectedObject> objs = ObjectDetector.FindObjects(kd.ColorImage, kd.Width, kd.Height);
                        kd.SetDetectedObjects(objs);
                    }

                    //sender matrix
                    if (Frame != null)
                    {
                        Frame(kd, e);
                    }
                }
            }
        }