public void Update(InfraredFrame frame)
        {
            if (Bitmap == null)
            {
                Width = frame.FrameDescription.Width;
                Height = frame.FrameDescription.Height;
                InfraredData = new ushort[Width * Height];
                Pixels = new byte[Width * Height * 4];
                Bitmap = new WriteableBitmap(Width, Height, 96.0, 96.0, PixelFormats.Bgr32, null);
            }

            frame.CopyFrameDataToArray(InfraredData);
            
            int colorIndex = 0;

            for (int infraredIndex = 0; infraredIndex < InfraredData.Length; infraredIndex++)
            {
                ushort ir = InfraredData[infraredIndex];
                
                byte intensity = (byte)(ir >> 6);

                Pixels[colorIndex++] = intensity; // Blue
                Pixels[colorIndex++] = intensity; // Green   
                Pixels[colorIndex++] = intensity; // Red
                
                colorIndex++;
            }

            Bitmap.Lock();

            Marshal.Copy(Pixels, 0, Bitmap.BackBuffer, Pixels.Length);
            Bitmap.AddDirtyRect(new Int32Rect(0, 0, Width, Height));

            Bitmap.Unlock();
        }
Example #2
0
 public async void Update(InfraredFrame frame)
 {
     if (frame != null)
     {
         frame.CopyFrameDataToArray(_data);
         await UpdateAsync(_data);
     }
 }
Example #3
0
        /// <summary>
        /// Process the infrared frames and update UI
        /// </summary>
        private void OnInfraredFrameArrived(object sender, InfraredFrameArrivedEventArgs e)
        {
            // Reference to infrared frame
            InfraredFrameReference refer = e.FrameReference;

            if (refer == null)
            {
                return;
            }

            // Get infrared frame
            InfraredFrame frame = refer.AcquireFrame();

            if (frame == null)
            {
                return;
            }

            // Process it
            using (frame)
            {
                // Get the description
                FrameDescription frameDesc = frame.FrameDescription;

                if (((frameDesc.Width * frameDesc.Height) == _infraData.Length) && (frameDesc.Width == _infraBitmap.PixelWidth) && (frameDesc.Height == _infraBitmap.PixelHeight))
                {
                    // Copy data
                    frame.CopyFrameDataToArray(_infraData);

                    int colorPixelIndex = 0;

                    for (int i = 0; i < _infraData.Length; ++i)
                    {
                        // Get infrared value
                        ushort ir = _infraData[i];

                        // Bitshift
                        byte intensity = (byte)(ir >> 8);

                        // Assign infrared intensity
                        _infraPixels[colorPixelIndex++] = intensity;
                        _infraPixels[colorPixelIndex++] = intensity;
                        _infraPixels[colorPixelIndex++] = intensity;

                        ++colorPixelIndex;
                    }

                    // Copy output to bitmap
                    _infraBitmap.WritePixels(
                        new Int32Rect(0, 0, frameDesc.Width, frameDesc.Height),
                        _infraPixels,
                        frameDesc.Width * _bytePerPixel,
                        0);
                }
            }
        }
Example #4
0
        //InfraredFrame Stream to Image
        public BitmapSource ToBitmapSrc(InfraredFrame frame)
        {
            int width  = frame.FrameDescription.Width;
            int height = frame.FrameDescription.Height;

            ushort[] frameData = new ushort[width * height];
            frame.CopyFrameDataToArray(frameData);

            return(KinectExtensions.ToBitmapSrc(frameData, width, height));
        }
