예제 #1
0
        private void HandleColorFrame(ColorFrameReference reference)
        {
            if (Task.StandBy)
            {
                ColorWatch.Reset(); return;
            }

            ColorWatch.Again();
            using (var frame = reference.AcquireFrame()) {
                if (frame == null)
                {
                    return;
                }

                // Copy data to array based on image format
                if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
                {
                    frame.CopyRawFrameDataToArray(Color.Pixels);
                }
                else
                {
                    frame.CopyConvertedFrameDataToArray(Color.Pixels, ColorImageFormat.Bgra);
                }

                Color.Stamp.Time = System.DateTime.Now;
            }
            ColorWatch.Stop();
        }
예제 #2
0
        private void HandleBodyIndexFrame(BodyIndexFrameReference reference)
        {
            if (Task.StandBy)
            {
                BodyIndexWatch.Reset(); return;
            }

            BodyIndexWatch.Again();
            using (var frame = reference.AcquireFrame()) {
                if (frame == null)
                {
                    return;
                }

                frame.CopyFrameDataToArray(BodyIndex.Pixels);

                /*
                 * using (Microsoft.Kinect.KinectBuffer buffer = indexFrame.LockImageBuffer()) {
                 * IntPtr ptr = buffer.UnderlyingBuffer;
                 * RefreshBodyArea(ptr, buffer.Size);
                 * }
                 */
                BodyIndex.Stamp.Time = System.DateTime.Now;
            }
            BodyIndexWatch.Stop();
        }
예제 #3
0
        private void OnMultipleFramesArrivedHandler(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            init = true;

            // Retrieve multisource frame reference
            MultiSourceFrameReference multiRef   = e.FrameReference;
            MultiSourceFrame          multiFrame = null;

            try {
                AllFrameWatch.Again();

                multiFrame = multiRef.AcquireFrame();
                if (multiFrame == null)
                {
                    AllFrameWatch.Stop();  return;
                }

                HandleDepthFrame(multiFrame.DepthFrameReference);

                // Motion check
                if (Task.StandBy)
                {
                    AllFrameWatch.Stop(); return;
                }

                HandleColorFrame(multiFrame.ColorFrameReference);
                HandleBodyFrame(multiFrame.BodyFrameReference);
                HandleBodyIndexFrame(multiFrame.BodyIndexFrameReference);

                AllFrameWatch.Stop();
            } catch (Exception) { /* ignore if the frame is no longer available */ } finally { }
        }
예제 #4
0
 private void HandleDepthFrame(DepthFrameReference reference)
 {
     DepthWatch.Again();
     using (var frame = reference.AcquireFrame()) {
         if (frame == null)
         {
             return;
         }
         frame.CopyFrameDataToArray(Depth.Pixels);
         Depth.Stamp.Time = System.DateTime.Now;
     }
     DepthWatch.Stop();
 }
        private async Task RepaintAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token)
        {
            // Initial wait time before we begin the periodic loop.
            if (dueTime > TimeSpan.Zero)
            {
                await Task.Delay(dueTime, token);
            }

            // Repeat this loop until cancelled.
            while (!token.IsCancellationRequested)
            {
                // Timestamp data
                RepaintWatch.Again();

                // Do Job
                try {
                    // Init once
                    InitRepaint();

                    // Copy frame
                    ColorFrame color = (ColorFrame)Descriptor.Find(typeof(ColorFrame));
                    if (color != null)
                    {
                        Buffer.BlockCopy(color.Pixels, 0, drawer, 0, color.Pixels.Length);
                        // Buffer.BlockCopy(Infrared, 0, drawer, 0, Infrared.Length);

                        // Ask repaint to addons
                        AddOnManager.GetInstance().RepaintColorFrame(Name, drawer, color.Width, color.Height);
                    }

                    // Resize
                    scale.Bytes = drawer;
                    var resize = scale.Resize(w, h, Emgu.CV.CvEnum.Inter.Cubic);
                    bitmap.WritePixels(rect, resize.Bytes, stride, 0);

                    // Ticks
                    this.Repaint.Text = "Repaint: " + RepaintWatch.Average();
                } catch (Exception ex) { Error(ex); }
                RepaintWatch.Stop();

                // Wait to repeat again.
                try {
                    if (interval > TimeSpan.Zero)
                    {
                        await Task.Delay(interval, token);
                    }
                } catch (ThreadInterruptedException) { break; }
            }
        }
예제 #6
0
        private void HandleInfraredFrame(InfraredFrameReference reference)
        {
            if (Task.StandBy)
            {
                InfraredWatch.Reset(); return;
            }

            InfraredWatch.Again();
            using (var frame = reference.AcquireFrame()) {
                if (frame == null)
                {
                    return;
                }

                frame.CopyFrameDataToArray(Infrared.Pixels);
                Infrared.Stamp.Time = System.DateTime.Now;
            }
            InfraredWatch.Stop();
        }
예제 #7
0
        private void HandleBodyFrame(BodyFrameReference reference)
        {
            if (Task.StandBy)
            {
                BodyWatch.Reset(); return;
            }

            BodyWatch.Again();
            using (var frame = reference.AcquireFrame()) {
                if (frame == null)
                {
                    return;
                }

                // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
                // As long as those body objects are not disposed and not set to null in the array,
                // those body objects will be re-used.
                var tmp = (IList <Body>)Body.RawData;
                frame.GetAndRefreshBodyData(tmp);
                Body.Stamp.Time = System.DateTime.Now;
                RefreshBodyData(Body);
            }
            BodyWatch.Stop();
        }
예제 #8
0
        private void KinectSensorOnAllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs)
        {
            if (++fpsGlobal < FPSGlobal)
            {
                return;
            }
            fpsGlobal = 0;

            using (var depthFrame = allFramesReadyEventArgs.OpenDepthImageFrame())
                using (var colorFrame = allFramesReadyEventArgs.OpenColorImageFrame())
                    using (var skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame()) {
                        if (null == depthFrame || null == colorFrame || null == skeletonFrame)
                        {
                            return;
                        }

                        AllFrameWatch.Again();

                        // Init ONCE with provided data
                        InitFrames(depthFrame, colorFrame, skeletonFrame);
                        if (!init)
                        {
                            return;
                        }

                        // Backup frames (motion)
                        depthFrame.CopyPixelDataTo(Depth.Pixelss);

                        // Motion check
                        if (Task == null || Task.StandBy)
                        {
                            AllFrameWatch.Stop();
                            return;
                        }

                        // Copy computed depth
                        if (++fpsDepth >= FPSDepth)
                        {
                            fpsDepth = 0;
                            // depthFrame.CopyDepthImagePixelDataTo(this.DepthPixels);
                            Depth.Stamp.Time = System.DateTime.Now;
                        }

                        // Copy color data
                        if (++fpsColor >= FPSColor)
                        {
                            fpsColor = 0;
                            colorFrame.CopyPixelDataTo(Color.Pixels);
                            Color.Stamp.Time = System.DateTime.Now;
                        }

                        // Copy skeleton data
                        if (++fpsSkeleton >= FPSSkeleton)
                        {
                            fpsSkeleton = 0;
                            skeletonFrame.CopySkeletonDataTo((Skeleton[])Skeletons.RawData);
                            Skeletons.Stamp.Time = System.DateTime.Now;
                        }

                        // Convert Joint 3D to 2D on 1st skeleton
                        if (++fpsJoints >= FPSJoints)
                        {
                            fpsJoints = 0;
                            RefreshBodyData(Skeletons);
                        }

                        AllFrameWatch.Stop();
                    }
        }