示例#1
0
        void useIRFrame(InfraredFrameReference irFrameReference)
        {
            try
            {
                InfraredFrame IRFrame = irFrameReference.AcquireFrame();

                if (IRFrame != null)
                {
                    using (IRFrame)
                    {
                        IRFrame.CopyFrameDataToArray(this.irImagePixelData);

                        this.updateBitmap(IRFrame.FrameDescription.Width, IRFrame.FrameDescription.Height, this.irImagePixelData, false);

                        IRFrame.CopyFrameDataToArray(this.irImagePixelDataOld);

                        this.pictureBox1.Image = new Bitmap(this.colorImageBitmap, this.pictureBox1.Width, this.pictureBox1.Height);
                    }
                }
            }
            catch (Exception er)
            {
                string message = er.Message;
                Console.WriteLine(message);
                // Don't worry about empty frames.
            }
        }
        private ImageSource ToBitmap(InfraredFrame frame)
        {
            int         width  = frame.FrameDescription.Width;
            int         height = frame.FrameDescription.Height;
            PixelFormat format = PixelFormats.Bgr32;


            ushort[] infraredData = new ushort[width * height];
            byte[]   pixelData    = new byte[width * height * (PixelFormats.Bgr32.BitsPerPixel + 7) / 8];

            frame.CopyFrameDataToArray(infraredData);

            int colorIndex = 0;

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

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

                ++colorIndex;
            }

            int stride = width * format.BitsPerPixel / 8;

            return(BitmapSource.Create(width, height, 96, 96, format, null, pixelData, stride));
        }
示例#3
0
        /// <summary>
        /// 赤外線センサーからフレームが到着した際に呼びされるイベントハンドラーです。
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_InfraredFrameArrived(object sender, InfraredFrameArrivedEventArgs e)
        {
            bool infraredFrameProcessed = false;


            using (InfraredFrame infraredFrame = e.FrameReference.AcquireFrame())
            {
                //赤外線フレームが存在するか場合処理を継続します。
                if (infraredFrame != null)
                {
                    //赤外線のフレームに関する情報を含んだオブジェクトを取得します。
                    FrameDescription infraredFrameDescription = infraredFrame.FrameDescription;

                    //infraredFrameDescription が持っている縦横のサイズと到着した赤外線フレームの縦横サイズを比較検証し、
                    //一致していれば次に進みます。
                    if (((infraredFrameDescription.Width * infraredFrameDescription.Height) == this.infraredFrameData.Length) &&
                        (infraredFrameDescription.Width == this.bitmap.PixelWidth) && (infraredFrameDescription.Height == this.bitmap.PixelHeight))
                    {
                        // フレームデータの情報を配列にコピーします。
                        infraredFrame.CopyFrameDataToArray(this.infraredFrameData);
                        infraredFrameProcessed = true;
                    }
                }
            }

            // 赤外線データを元に描画処理を実行します。
            if (infraredFrameProcessed)
            {
                //赤外線データを、RGB 値に変換します。
                this.ConvertInfraredData();

                //変換したデータを画面に描画します。
                this.RenderInfraredPixels(this.infraredPixels);
            }
        }
        public void Update()
        {
            if (reader != null)
            {
                InfraredFrame frame = reader.AcquireLatestFrame();
                if (frame != null)
                {
                    frame.CopyFrameDataToArray(FrameData);

                    int index = 0;
                    foreach (var ir in FrameData)
                    {
                        byte intensity = (byte)(ir >> 8);
                        for (int i = 0; i < 3; i++)
                        {
                            RawData[index++] = intensity;
                        }
                        RawData[index++] = 255; // Alpha
                    }

                    Texture.LoadRawTextureData(RawData);
                    Texture.Apply();

                    frame.Dispose();
                    frame = null;
                }
            }
        }
        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();
        }
        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();
        }
        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);
            }
        }