Example #5
0
        //used for multiple video sources
        private void Reader_MultiSourceFrameArrived(MultiSourceFrameReader sender, MultiSourceFrameArrivedEventArgs e)
        {
            MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame();

            // If the Frame has expired by the time we process this event, return.
            if (multiSourceFrame == null)
            {
                return;
            }
            //resets all frames
            DepthFrame     depthFrame         = null;
            ColorFrame     colorFrame         = null;
            InfraredFrame  infraredFrame      = null;
            BodyFrame      bodyFrame          = null;
            BodyIndexFrame bodyIndexFrame     = null;
            IBuffer        depthFrameData     = null;
            IBuffer        bodyIndexFrameData = null;
            // Com interface for unsafe byte manipulation
            IBufferByteAccess bodyIndexByteAccess = null;

            switch (currentDisplayFrameType)
            {
            case DisplayFrameType.Infrared:
                using (infraredFrame = multiSourceFrame.InfraredFrameReference.AcquireFrame())
                {
                    ShowInfraredFrame(infraredFrame);
                }
                break;

            case DisplayFrameType.Color:
                using (colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame())
                {
                    ShowColorFrame(colorFrame);
                }
                break;

            case DisplayFrameType.Depth:
                using (depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame())
                {
                    ShowDepthFrame(depthFrame);
                }
                break;


            case DisplayFrameType.BodyJoints:
                using (bodyFrame = multiSourceFrame.BodyFrameReference.AcquireFrame())
                {
                    ShowBodyJoints(bodyFrame);
                }
                break;

            default:
                break;
            }
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplayInfraredFrame"/> class
        /// from an <c>InfraredFrame</c> with the data already extracted.
        /// </summary>
        /// <param name="frame">The frame.</param>
        /// <param name="frameData">The frame data.</param>
        internal ReplayInfraredFrame(InfraredFrame frame, ushort[] frameData)
        {
            this.FrameType    = FrameTypes.Infrared;
            this.RelativeTime = frame.RelativeTime;

            this.Width         = frame.FrameDescription.Width;
            this.Height        = frame.FrameDescription.Height;
            this.BytesPerPixel = frame.FrameDescription.BytesPerPixel;

            _frameData = frameData;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplayInfraredFrame"/> class
        /// from an <c>InfraredFrame</c> with the data already extracted.
        /// </summary>
        /// <param name="frame">The frame.</param>
        /// <param name="frameData">The frame data.</param>
        public ReplayInfraredFrameCustomTime(InfraredFrame frame, ushort[] frameData, TimeSpan relativeTime)
        {
            this.FrameType    = FrameTypes.Infrared;
            this.RelativeTime = relativeTime;

            this.Width         = frame.FrameDescription.Width;
            this.Height        = frame.FrameDescription.Height;
            this.BytesPerPixel = frame.FrameDescription.BytesPerPixel;

            _frameData = frameData;
        }
Example #8
0
        public WriteableBitmap ParseToWriteableBitmap(InfraredFrame infraredFrame)
        {
            WriteableBitmap infraredBitmap = new WriteableBitmap(infraredFrame.FrameDescription.Width, infraredFrame.FrameDescription.Height, 96.0, 96.0, PixelFormats.Gray32Float, null);

            using (Microsoft.Kinect.KinectBuffer infraredBuffer = infraredFrame.LockImageBuffer())
            {
                ConvertInfraredFrameData(infraredBitmap, infraredFrame.FrameDescription, infraredBuffer.UnderlyingBuffer, infraredBuffer.Size);
            }

            return(infraredBitmap);
        }
Example #9
0
        void reader_IRFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            using (InfraredFrame frame = reference.InfraredFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    int      width     = frame.FrameDescription.Width;
                    int      height    = frame.FrameDescription.Height;
                    ushort[] data      = new ushort[width * height];
                    byte[]   pixelData = new byte[width * height * 4];
                    int      xcoord    = 0;
                    int      ycoord    = 0;

                    frame.CopyFrameDataToArray(data);
                    int    akt    = 0;
                    Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
                    for (int infraredIndex = 0; infraredIndex < data.Length; infraredIndex++)
                    {
                        ushort ir        = data[infraredIndex];
                        byte   intensity = (byte)(ir >> 8);

                        pixelData[infraredIndex * 4]     = intensity; // Blue
                        pixelData[infraredIndex * 4 + 1] = intensity; // Green
                        pixelData[infraredIndex * 4 + 2] = intensity; // Red
                        pixelData[infraredIndex * 4 + 3] = 255;       //Brightness
                    }
                    var bitmapdata = bitmap.LockBits(
                        new Rectangle(0, 0, width, height),
                        ImageLockMode.WriteOnly,
                        bitmap.PixelFormat
                        );
                    IntPtr ptr = bitmapdata.Scan0;

                    Marshal.Copy(pixelData, 0, ptr, pixelData.Length);
                    bitmap.UnlockBits(bitmapdata);
                    bitmap.RotateFlip(RotateFlipType.Rotate180FlipY);

                    EuclideanColorFiltering filter  = new EuclideanColorFiltering();
                    ResizeNearestNeighbor   filter2 = new ResizeNearestNeighbor(512, 424);
                    filter.Radius      = (short)trackBar1.Value; //Increase this to allow off-whites
                    filter.FillOutside = false;

                    Bitmap bmp = filter.Apply(bitmap);

                    filter2.Apply(bmp);
                    //filter3.Apply(bmp);
                    pictureBox1.Image = bitmap;
                }
            }
        }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplayInfraredFrame"/> class
        /// from an <c>InfraredFrame</c>.
        /// </summary>
        /// <param name="frame">The frame.</param>
        internal ReplayInfraredFrame(InfraredFrame frame)
        {
            this.FrameType = FrameTypes.Infrared;
            this.RelativeTime = frame.RelativeTime;

            this.Width = frame.FrameDescription.Width;
            this.Height = frame.FrameDescription.Height;
            this.BytesPerPixel = frame.FrameDescription.BytesPerPixel;

            _frameData = new ushort[this.Width * this.Height];

            frame.CopyFrameDataToArray(_frameData);
        }
Example #11
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);
        }
