Example #1
0
    /// <summary>
    ///The first time in each frame that it is called, poll the kinect for updated color data and return
    ///true if there is new data. Subsequent calls do nothing and return the same value.
    /// </summary>
    /// <returns>
    /// A <see cref="System.Boolean"/> : is there new data this frame
    /// </returns>
    bool KinectInterface.pollColor()
    {
        if (!updatedColor)
        {
            updatedColor = true;
            IntPtr imageFramePtr = IntPtr.Zero;

            int hr = NativeMethods.NuiImageStreamGetNextFrame(colorStreamHandle, 100, 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);
                colorImage = extractColorImage(lockedRectPtr);

                hr = NativeMethods.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr);
            }
        }
        return(newColor);
    }
Example #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);
    }
Example #3
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);
    }
    public static bool PollColor(IntPtr colorStreamHandle, ref byte[] videoBuffer)
    {
        IntPtr imageFramePtr = IntPtr.Zero;
        bool   newColor      = false;

        int hr = KinectV1Wrapper.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);
            Marshal.Copy(lockedRectPtr.pBits, videoBuffer, 0, videoBuffer.Length);
            frameTexture.UnlockRect(0);
            hr = KinectV1Wrapper.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr);
        }
        else
        {
            Debug.Log("color frame not ready " + hr.ToString());
        }

        return(newColor);
    }
Example #5
0
    //poll kinect for updated color data
    bool KinectInterface.pollColor()
    {
        if (!updatedColor)
        {
            updatedColor = true;
            IntPtr imageFramePtr = IntPtr.Zero;
            int    hr            = NativeMethods.NuiImageStreamGetNextFrame(colorStreamHandle, 100, ref imageFramePtr);
            if (hr == 0)
            {
                newColor = true;
                NuiImageFrame  imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame));
                NuiImageBuffer imageBuf   = (NuiImageBuffer)Marshal.PtrToStructure(imageFrame.pFrameTexture, typeof(NuiImageBuffer));
                colorImage = extractColorImage(imageBuf);

                hr = NativeMethods.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr);
            }
        }
        return(newColor);
    }
Example #6
0
    /// <summary>
    ///The first time in each frame that it is called, poll the kinect for updated depth (and player) data and return
    ///true if there is new data. Subsequent calls do nothing and return the same value.
    /// </summary>
    /// <returns>
    /// A <see cref="System.Boolean"/> : is there new data this frame
    /// </returns>
    bool KinectInterface.pollDepth()
    {
        if (!updatedDepth)
        {
            updatedDepth = true;
            IntPtr imageFramePtr = IntPtr.Zero;
            int    hr            = NativeMethods.NuiImageStreamGetNextFrame(depthStreamHandle, 100, ref imageFramePtr);
            if (hr == 0)
            {
                newDepth = true;
                NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame));

                NuiImageBuffer imageBuf = (NuiImageBuffer)Marshal.PtrToStructure(imageFrame.pFrameTexture, typeof(NuiImageBuffer));
                depthPlayerData = extractDepthImage(imageBuf);

                hr = NativeMethods.NuiImageStreamReleaseFrame(depthStreamHandle, imageFramePtr);
            }
        }
        return(newDepth);
    }
Example #7
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);
    }
Example #8
0
    /// <summary>
    ///The first time in each frame that it is called, poll the kinect for updated color data and return
    ///true if there is new data. Subsequent calls do nothing and return the same value.
    /// </summary>
    /// <returns>
    /// A <see cref="System.Boolean"/> : is there new data this frame
    /// </returns>
    bool KinectInterface.pollColor()
    {
        if (!updatedColor)
        {
            updatedColor = true;
            IntPtr imageFramePtr = IntPtr.Zero;
            int    hr            = NativeMethods.NuiImageStreamGetNextFrame(colorStreamHandle, 100, ref imageFramePtr);
            if (hr == 0)
            {
                newColor = true;
                NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame));

                //Debug.Log("ptr:" + imageFramePtr + " frame:" + imageFrame.dwFrameNumber);
                NuiImageBuffer imageBuf = (NuiImageBuffer)Marshal.PtrToStructure(imageFrame.pFrameTexture, typeof(NuiImageBuffer));
                //Debug.Log("width:" + imageBuf.m_Width + " height:" + imageBuf.m_Height + " total:" + (imageBuf.m_Width * imageBuf.m_Height * imageBuf.m_BytesPerPixel));

                colorImage = extractColorImage(imageBuf);

                hr = NativeMethods.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr);
            }
        }
        return(newColor);
    }