Example #1
0
        public ColorFrame(Windows.Kinect.ColorFrame cf)
        {
            Type = FrameType.Color;

            underlyingColorFrame = cf;

            FrameDescription cfd = underlyingColorFrame.CreateFrameDescription(ColorImageFormat.Bgra);

            Width  = cfd.Width;
            Height = cfd.Height;

            // Stride is the number of bytes allocated for one scanline of the bitmap
            // Fact: Scanlines must be aligned on 32-bit boundaries
            // So, each scanline may have padded bytes at the end to ensure this
            // so stride is: ((w * bitsPerPixel + (padBits-1)) / padBits) * padToNBytes
            // where padBits = 8 * padToNBytes
            // See https://msdn.microsoft.com/en-us/library/windows/desktop/aa473780(v=vs.85).aspx
            stride = (Width * 32 + 7) / 8;

            if (colorData == null)
            {
                colorData = new byte[stride * Height];

                using (KinectBuffer colorBuffer = cf.LockRawImageBuffer())
                {
                    // TODO: crop and convert to jpeg.
                    underlyingColorFrame.CopyConvertedFrameDataToArray(colorData, ColorImageFormat.Bgra);
                }

                colorDataBitmap = new Bitmap(Width, Height, stride,
                                             System.Drawing.Imaging.PixelFormat.Format32bppArgb,
                                             Marshal.UnsafeAddrOfPinnedArrayElement(colorData, 0));
            }
        }
Example #2
0
        public SegmentedColorFrame(Windows.Kinect.ColorFrame cf, ClosestBodyFrame cbf) : base(cf)
        {
            underlyingClosestBodyFrame = cbf;

            SetCenter();

            // If unable to segment, then the reader should return a null frame
            segmented = Segment();
            // No need to threshold because there is no depth data
        }
Example #3
0
    private Bitmap ColorImageFrameToBitmap(Windows.Kinect.ColorFrame colorFrame)
    {
        colorFrame.CreateFrameDescription(ColorImageFormat.Yuy2);

        byte[] pixelBuffer = new byte[
            colorFrame.FrameDescription.Width *
            colorFrame.FrameDescription.Height *
            colorFrame.FrameDescription.BytesPerPixel];

        colorFrame.CopyConvertedFrameDataToArray(
            pixelBuffer, ColorImageFormat.Yuy2);
        Bitmap bitmapFrame = ArrayToBitmap(pixelBuffer, colorFrame.FrameDescription.Width, colorFrame.FrameDescription.Height, PixelFormat.Format32bppRgb);

        return(bitmapFrame);
    }
    public bool GetMultiSourceFrame(KinectInterop.SensorData sensorData)
    {
        if(multiSourceFrameReader != null)
        {
            multiSourceFrame = multiSourceFrameReader.AcquireLatestFrame();

            if(multiSourceFrame != null)
            {
                // try to get all frames at once
                msBodyFrame = (sensorFlags & KinectInterop.FrameSource.TypeBody) != 0 ? multiSourceFrame.BodyFrameReference.AcquireFrame() : null;
                msBodyIndexFrame = (sensorFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0 ? multiSourceFrame.BodyIndexFrameReference.AcquireFrame() : null;
                msColorFrame = (sensorFlags & KinectInterop.FrameSource.TypeColor) != 0 ? multiSourceFrame.ColorFrameReference.AcquireFrame() : null;
                msDepthFrame = (sensorFlags & KinectInterop.FrameSource.TypeDepth) != 0 ? multiSourceFrame.DepthFrameReference.AcquireFrame() : null;
                msInfraredFrame = (sensorFlags & KinectInterop.FrameSource.TypeInfrared) != 0 ? multiSourceFrame.InfraredFrameReference.AcquireFrame() : null;

                bool bAllSet =
                    ((sensorFlags & KinectInterop.FrameSource.TypeBody) == 0 || msBodyFrame != null) &&
                    ((sensorFlags & KinectInterop.FrameSource.TypeBodyIndex) == 0 || msBodyIndexFrame != null) &&
                    ((sensorFlags & KinectInterop.FrameSource.TypeColor) == 0 || msColorFrame != null) &&
                    ((sensorFlags & KinectInterop.FrameSource.TypeDepth) == 0 || msDepthFrame != null) &&
                    ((sensorFlags & KinectInterop.FrameSource.TypeInfrared) == 0 || msInfraredFrame != null);

                if(!bAllSet)
                {
                    // release all frames
                    if(msBodyFrame != null)
                    {
                        msBodyFrame.Dispose();
                        msBodyFrame = null;
                    }

                    if(msBodyIndexFrame != null)
                    {
                        msBodyIndexFrame.Dispose();
                        msBodyIndexFrame = null;
                    }

                    if(msColorFrame != null)
                    {
                        msColorFrame.Dispose();
                        msColorFrame = null;
                    }

                    if(msDepthFrame != null)
                    {
                        msDepthFrame.Dispose();
                        msDepthFrame = null;
                    }

                    if(msInfraredFrame != null)
                    {
                        msInfraredFrame.Dispose();
                        msInfraredFrame = null;
                    }
                }
        //				else
        //				{
        //					bool bNeedBody = (sensorFlags & KinectInterop.FrameSource.TypeBody) != 0;
        //					bool bNeedBodyIndex = (sensorFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0;
        //					bool bNeedColor = (sensorFlags & KinectInterop.FrameSource.TypeColor) != 0;
        //					bool bNeedDepth = (sensorFlags & KinectInterop.FrameSource.TypeDepth) != 0;
        //					bool bNeedInfrared = (sensorFlags & KinectInterop.FrameSource.TypeInfrared) != 0;
        //
        //					bAllSet = true;
        //				}
            }

            return (multiSourceFrame != null);
        }

        return false;
    }
    public void FreeMultiSourceFrame(KinectInterop.SensorData sensorData)
    {
        // release all frames
        if(msBodyFrame != null)
        {
            msBodyFrame.Dispose();
            msBodyFrame = null;
        }

        if(msBodyIndexFrame != null)
        {
            msBodyIndexFrame.Dispose();
            msBodyIndexFrame = null;
        }

        if(msColorFrame != null)
        {
            msColorFrame.Dispose();
            msColorFrame = null;
        }

        if(msDepthFrame != null)
        {
            msDepthFrame.Dispose();
            msDepthFrame = null;
        }

        if(msInfraredFrame != null)
        {
            msInfraredFrame.Dispose();
            msInfraredFrame = null;
        }

        if(multiSourceFrame != null)
        {
            multiSourceFrame = null;
        }
    }
Example #6
0
 public HeadColorFrame(Windows.Kinect.ColorFrame cf, ClosestBodyFrame cbf) : base(cf, cbf)
 {
     Type = FrameType.HeadColor;
 }
Example #7
0
 // Token: 0x060028EE RID: 10478 RVA: 0x000D2BDA File Offset: 0x000D0FDA
 internal ColorFrame(IntPtr pNative)
 {
     this._pNative = pNative;
     ColorFrame.Windows_Kinect_ColorFrame_AddRefObject(ref this._pNative);
 }