Example #12
0
        private void RenderInfraredPixels(InfraredFrame frame)
        {
            int width  = frame.FrameDescription.Width;
            int height = frame.FrameDescription.Height;
            int format = PixelFormats.Gray16.BitsPerPixel;

            ushort[] infraredData = new ushort[width * height];
            frame.CopyFrameDataToArray(infraredData);

            int stride = width * format / 8;

            infraBitmap = BitmapSource.Create(width, height, 96, 96, PixelFormats.Gray16, null, infraredData, stride);
        }
Example #13
0
        private void UpdateInfraredFrame(MultiSourceFrame multiFrame)
        {
            // Frame
            using (InfraredFrame infraredFrame = multiFrame.InfraredFrameReference.AcquireFrame())
            {
                if (infraredFrame == null)
                {
                    return;
                }

                infraredFrame.CopyFrameDataToArray(infraredBuffer);
            }
        }
        /// <summary>
        /// Store infrared image
        /// </summary>
        /// <param name="infraredFrame">infrared frame to be stored</param>
        /// <param name="frameNumber">frame number</param>
        public static void Handle_InfraredFrame(InfraredFrame infraredFrame, String frameNumber)
        {
            using (Microsoft.Kinect.KinectBuffer infraredBuffer = infraredFrame.LockImageBuffer())
            {
                BitmapSource bitmapSource = BitmapSource.Create(infraredWidth, infraredHeight, 96.0, 96.0,
                                                                PixelFormats.Gray16, null, infraredBuffer.UnderlyingBuffer, (int)infraredBuffer.Size, infraredWidth << 1);

                String infraredPath = FramesAndPaths.GetImageFilePath(FramesAndPaths.FileType.InfraredImage, frameNumber);
                bitmapSource.Save(infraredPath + ".jpg", ImageFormat.Jpeg);
            }
            // Release infraredFrame
            infraredFrame.Dispose();
        }
Example #15
0
        public IRMetaData(InfraredFrame myframeIR, bool createBitmap)
        {
            this.frameInfrared = myframeIR;

            this.FrameData = AssignIRFrameData(myframeIR);


            if (createBitmap)
            {
                this.pixels = ImageExtensions.ConvertUshortToByte(this.FrameData);
                irBitmap    = WriteableBitmapUtils.FromByteArray_ToGray(pixels, MetaDataBase.XDepthMaxKinect, MetaDataBase.YDepthMaxKinect);
            }
        }
        public Tuple <BitmapSource, TimeSpan> CaptureInfraredFrameBitmap(LiveFrame frame, byte[] buffer)
        {
            InfraredFrame infraredFrame = frame.NativeInfraredFrame;

            int width  = infraredFrame.FrameDescription.Width;
            int height = infraredFrame.FrameDescription.Height;

            infraredFrame.CopyFrameDataToArray(_smallBuffer);

            BitmapSource result = BufferCaptureBitmapHelper(_smallBuffer, width, height, 2, buffer);

            return(new Tuple <BitmapSource, TimeSpan>(result, infraredFrame.RelativeTime));
        }
Example #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplayInfraredFrame"/> class
        /// from an <c>InfraredFrame</c>.
        /// </summary>
        /// <param name="frame">The frame.</param>
        internal ReplayInfraredFrame(InfraredFrame frame)
        {
            this.FrameType    = FrameTypes.Infrared;
            this.RelativeTime = frame.RelativeTime;

            this.Width         = frame.FrameDescription.Width;
            this.Height        = frame.FrameDescription.Height;
            this.BytesPerPixel = frame.FrameDescription.BytesPerPixel;

            _frameData = new ushort[this.Width * this.Height];

            frame.CopyFrameDataToArray(_frameData);
        }
Example #18
0
        /// <summary>
        /// Multiple Source Reader Handler.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="multiSourceFrameArrivedEventArgs">The <see cref="MultiSourceFrameArrivedEventArgs"/> instance containing the event data.</param>
        private void MultiSourceFrameReaderHandler(object sender, MultiSourceFrameArrivedEventArgs multiSourceFrameArrivedEventArgs)
        {
            MultiSourceFrame reference = null;

            try
            {
                reference = multiSourceFrameArrivedEventArgs.FrameReference.AcquireFrame();
            }
            catch (System.Exception)
            {
                return;
            }


            // Update Color Texture
            if (this.CurrentSource.HasFlag(KinectSources.Color))
            {
                using (ColorFrame frame = reference.ColorFrameReference.AcquireFrame())
                {
                    this.ProcessColorImage(frame);
                }
            }

            // Update Depth Texture
            if (this.CurrentSource.HasFlag(KinectSources.Depth))
            {
                using (DepthFrame frame = reference.DepthFrameReference.AcquireFrame())
                {
                    this.ProcessDepthImage(frame);
                }
            }

            // Update Infrared Image
            if (this.CurrentSource.HasFlag(KinectSources.Infrared))
            {
                using (InfraredFrame frame = reference.InfraredFrameReference.AcquireFrame())
                {
                    this.ProcessInfraredFrame(frame);
                }
            }

            // Update Body Frame
            if (this.CurrentSource.HasFlag(KinectSources.Body))
            {
                using (BodyFrame frame = reference.BodyFrameReference.AcquireFrame())
                {
                    this.ProcessBodyFrame(frame);
                }
            }
        }
        internal static void CopyToFrameToPixelArray(this InfraredFrame infraredFrame, ref ushort[] frameData, ref byte[] pixels)
        {
            var pixelIndex = 0;

            infraredFrame.CopyFrameDataToArray(frameData);

            foreach (var intensity in frameData.Select(framePixel => (byte)(framePixel >> 8)))
            {
                pixels[pixelIndex++] = intensity;
                pixels[pixelIndex++] = intensity;
                pixels[pixelIndex++] = intensity;

                ++pixelIndex;
            }
        }
