Exemple #1
0
    public static bool PollColor(IntPtr colorStreamHandle, ref Color32[] colorImage)
    {
        IntPtr imageFramePtr = IntPtr.Zero;
        bool   newColor      = false;

        int hr = KinectWrapper.NuiImageStreamGetNextFrame(colorStreamHandle, 0, ref imageFramePtr);

        if (hr == 0)
        {
            newColor = true;

            NuiImageFrame    imageFrame   = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame));
            INuiFrameTexture frameTexture = (INuiFrameTexture)Marshal.GetObjectForIUnknown(imageFrame.pFrameTexture);

            NuiLockedRect lockedRectPtr = new NuiLockedRect();
            IntPtr        r             = IntPtr.Zero;

            frameTexture.LockRect(0, ref lockedRectPtr, r, 0);
            ExtractColorImage(lockedRectPtr, ref colorImage);

            frameTexture.UnlockRect(0);
            hr = KinectWrapper.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr);
        }

        return(newColor);
    }
Exemple #2
0
    public static bool PollDepth(IntPtr depthStreamHandle, bool isNearMode, ref short[] depthPlayerData)
    {
        IntPtr imageFramePtr = IntPtr.Zero;
        bool   newDepth      = false;

        if (isNearMode)
        {
            KinectWrapper.NuiImageStreamSetImageFrameFlags(depthStreamHandle, NuiImageStreamFlags.EnableNearMode);
        }
        else
        {
            KinectWrapper.NuiImageStreamSetImageFrameFlags(depthStreamHandle, NuiImageStreamFlags.None);
        }

        int hr = KinectWrapper.NuiImageStreamGetNextFrame(depthStreamHandle, 0, ref imageFramePtr);

        if (hr == 0)
        {
            newDepth = true;

            NuiImageFrame    imageFrame   = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame));
            INuiFrameTexture frameTexture = (INuiFrameTexture)Marshal.GetObjectForIUnknown(imageFrame.pFrameTexture);

            NuiLockedRect lockedRectPtr = new NuiLockedRect();
            IntPtr        r             = IntPtr.Zero;

            frameTexture.LockRect(0, ref lockedRectPtr, r, 0);
            depthPlayerData = ExtractDepthImage(lockedRectPtr);

            frameTexture.UnlockRect(0);
            hr = KinectWrapper.NuiImageStreamReleaseFrame(depthStreamHandle, imageFramePtr);
        }

        return(newDepth);
    }
Exemple #3
0
    //public static bool PollColor(IntPtr colorStreamHandle, ref byte[] videoBuffer, ref Color32[] colorImage)
    public static bool PollColor(IntPtr colorStreamHandle, ref Color32[] colorImage)
    {
        IntPtr imageFramePtr = IntPtr.Zero;
        bool   newColor      = false;

        int hr = KinectWrapper.NuiImageStreamGetNextFrame(colorStreamHandle, 0, ref imageFramePtr);

        if (hr == 0)
        {
            newColor = true;

            NuiImageFrame    imageFrame   = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame));
            INuiFrameTexture frameTexture = (INuiFrameTexture)Marshal.GetObjectForIUnknown(imageFrame.pFrameTexture);

            NuiLockedRect lockedRectPtr = new NuiLockedRect();
            IntPtr        r             = IntPtr.Zero;

            frameTexture.LockRect(0, ref lockedRectPtr, r, 0);

            ColorBuffer cb          = (ColorBuffer)Marshal.PtrToStructure(lockedRectPtr.pBits, typeof(ColorBuffer));
            int         totalPixels = Constants.ColorImageWidth * Constants.ColorImageHeight;

            for (int pix = 0; pix < totalPixels; pix++)
            {
                int ind = pix;                 // totalPixels - pix - 1;
                colorImage[ind].r = cb.pixels[pix].r;
                colorImage[ind].g = cb.pixels[pix].g;
                colorImage[ind].b = cb.pixels[pix].b;
                colorImage[ind].a = 255;
//				videoBuffer[4 * ind] = cb.pixels[pix].b;
//				videoBuffer[4 * ind + 1] = cb.pixels[pix].g;
//				videoBuffer[4 * ind + 2] = cb.pixels[pix].r;
//				videoBuffer[4 * ind + 3] = 255;
            }

            frameTexture.UnlockRect(0);
            hr = KinectWrapper.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr);
        }

        return(newColor);
    }