示例#8
0
        /// <summary>
        /// TODO - not correct yet
        /// </summary>
        /// <param name="myframeIR"></param>
        /// <returns></returns>
        private static ushort[] AssignIRFrameData(InfraredFrame myframeIR)
        {
            ushort[] frameData = new ushort[XDepthMaxKinect * YDepthMaxKinect];

            ushort[] pixelData = new ushort[XDepthMaxKinect * YDepthMaxKinect];

            myframeIR.CopyFrameDataToArray(frameData);

            int index = 0;

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

                pixelData[index] = intensity;


                ++index;
            }



            return(pixelData);
        }
示例#9
0
        /// <summary>
        /// Converts an infrared frame to a System.Drawing.Bitmap.
        /// </summary>
        /// <param name="frame">The specified infrared frame.</param>
        /// <returns>The specified frame in a System.media.ImageSource format.</returns>
        public static Bitmap ToBitmap(this InfraredFrame frame)
        {
            int width  = frame.FrameDescription.Width;
            int height = frame.FrameDescription.Height;

            ushort[] frameData = new ushort[width * height];
            byte[]   pixels    = new byte[width * height * 4];

            frame.CopyFrameDataToArray(frameData);

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

            for (int infraredIndex = 0; infraredIndex < frameData.Length; ++infraredIndex)
            {
                // Get the infrared value for this pixel
                ushort ir = frameData[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 >> 8);

                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;
            }

            return(pixels.ToBitmap(frame.FrameDescription.Width, frame.FrameDescription.Height));
        }
示例#10
0
    void updateInfrared(InfraredFrame infraredFrame)
    {
        if (infraredFrame != null)
        {
            infraredFrame.CopyFrameDataToArray(infraredRawData);

            Parallel.For(0, infraredHeight, y =>
            {
                for (int x = 0; x < infraredWidth; x++)
                {
                    int index      = y * infraredWidth + x;
                    byte intensity = (byte)(infraredRawData[index] >> 8);
                    infraredData[(index << 2) | 0] = intensity;
                    infraredData[(index << 2) | 1] = intensity;
                    infraredData[(index << 2) | 2] = intensity;
                    infraredData[(index << 2) | 3] = 255;
                }
            });

            infraredTexture.LoadRawTextureData(infraredData);
            infraredTexture.Apply();

            infraredFrame.Dispose();
            infraredFrame = null;
        }
    }
        /// <summary>
        /// Handles the infrared frame data arriving from the sensor.
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_InfraredFrameArrived(object sender, InfraredFrameArrivedEventArgs e)
        {
            bool infraredFrameProcessed = false;

            // InfraredFrame is IDisposable
            using (InfraredFrame infraredFrame = e.FrameReference.AcquireFrame())
            {
                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.ConvertInfraredData();
                this.RenderInfraredPixels(this.infraredPixels);
            }
        }
示例#12
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);
            }
        }
示例#13
0
        private void InfraredToBitmap(InfraredFrame frame)
        {
            int width  = frame.FrameDescription.Width;
            int height = frame.FrameDescription.Height;

            frame.CopyFrameDataToArray(infraredData);

            int colorIndex = 0;

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

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

                ++colorIndex;
            }

            int stride = width * PixelFormats.Bgr32.BitsPerPixel / 8;

            this.infraredBitmap.WritePixels(new Int32Rect(0, 0, width, height), infraredBuffer, stride, 0);
        }
示例#14
0
        public ImageSource processIRFrame(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));
        }
示例#15
0
 public async void Update(InfraredFrame frame)
 {
     if (frame != null)
     {
         frame.CopyFrameDataToArray(_data);
         await UpdateAsync(_data);
     }
 }
示例#16
0
 /// <summary>
 /// Update the Bitmap from the supplied <c>InfraredFrame</c>.
 /// </summary>
 public async void Update(InfraredFrame frame)
 {
     if (frame != null)
     {
         frame.CopyFrameDataToArray(_data);
         await UpdateAsync(_data);
     }
 }
示例#17
0
        /// <summary>
        /// Process the infrared frames and update UI
        /// </summary>
        public 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);
                }
            }
        }