Example #20
0
        public RecordInfraredFrame(InfraredFrame frame)
        {
            this.Codec = Codecs.RawColor;

            this.FrameType = FrameTypes.Infrared;
            this.RelativeTime = frame.RelativeTime;

            this.Width = frame.FrameDescription.Width;
            this.Height = frame.FrameDescription.Height;
            this.BytesPerPixel = frame.FrameDescription.BytesPerPixel;

            _frameData = new ushort[this.Width * this.Height];

            frame.CopyFrameDataToArray(_frameData);
        }
Example #21
0
 private static void IrReader_FrameArrived(object sender, InfraredFrameArrivedEventArgs e)
 {
     // ColorFrame is IDisposable
     using (InfraredFrame irFrame = e.FrameReference.AcquireFrame())
     {
         if (irFrame != null)
         {
             irFrame.CopyFrameDataToArray(irData);
             foreach (var data in irData)
             {
                 Console.Write(data);
             }
         }
     }
 }
Example #22
0
        private void frameArrivedCallback(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            this.numFramesPassed++;
            if (DateTime.Now > updateFPSMilestone)
            {
                this.stopwatch.Stop();
                double fps = this.numFramesPassed / this.stopwatch.Elapsed.TotalSeconds;
                this.stopwatch.Reset();
                this.stopwatch.Start();
                this.updateFPSMilestone = DateTime.Now + TimeSpan.FromSeconds(this.deltaTimeForFPS);
                this.numFramesPassed    = 0;
                this.statusBox.Text     = fps.ToString();
            }
            MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame();

            using (ColorFrame cFrame = multiSourceFrame.ColorFrameReference.AcquireFrame())
            {
                if (cFrame != null)
                {
                    cFrame.CopyConvertedFrameDataToArray(this.colourArray, ColorImageFormat.Bgra);
                    //Not Needed
                    this.colorBitMap.WritePixels(new Int32Rect(0, 0, cFrame.FrameDescription.Width, cFrame.FrameDescription.Height),
                                                 this.colourArray,
                                                 cFrame.FrameDescription.Width * this.bytesPerColorPixel,
                                                 0);
                    colorOutput.Source = this.colorBitMap;
                    colorConnector.sendToAll(this.colourArray);
                }
            }
            using (DepthFrame dFrame = multiSourceFrame.DepthFrameReference.AcquireFrame())
            {
                if (dFrame != null)
                {
                    dFrame.CopyFrameDataToArray(this.depthArray);   //Ushort Array ! Use BitConverter.getBytes() to convert to two bytes per each uShort. it gives low byte followed by high byte
                    Buffer.BlockCopy(this.depthArray, 0, this.byteDepthArray, 0, this.byteDepthArray.Length);
                    this.depthConnector.sendToAll(this.byteDepthArray);
                }
            }
            using (InfraredFrame IRFrame = multiSourceFrame.InfraredFrameReference.AcquireFrame())
            {
                if (IRFrame != null)
                {
                    IRFrame.CopyFrameDataToArray(this.IRArray);     //Ushort Array ! Use BitConverter.getBytes() to convert to two bytes per each uShort. it gives low byte followed by high byte
                    Buffer.BlockCopy(this.IRArray, 0, this.byteIRArray, 0, this.byteIRArray.Length);
                    this.IRConnector.sendToAll(this.byteIRArray);
                }
            }
        }
