コード例 #1
0
        void irReader_FrameArrived(object sender, InfraredFrameArrivedEventArgs e)
        {
            using (InfraredFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    FrameDescription desc = frame.FrameDescription;

                    KinectBase.ColorFrameEventArgs irE = new KinectBase.ColorFrameEventArgs();
                    irE.bytesPerPixel = (int)desc.BytesPerPixel;
                    irE.pixelFormat   = PixelFormats.Gray16;
                    irE.height        = desc.Height;
                    irE.width         = desc.Width;
                    irE.kinectID      = kinectID;
                    irE.timeStamp     = frame.RelativeTime;
                    irE.isIR          = true;
                    //irE.image = new byte[desc.LengthInPixels * sizeof(UInt16)];
                    irE.image = irImagePool.GetObject();
                    unsafe
                    {
                        fixed(byte *ptr = irE.image)
                        {
                            frame.CopyFrameDataToIntPtr((IntPtr)ptr, desc.LengthInPixels * sizeof(UInt16));
                        }
                    }

                    OnColorFrameReceived(irE);
                }
            }
        }
コード例 #2
0
        private void InfraredFrameArrived(object sender, InfraredFrameArrivedEventArgs e)
        {
            if (null == e.FrameReference)
            {
                return;
            }

            // If you do not dispose of the frame, you never get another one...
            using (InfraredFrame _InfraredFrame = e.FrameReference.AcquireFrame()) {
                if (null == _InfraredFrame)
                {
                    return;
                }

                BitmapToDisplay.Lock();
                _InfraredFrame.CopyFrameDataToIntPtr(
                    BitmapToDisplay.BackBuffer,
                    Convert.ToUInt32(BitmapToDisplay.BackBufferStride * BitmapToDisplay.PixelHeight));
                BitmapToDisplay.AddDirtyRect(
                    new Int32Rect(
                        0,
                        0,
                        _InfraredFrame.FrameDescription.Width,
                        _InfraredFrame.FrameDescription.Height));
                BitmapToDisplay.Unlock();
            }
        }
コード例 #3
0
        /// <summary> EMGU VERSION
        /// Directly accesses the underlying image buffer of the InfraredFrame to
        /// create a displayable bitmap.
        /// This function requires the /unsafe compiler option as we make use of direct
        /// access to the native memory pointed to by the infraredFrameData pointer.
        /// </summary>
        /// <param name="infraredFrame"> the InfraredFrame image </param>
        /// <param name="infraredFrameDataSize">Size of the InfraredFrame image data</param>
        private unsafe Mat ProcessInfaredFrameData(InfraredFrame infraredFrame)
        {
            // create EMGU and copy the Frame Data into it

            // Generate Mat used for EMGU images
            Mat mat = new Mat(infraredFrameDescription.Height, infraredFrameDescription.Width, DepthType.Cv16U, 1);

            // Move data to new Mat
            infraredFrame.CopyFrameDataToIntPtr(mat.DataPointer, (uint)(infraredFrameDescription.Width * infraredFrameDescription.Height * 2));


            return(mat);
        }
コード例 #4
0
 private void InfraredFrameReader_FrameArrived(InfraredFrameReference infraredFrameReference)
 {
     using (InfraredFrame infraredFrame = infraredFrameReference.AcquireFrame())
     {
         if (infraredFrame != null)
         {
             FrameDescription infraredFrameDescription = infraredFrame.FrameDescription;
             using (KinectBuffer infraredBuffer = infraredFrame.LockImageBuffer())
             {
                 using (var dest = ImagePool.GetOrCreate(infraredFrameDescription.Width, infraredFrameDescription.Height, Imaging.PixelFormat.Gray_16bpp))
                 {
                     infraredFrame.CopyFrameDataToIntPtr(dest.Resource.ImageData, (uint)(infraredFrameDescription.Width * infraredFrameDescription.Height * 2));
                     var time = this.pipeline.GetCurrentTimeFromElapsedTicks(infraredFrameReference.RelativeTime.Ticks);
                     this.InfraredImage.Post(dest, time);
                 }
             }
         }
     }
 }
コード例 #5
0
        /// <summary>
        /// Performs triangle detection on the infrared stream.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Reader_InfraredFrameArrived(object sender, InfraredFrameArrivedEventArgs e)
        {
            //check if infrared frame processing is enabled by the user
            if (!infraredRadioButton.IsChecked ?? false)
            {
                return;
            }
            using (InfraredFrame infraredFrame = e.FrameReference.AcquireFrame()) {
                var infraredFrameDescription = this.infraredFrameReader.InfraredFrameSource.FrameDescription;

                using (Mat infraredMat = new Mat(infraredFrameDescription.Height, infraredFrameDescription.Width, DepthType.Cv16U, 1)) {
                    //convert to Emgu.CV.Mat
                    infraredFrame?.CopyFrameDataToIntPtr(infraredMat.DataPointer, infraredFrameDescription.LengthInPixels * 2);
                    //main processing
                    TriangleFromInfrared(infraredMat);
                    //display
                    CvInvoke.Imshow("infrared", infraredMat);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Processes the infrared frame.
        /// </summary>
        /// <param name="frame">The frame.</param>
        private void ProcessInfraredFrame(InfraredFrame frame)
        {
            if (frame != null)
            {
                FrameDescription frameDescription = frame.FrameDescription;

                // the fastest way to process the body index data is to directly access
                // the underlying buffer
                using (KinectBuffer buffer = frame.LockImageBuffer())
                {
                    // verify data and write the color data to the display bitmap
                    if (((frameDescription.Width * frameDescription.Height) == (buffer.Size / frameDescription.BytesPerPixel)) &&
                        (frameDescription.Width == this.infraredTexture.Width) && (frameDescription.Height == this.infraredTexture.Height))
                    {
                        frame.CopyFrameDataToIntPtr(this.infraredTexturePointer, (uint)this.infraredPointerSize);
                        this.updateInfraredTexture = true;
                    }
                }
            }
        }