Kinect No Color Data using INUISensor

Hello,

I’m having a problem where I do not see any color data coming from the Kinect’s camera when I initialize the Kinect using the “NUI_INITIALIZE_FLAG_USES_COLOR” flag. I’m able to get depth data with no problem. I’ve been checking the output using texture output in Unity and the Kinect Studio application included with the Microsoft Kinect SDK. The depth preview would show the depth data, but the color preview is just black.

I’m trying to implement the INUISensor interface with my Kinect wrapper, but the olny problem so far is that I cannot initialize the camera. I’ve tested without using the INUISensor interface, and it works fine. So I think my INUISensor interface might be wrong. Though I’m not sure.

If it’s not to much to ask if someone could look at the interface I created below and see if I made any mistakes that might be causing the error. (I’ve excluded the guid number just in case I shouldn’t post it here.)

public static INuiSensor KinectSensor;

[Guid("#####")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComImport()]
public interface INuiSensor
{
	[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
	[PreserveSig]
	int NuiInitialize(NuiInitializeFlags dwFlags);
	
	[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
	[PreserveSig]
	void NuiShutdown();

	[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
	[PreserveSig]
	int NuiImageStreamOpen(NuiImageTypes eImageType, NuiImageResolutions eResolution, uint dwImageFrameFlags, uint dwFrameLimit, IntPtr hNextFrameEvent, ref IntPtr phStreamHandle);
	
	[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
	[PreserveSig]
	int NuiImageStreamSetImageFrameFlags(IntPtr hStream, NuiImageFlags dwImageFrameFlags);
	
	[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
	[PreserveSig]
	int NuiImageStreamGetImageFrameFlags(IntPtr hStream, ref NuiImageFlags dwImageFrameFlags);
	
	[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
	[PreserveSig]
	int NuiImageStreamGetNextFrame(IntPtr hStream, uint dwMillisecondsToWait, ref IntPtr ppcImageFrame);
	
	[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
	[PreserveSig]
	int NuiImageStreamReleaseFrame(IntPtr hStream, IntPtr pImageFrame);
	
	[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
	[PreserveSig]
	int NuiStatus();
}
// Get the number of connect devices that the native code can find
hresult = KinectModel.NuiGetSensorCount(out KinectSensorCount);
if(hresult != 0)
{
	throw new Exception("Could not get sensor count.");
}
// If the number of devices is greater than 0, than check each found sensor if it can be created and its status.
if(KinectSensorCount > 0)
{
	// Get the first sensor found
	IntPtr nuiSensorPtr = IntPtr.Zero;
	hresult = KinectModel.NuiCreateSensorByIndex(0, ref nuiSensorPtr);
	if(hresult != 0)
	{
		throw new Exception("Unable to create sensor by index 0");
	}

	KinectModel.KinectSensor = (KinectModel.INuiSensor)Marshal.GetObjectForIUnknown(nuiSensorPtr);
	
	// Once a sensor has been found then initialize it.
	hresult = KinectModel.KinectSensor.NuiInitialize(KinectModel.NuiInitializeFlags.UsesColor);
	if(hresult != 0)
	{
		throw new Exception("Could not initialize the kinect sensor.");
	}
	
	// Get a pointer to the color stream handle
	hresult = KinectModel.KinectSensor.NuiImageStreamOpen(KinectModel.NuiImageTypes.Color, KinectModel.NuiImageResolutions.Resolution_640x480, 0, 2, IntPtr.Zero, ref ColorStreamHandle);
	if(hresult != 0)
	{
		throw new Exception("Unable to open the color stream");
	}
}

I’ve had no luck so far. I’ve went back to the COM Import Tutorials on MSDN to see what I could find. I learned from before that I have to have the methods in the same sequence as they appear in the unmanaged code. What I’m not sure about now is if I have to include all of the methods to properly import the interface from C++ to C#. Due to my uncertainty I did make an interface with all of the methods in the INUISensor interface, but still not able to get the color stream from the camera to initialize.