Example #23
0
        private void MultiSource_FrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame();

            using (InfraredFrame infraredFrame = multiSourceFrame.InfraredFrameReference.AcquireFrame())
            {
                if (infraredFrame != null)
                {
                    using (KinectBuffer infraredBuffer = infraredFrame.LockImageBuffer())
                    {
                        ProcessInfraredFrameData(infraredBuffer.UnderlyingBuffer, infraredBuffer.Size);
                    }
                }
            }

            using (BodyFrame bodyFrame = multiSourceFrame.BodyFrameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    bodyFrame.GetAndRefreshBodyData(bodies);

                    using (DrawingContext dc = drawingGroup.Open())
                    {
                        dc.DrawImage(infraredBitmap, new Rect(0, 0,
                                                              infraredBitmap.Width,
                                                              infraredBitmap.Height));

                        for (int i = 0; i < 6; i++)
                        {
                            if (faceFrameSources[i].IsTrackingIdValid)
                            {
                                if (faceFrameResults[i] != null)
                                {
                                    DrawFace(i, faceFrameResults[i], dc);
                                }
                            }
                            else
                            {
                                if (bodies[i].IsTracked)
                                {
                                    faceFrameSources[i].TrackingId = bodies[i].TrackingId;
                                }
                            }
                        }
                    }
                }
            }
        }
 private void Reader_InfraredFrameArrived(object sender, InfraredFrameArrivedEventArgs e)
 {
     using (InfraredFrame infrFrame = e.FrameReference.AcquireFrame())
     {
         if (infrFrame != null)
         {
             using (KinectBuffer infrBuffer = infrFrame.LockImageBuffer())
             {
                 if ((infrFrame.FrameDescription.Width * infrFrame.FrameDescription.Height) == (infrBuffer.Size / infrFrame.FrameDescription.BytesPerPixel))
                 {
                     this.ProcessInfraredFrameData(infrBuffer.UnderlyingBuffer, infrBuffer.Size, infrFrame.FrameDescription.BytesPerPixel);
                 }
             }
         }
     }
 }
