none
wrap kinect c++ code as dll export to C# ,not working RRS feed

  • Question

  • hi guys,

    I am using c++ as programming language in the past days, and that's what i am most familiar , now i want to wrap my code as dll ,and export it to C# code.

    Now i have some problem, the sensor can be inited ,but the update code not working ,after some debugging by placing code to output information at some place, i found that it seems the "WaitForSingleObject" not working ,

    my update code is something like this

    void MSKinectSensor::UpdateOnce()
    {	
    	if ( WAIT_OBJECT_0 == WaitForSingleObject( m_hNextColorFrameEvent, 0 ) )
    	{		
    		UpdateColorStream();		
    		OutputDebugInfo("log.txt","update color");
    	}
    
    	if ( WAIT_OBJECT_0 == WaitForSingleObject( m_hNextDepthFrameEvent, 0 ) )
    	{	
    		UpdateDepthStream();	
    		
    		OutputDebugInfo("log.txt","update depth");
    	}
    }

    any reply would be appreciated.


    Tuesday, November 19, 2013 9:21 AM

Answers

  • At this time, it is a c based library. You can create your own p/invoke into that library but the trick will be getting the structures that you need to pass correctly. If you contact the MSOpenTech team provide feedback or changes the are equipped to accept submissions from the community.

    While not complete, you could try something like this:

    using System.Runtime.InteropServices; namespace KinectCommonBridge { using HRESULT = Int32; using KCBHANDLE = Int32; public enum NUI_IMAGE_RESOLUTION { NUI_IMAGE_RESOLUTION_80x60 = 0, NUI_IMAGE_RESOLUTION_320x240, NUI_IMAGE_RESOLUTION_640x480, NUI_IMAGE_RESOLUTION_1280x960 };

        [StructLayout(LayoutKind.Sequential, Pack = 1), Serializable]
        public class KINECT_IMAGE_FRAME_FORMAT
        {
            public uint dwStructSize;
            public uint dwHeight;
            public uint dwWidth;
            public uint cbBytesPerPixel;
            public uint cbBufferSize;
        }; [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 1)] public struct LARGE_INTEGER { [FieldOffset(0)] public Int64 QuadPart; [FieldOffset(0)] public UInt32 LowPart; [FieldOffset(4)] public Int32 HighPart; } static class KCB { [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern KCBHANDLE KinectOpenDefaultSensor(); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern void KinectCloseSensor(KCBHANDLE hKinect); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern void KinectEnableColorStream(KCBHANDLE hKinect, NUI_IMAGE_RESOLUTION resolution, [In, Out, MarshalAs(UnmanagedType.LPStruct)] KINECT_IMAGE_FRAME_FORMAT pFormat); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern void KinectEnableDepthStream(KCBHANDLE hKinect, bool bNearMode, NUI_IMAGE_RESOLUTION resolution, [In, Out, MarshalAs(UnmanagedType.LPStruct)] KINECT_IMAGE_FRAME_FORMAT pFormat); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern HRESULT KinectGetColorFrame(KCBHANDLE hKinect, uint cbByteBufferSize, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] buffer, ref ulong liTimeStamp); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern HRESULT KinectGetDepthFrame(KCBHANDLE hKinect, uint cbByteBufferSize, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] short[] buffer, ref ulong liTimeStamp); } }



    Carmine Sirignano - MSFT


    Friday, November 22, 2013 6:02 PM

All replies

  • Have a look at Kinect Common Bridge. https://github.com/MSOpenTech/KinectCommonBridge

    Without any context on how you created/opened the stream to get these event objects there is no way to know they are valid handles. Are you checking these are valid? Depending on what else is happening on the system, you may not be getting frames based on other factors.


    Carmine Sirignano - MSFT

    Tuesday, November 19, 2013 10:21 PM
  • thanks , that's really what i want.

    by the way, is there any c# samples for this lib? i search through the net ,found none.

    Friday, November 22, 2013 9:21 AM
  • At this time, it is a c based library. You can create your own p/invoke into that library but the trick will be getting the structures that you need to pass correctly. If you contact the MSOpenTech team provide feedback or changes the are equipped to accept submissions from the community.

    While not complete, you could try something like this:

    using System.Runtime.InteropServices; namespace KinectCommonBridge { using HRESULT = Int32; using KCBHANDLE = Int32; public enum NUI_IMAGE_RESOLUTION { NUI_IMAGE_RESOLUTION_80x60 = 0, NUI_IMAGE_RESOLUTION_320x240, NUI_IMAGE_RESOLUTION_640x480, NUI_IMAGE_RESOLUTION_1280x960 };

        [StructLayout(LayoutKind.Sequential, Pack = 1), Serializable]
        public class KINECT_IMAGE_FRAME_FORMAT
        {
            public uint dwStructSize;
            public uint dwHeight;
            public uint dwWidth;
            public uint cbBytesPerPixel;
            public uint cbBufferSize;
        }; [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 1)] public struct LARGE_INTEGER { [FieldOffset(0)] public Int64 QuadPart; [FieldOffset(0)] public UInt32 LowPart; [FieldOffset(4)] public Int32 HighPart; } static class KCB { [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern KCBHANDLE KinectOpenDefaultSensor(); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern void KinectCloseSensor(KCBHANDLE hKinect); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern void KinectEnableColorStream(KCBHANDLE hKinect, NUI_IMAGE_RESOLUTION resolution, [In, Out, MarshalAs(UnmanagedType.LPStruct)] KINECT_IMAGE_FRAME_FORMAT pFormat); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern void KinectEnableDepthStream(KCBHANDLE hKinect, bool bNearMode, NUI_IMAGE_RESOLUTION resolution, [In, Out, MarshalAs(UnmanagedType.LPStruct)] KINECT_IMAGE_FRAME_FORMAT pFormat); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern HRESULT KinectGetColorFrame(KCBHANDLE hKinect, uint cbByteBufferSize, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] buffer, ref ulong liTimeStamp); [DllImport("KinectCommonBridge.dll", CallingConvention = CallingConvention.Winapi)] public static extern HRESULT KinectGetDepthFrame(KCBHANDLE hKinect, uint cbByteBufferSize, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] short[] buffer, ref ulong liTimeStamp); } }



    Carmine Sirignano - MSFT


    Friday, November 22, 2013 6:02 PM
  • sorry for such a late reply, i have just try this, it works .

    Thanks very much  Carmine Si ,you are really a nice man.

    Monday, November 25, 2013 2:38 AM