示例#18
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));
        }
示例#19
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;
                }
            }
        }
        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));
        }
示例#21
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);
        }
示例#22
0
        private void UpdateInfraredFrame(MultiSourceFrame multiFrame)
        {
            // Frame
            using (InfraredFrame infraredFrame = multiFrame.InfraredFrameReference.AcquireFrame())
            {
                if (infraredFrame == null)
                {
                    return;
                }

                infraredFrame.CopyFrameDataToArray(infraredBuffer);
            }
        }
示例#23
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);
        }
示例#24
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);
             }
         }
     }
 }
示例#25
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);
        }
        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;
            }
        }
示例#27
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);
                }
            }
        }
示例#28
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);
             }
         }
     }
 }
示例#29
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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#30
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();
            }
        }
示例#31
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);
        }
示例#32
0
        /// <summary>
        /// Метод отрисовки инфракрасной камеры из инфракрасного фрейма.
        /// </summary>
        /// <param name="frameReference">Ссылка на инфракрасный фрейм.</param>
        private void ShowIRImage(InfraredFrameReference frameReference)
        {
            // Попытка получить текущий фрейм с сенсора
            InfraredFrame frame = frameReference.AcquireFrame();

            if (frame != null)
            {
                FrameDescription description = null;
                using (frame)
                {
                    // Теперь получаем описание фрейма и создаем изображение для infrare picture box
                    description = frame.FrameDescription;
                    Bitmap outputImage = new Bitmap(description.Width, description.Height, PixelFormat.Format32bppArgb);

                    // Далее создаем указатель на данные картинки и указываем будующий размер
                    System.Drawing.Imaging.BitmapData imageData = outputImage.LockBits(new Rectangle(0, 0, outputImage.Width, outputImage.Height),
                                                                                       ImageLockMode.WriteOnly, outputImage.PixelFormat);
                    IntPtr imageDataPtr = imageData.Scan0;
                    int    size         = imageData.Stride * outputImage.Height;

                    // Теперь копируем изображение в соответствующий массив. Смещаем каждый RGB пиксел к byte размеру, получая grayscale изображение
                    frame.CopyFrameDataToArray(this.rawIRPixelData);
                    byte[] rawData = new byte[description.Width * description.Height * 4];

                    for (int i = 0; i < this.rawIRPixelData.Length; i++)
                    {
                        byte intensity = (byte)(this.rawIRPixelData[i] >> 8);

                        rawData[i * 4]     = intensity;
                        rawData[i * 4 + 1] = intensity;
                        rawData[i * 4 + 2] = intensity;
                        rawData[i * 4 + 3] = 255;
                    }

                    // Наконец создаем картинку из буфера
                    System.Runtime.InteropServices.Marshal.Copy(rawData, 0, imageDataPtr, size);
                    outputImage.UnlockBits(imageData);

                    // Test: Немного яркости для выхода IRSensor.
                    this.pictureBoxInfraredCamera.Image = drawGestureStaticRectabgle(AdjustBrightness(outputImage, 8.0f)); // 8.0f для работы от полуметра, как заявлено в документации Kinect v2
                }
            }
        }
示例#33
0
        /// <summary>
        /// Converts an infrared frame to a System.Drawing.Bitmap.
        /// </summary>
        /// <param name="frame">The specified infrared frame.</param>
        /// <returns>The specified frame in a System.media.ImageSource format.</returns>
        public static Bitmap 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 Bitmap(_width, _height, Constants.FORMAT);
            }

            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 >> 8);

                _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;
            }

            BitmapData bitmapData = _bitmap.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadWrite, _bitmap.PixelFormat);

            Marshal.Copy(_pixels, 0, bitmapData.Scan0, _pixels.Length);

            _bitmap.UnlockBits(bitmapData);

            return(_bitmap);
        }
示例#34
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);
            }
        }
        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);
        }
示例#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);    
        }
示例#37
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);
        }
        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);
        }
        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);
            }
        }