Example #25
0
 private void DrawInfraredImage(InfraredFrame iframe)
 {
     if (iframe != null)
     {
         Bitmap     ibmp = null;
         BitmapData bd   = null;
         try
         {
             ushort[] idata = new ushort[iframe.FrameDescription.Width * iframe.FrameDescription.Height];
             iframe.CopyFrameDataToArray(idata);
             if (_maxIR < 0)
             {
                 for (int ix = 0; ix < idata.Length; ix++)
                 {
                     _maxIR = Math.Max(_maxIR, idata[ix]);
                     _minIR = Math.Min(_minIR, idata[ix]);
                 }
                 _scIR = _maxIR - _minIR;
             }
             else
             {
                 ibmp = new Bitmap(iframe.FrameDescription.Width, iframe.FrameDescription.Height);
                 bd   = ibmp.LockBits(new Rectangle(0, 0, iframe.FrameDescription.Width, iframe.FrameDescription.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                 int[] ipixels = new int[iframe.FrameDescription.Width * iframe.FrameDescription.Height];
                 for (int ix = 0; ix < idata.Length; ix++)
                 {
                     int pxint = (255 * (idata[ix] - _minIR)) / _scIR;
                     ipixels[ix] = Color.FromArgb(pxint, pxint, pxint).ToArgb();
                 }
                 Marshal.Copy(ipixels, 0, bd.Scan0, ipixels.Length);
                 ibmp.UnlockBits(bd);
                 bd = null;
                 pbInfrared.Image = ibmp;
             }
         }
         catch
         {
         }
         finally
         {
             if ((ibmp != null) && (bd != null))
             {
                 ibmp.UnlockBits(bd);
             }
         }
     }
 }
Example #26
0
        void msfr_MultiSourceFrameArrived(MultiSourceFrameReader sender, MultiSourceFrameArrivedEventArgs args)
        {
            using (MultiSourceFrame msf = args.FrameReference.AcquireFrame()) {
                if (msf != null)
                {
                    using (BodyFrame bodyFrame = msf.BodyFrameReference.AcquireFrame()) {
                        using (InfraredFrame irFrame = msf.InfraredFrameReference.AcquireFrame()) {
                            if (bodyFrame != null && irFrame != null)
                            {
                                irFrame.CopyFrameDataToArray(irData);
                                for (int i = 0; i < irData.Length; i++)
                                {
                                    byte intensity = (byte)(irData[i] >> 8);
                                    irDataConvert[i * 4]     = intensity;
                                    irDataConvert[i * 4 + 1] = intensity;
                                    irDataConvert[i * 4 + 2] = intensity;
                                    irDataConvert[i * 4 + 3] = 255;
                                }
                                irDataConvert.CopyTo(irBitmap.PixelBuffer);
                                irBitmap.Invalidate();

                                bodyFrame.GetAndRefreshBodyData(bodies);
                                bodyCanvas.Children.Clear();
                                foreach (Body body in bodies)
                                {
                                    if (body.IsTracked)
                                    {
                                        Joint headJoint = body.Joints[JointType.Head];
                                        if (headJoint.TrackingState == TrackingState.Tracked)
                                        {
                                            DepthSpacePoint dsp        = sensor.CoordinateMapper.MapCameraPointToDepthSpace(headJoint.Position);
                                            Ellipse         headCircle = new Ellipse()
                                            {
                                                Width = 100, Height = 100, Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0))
                                            };
                                            bodyCanvas.Children.Add(headCircle);
                                            Canvas.SetLeft(headCircle, dsp.X - 50);
                                            Canvas.SetTop(headCircle, dsp.Y - 50);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #27
0
        private void processInfraredFrame(InfraredFrame infraredFrame)
        {
            if (infraredFrame != null)
            {
                Box dimensions = Box.With(infraredFrame.FrameDescription.Width, infraredFrame.FrameDescription.Height);
                frameResolutions[SourceType.INFRARED]  = dimensions;
                framePixelFormats[SourceType.INFRARED] = PixelFormats.Gray16;

                if (infraredPixels == null)
                {
                    infraredPixels = new UInt16[dimensions.Area];
                }

                infraredFrame.CopyFrameDataToArray(infraredPixels);
                infraredFrame?.Dispose();
            }
        }
Example #28
0
        /// <summary>
        /// Used in "Manual" mode to record a single <c>InfraredFrame</c> if
        /// the infrared frame data has already been retrieved from the frame.
        /// </summary>
        public void RecordFrame(InfraredFrame frame, ushort[] frameData)
        {
            if (!_isStarted)
            {
                throw new InvalidOperationException("Cannot record frames unless the KinectRecorder is started.");
            }

            if (frame != null)
            {
                _recordQueue.Enqueue(new ReplayInfraredFrame(frame, frameData));
                System.Diagnostics.Debug.WriteLine("+++ Enqueued Infrared Frame ({0})", _recordQueue.Count);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("!!! FRAME SKIPPED (Infrared in KinectRecorder)");
            }
        }
Example #29
0
 /// <summary>
 /// Acquires the latest infrared frame.
 /// It calles the OnInfraredFrameReceived only if the acquired frame is not null.
 /// </summary>
 protected void UpdateInfraredFrame(bool updateFrameView = true)
 {
     if (infraredFrameReader != null)
     {
         using (InfraredFrame frame = infraredFrameReader.AcquireLatestFrame())
         {
             if (frame != null)
             {
                 if (updateFrameView)
                 {
                     frameView.FrameTexture = frame.ToBitmap();
                 }
                 OnInfraredFrameReceived(frame);
             }
         }
     }
 }
Example #30
0
        /// <summary>
        /// Converts an infrared frame to a System.Media.Imaging.BitmapSource.
        /// </summary>
        /// <param name="frame">The specified infrared frame.</param>
        /// <returns>The specified frame in a System.media.Imaging.BitmapSource representation of the infrared frame.</returns>
        public static ImageSource ToBitmap(this InfraredFrame frame)
        {
            if (_bitmap == null)
            {
                _width        = frame.FrameDescription.Width;
                _height       = frame.FrameDescription.Height;
                _infraredData = new ushort[_width * _height];
                _pixels       = new byte[_width * _height * Constants.BYTES_PER_PIXEL];
                _bitmap       = new WriteableBitmap(_width, _height, Constants.DPI, Constants.DPI, Constants.FORMAT, null);
            }

            frame.CopyFrameDataToArray(_infraredData);

            // Convert the infrared to RGB.
            int colorIndex = 0;

            for (int infraredIndex = 0; infraredIndex < _infraredData.Length; infraredIndex++)
            {
                // Get the infrared value for this pixel
                ushort ir = _infraredData[infraredIndex];

                // To convert to a byte, we're discarding the most-significant
                // rather than least-significant bits.
                // We're preserving detail, although the intensity will "wrap."
                byte intensity = (byte)(ir >> 6);

                _pixels[colorIndex++] = intensity; // Blue
                _pixels[colorIndex++] = intensity; // Green
                _pixels[colorIndex++] = intensity; // Red

                // We're outputting BGR, the last byte in the 32 bits is unused so skip it
                // If we were outputting BGRA, we would write alpha here.
                colorIndex++;
            }

            _bitmap.Lock();

            Marshal.Copy(_pixels, 0, _bitmap.BackBuffer, _pixels.Length);
            _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height));

            _bitmap.Unlock();

            return(_bitmap);
        }
Example #31
0
        private void InfraredFrameReader_FrameArrived(object sender, InfraredFrameArrivedEventArgs e)
        {
            using (InfraredFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame == null)
                {
                    return;
                }

                if (Mode == CameraMode.Infrared)
                {
                    if (blobDetect)
                    {
                        KeyValuePair <BitmapSource, List <KeyValuePair <Emgu.CV.Cvb.CvBlob, CameraSpacePoint> > > kvp = frameProc.processBlobs(depthFrameReader, frame, BlobTreshold);
                        List <KeyValuePair <Emgu.CV.Cvb.CvBlob, CameraSpacePoint> > blobs = kvp.Value;
                        if (kvp.Key == null || blobs == null)
                        {
                            return;
                        }

                        camera.Source     = kvp.Key;
                        blobCamera.Source = camera.Source;

                        if (blobs.Count > 0)
                        {
                            foreach (var blob in blobs)
                            {
                                BlobX = m2cm(blob.Value.X);
                                BlobY = m2cm(blob.Value.Y);
                                BlobZ = m2cm(blob.Value.Z);

                                var blobEventModel = new BlobEventModel(blob.Value, blob.Key.Area);

                                wsClient.SendData(BlobSerializer.SerializeBlob(blobEventModel));
                            }
                        }
                    }
                    else
                    {
                        camera.Source = frameProc.processIRFrame(frame);
                    }
                }
            }
        }
Example #32
0
        private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            using (BodyFrame frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    HandleBodyFrame(frame);
                }
            }

            using (ColorFrame frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    ColorToBitmap(frame);
                }
            }

            using (DepthFrame frame = reference.DepthFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    DepthToBitmap(frame);
                }
            }

            using (InfraredFrame frame = reference.InfraredFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    InfraredToBitmap(frame);
                }
            }

            using (BodyIndexFrame frame = reference.BodyIndexFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    IndexToBitmap(frame);
                }
            }
        }
Example #33
0
        private void StartInfraredStream()
        {
            // Get frame description for the infr output
            var description = Sensor.InfraredFrameSource.FrameDescription;

            // Init infr buffer
            InfraredFrame frame = Infrared = new InfraredFrame();

            frame.Width  = description.Width;
            frame.Height = description.Height;
            frame.Pixels = new ushort[description.LengthInPixels];
            frame.Stamp  = new Timestamp();

            AddOnManager.GetInstance().InitFrame(Name, frame);
            Log(frame.ToString());

            // Start Watch
            InfraredWatch = new StopwatchAvg();
        }
Example #34
0
        /// <summary>
        /// Used in "Manual" mode to record a single <c>InfraredFrame</c> if
        /// the infrared frame data has already been retrieved from the frame.
        /// </summary>
        public override void RecordFrame(InfraredFrame frame, ushort[] frameData)
        {
            if (!_isStarted)
            {
                throw new InvalidOperationException("Cannot record frames unless the KinectRecorder is started.");
            }

            var time = _dataAccessFacade.GetSceneInUseAccess().GetLocation();

            if (!ReferenceEquals(null, frame) && time.HasValue)
            {
                _recordQueue.Enqueue(new ReplayInfraredFrameCustomTime(frame, frameData, time.Value));
                System.Diagnostics.Debug.WriteLine("+++ Enqueued Infrared Frame ({0})", _recordQueue.Count);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("!!! FRAME SKIPPED (Infrared in KinectRecorder)");
            }
        }
        public void RecordFrame(InfraredFrame frame)
        {
            if (!_isStarted)
                throw new InvalidOperationException("Cannot record frames unless the KinectRecorder is started.");

            if (frame != null)
            {
                _recordQueue.Enqueue(new RPInfraredFrame(frame));
                System.Diagnostics.Debug.WriteLine("+++ Enqueued Infrared Frame ({0})", _recordQueue.Count);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("!!! FRAME SKIPPED (Infrared in KinectRecorder)");
            }
        }
Example #36
0
        private void RenderInfraredPixels(InfraredFrame frame)
        {
            int width = frame.FrameDescription.Width;
            int height = frame.FrameDescription.Height;
            int format = PixelFormats.Gray16.BitsPerPixel;

            ushort[] infraredData = new ushort[width * height];
            frame.CopyFrameDataToArray(infraredData);

            int stride = width * format / 8;

            infraBitmap = BitmapSource.Create(width, height, 96, 96, PixelFormats.Gray16, null, infraredData, stride);    
        }
Example #37
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplayInfraredFrame"/> class
        /// from an <c>InfraredFrame</c> with the data already extracted.
        /// </summary>
        /// <param name="frame">The frame.</param>
        /// <param name="frameData">The frame data.</param>
        internal ReplayInfraredFrame(InfraredFrame frame, ushort[] frameData)
        {
            this.FrameType = FrameTypes.Infrared;
            this.RelativeTime = frame.RelativeTime;

            this.Width = frame.FrameDescription.Width;
            this.Height = frame.FrameDescription.Height;
            this.BytesPerPixel = frame.FrameDescription.BytesPerPixel;

            _frameData = frameData;
        }
Example #38
0
        private void ShowInfraredFrame(InfraredFrame infraredFrame)
        {
            bool infraredFrameProcessed = false;

            if (infraredFrame != null)
            {
                FrameDescription infraredFrameDescription = infraredFrame.FrameDescription;

                // verify data and write the new infrared frame data to the display bitmap
                if (((infraredFrameDescription.Width * infraredFrameDescription.Height)
                    == this.infraredFrameData.Length) &&
                    (infraredFrameDescription.Width == this.bitmap.PixelWidth) &&
                    (infraredFrameDescription.Height == this.bitmap.PixelHeight))
                {
                    // Copy the pixel data from the image to a temporary array
                    infraredFrame.CopyFrameDataToArray(this.infraredFrameData);

                    infraredFrameProcessed = true;
                }
            }

            // we got a frame, convert and render
            if (infraredFrameProcessed)
            {
                this.ConvertInfraredDataToPixels();
                this.RenderPixelArray(this.infraredPixels);
            }
        }
        private void ShowInfraredFrame(InfraredFrame infraredFrame)
        {
            // FUNCTION : Event handle for recieving frames
            bool infraredFrameProcessed = false;
            
            if (infraredFrame != null)
            {
                FrameDescription infraredFrameDescription = infraredFrame.FrameDescription;

                // Write the new infrared frame data to the display bitmap
                if (((infraredFrameDescription.Width * infraredFrameDescription.Height) == this.infraredFrameData.Length) && (infraredFrameDescription.Width == this.bitmap.PixelWidth) && (infraredFrameDescription.Height == this.bitmap.PixelHeight))
                {
                    // Add pixel data to temporary array
                    infraredFrame.CopyFrameDataToArray(this.infraredFrameData);

                    infraredFrameProcessed = true;
                }
            }  

            // Render Frame
            if (infraredFrameProcessed)
            {
                this.ConvertInfraredDataToPixels();
                this.RenderPixelArray(this.infraredPixels);
            }
        }
        public void BuildInfraredBitmap(InfraredFrame infraredFrame, SmallFrameBitmap bitmap, bool withLock)
        {
            infraredFrame.CopyFrameDataToArray(_infraredData);

            _displayFilter.Init(
                DisplayFilterMode.GrayScale,
                Frame.DEPTH_INFRARED_WIDTH,
                Frame.DEPTH_INFRARED_HEIGHT,
                0,
                int.MaxValue,
                int.MinValue
            );

            Array.Clear(_infraredPixels, 0, _infraredPixels.Length);
            _displayFilter.Apply(_infraredData, _infraredPixels, null);

            WriteableBitmap outBitmap = bitmap.Bitmap;
            ValidateBitmap(outBitmap, Frame.DEPTH_INFRARED_WIDTH, Frame.DEPTH_INFRARED_HEIGHT);
            CopyToDisplay(outBitmap, _infraredPixels, withLock);
        }
Example #41
0
    private void StartInfraredStream() {
      // Get frame description for the infr output
      var description = Sensor.InfraredFrameSource.FrameDescription;

      // Init infr buffer
      InfraredFrame frame = Infrared = new InfraredFrame();
      frame.Width = description.Width;
      frame.Height = description.Height;
      frame.Pixels = new ushort[description.LengthInPixels];
      frame.Stamp = new Timestamp();

      AddOnManager.GetInstance().InitFrame(Name, frame);
      Log(frame.ToString());

      // Start Watch
      InfraredWatch = new StopwatchAvg();
    }
        public ImageSource ToBitmap(InfraredFrame frame)
        {
            int width = frame.FrameDescription.Width;
            int height = frame.FrameDescription.Height;
            PixelFormat format = PixelFormats.Bgr32;

            ushort[] frameData = new ushort[width * height];
            byte[] pixels = new byte[width * height * (format.BitsPerPixel + 7) / 8];

            frame.CopyFrameDataToArray(frameData);

            int colorIndex = 0;
            for (int infraredIndex = 0; infraredIndex < frameData.Length; infraredIndex++)
            {
                ushort ir = frameData[infraredIndex];

                byte intensity = (byte)(ir >> 7);

                pixels[colorIndex++] = (byte)(intensity / 1); // Blue
                pixels[colorIndex++] = (byte)(intensity / 1); // Green
                pixels[colorIndex++] = (byte)(intensity / 0.4); // Red

                colorIndex++;
            }

            int stride = width * format.BitsPerPixel / 8;

            return BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride);
        }
        private void ShowInfraredFrame(InfraredFrame infraredFrame, BodyFrame bodyFrame)
        {
            bool infraredFrameProcessed = false;

            if (infraredFrame != null)
            {
                FrameDescription infraredFrameDescription = infraredFrame.FrameDescription;

                // verify data and write the new infrared frame data to the display bitmap
                if (((infraredFrameDescription.Width * infraredFrameDescription.Height)
                    == this.infraredFrameData.Length) &&
                    (infraredFrameDescription.Width == this.bitmap.PixelWidth) &&
                    (infraredFrameDescription.Height == this.bitmap.PixelHeight))
                {

                    //Debug.WriteLine("Width is " + infraredFrameDescription.Width);
                    //Debug.WriteLine("Height is " + infraredFrameDescription.Height);

                    infraredWidth = infraredFrameDescription.Width;
                    infraredHeight = infraredFrameDescription.Height;

                    // Copy the pixel data from the image to a temporary array
                    infraredFrame.CopyFrameDataToArray(this.infraredFrameData);

                    infraredFrameProcessed = true;
                }
            }

         
            if (bodyFrame != null && bodyFrame.BodyCount > 0)
            {
                myBodies = new Body[this.kinectSensor.BodyFrameSource.BodyCount];
                bodyFrame.GetAndRefreshBodyData(myBodies);
            }

            // we got a frame, convert and render
            if (infraredFrameProcessed)
            {
                this.ConvertInfraredDataToPixels(myBodies);
                this.RenderPixelArray(this.infraredPixels);
            }
        }