0
votes

I have written an external C# dll that takes in an Image and does image processing for detecting hand pose. I am currently using ZigFu unity binding for getting kinect data. Now I want to pass Image/Depth data from Kinect to my C# dll.

Following are code extracts:

C# in Unity

h1.detectHandPose(OpenNIContext.Instance.Depth.GetDepthMap().XRes,OpenNIContext.Instance.Depth.GetDepthMap().YRes);

where h1 is an instace of my C# dll class

and code in C# dll

public int detectHandPose(IntPtr srcptr,Int32 w,Int32 h)
{
   int fingerNum = 0;

   Bitmap srcbmp = new Bitmap(w, h, 2,System.Drawing.Imaging.PixelFormat.Format16bppGrayScale, srcptr);

   ccDefects(srcbmp);

   return fingerNum;
}

public Image<Bgr, Byte> ccDefects(Bitmap b)
{
   //all image processing code for convexity defects    
}

However I am not able to get this running and get following error:

ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter] System.Drawing.GDIPlus.CheckStatus (Status status) System.Drawing.Bitmap..ctor (Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0) (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (int,int,int,System.Drawing.Imaging.PixelFormat,intptr) handDetectionDLL.handDetection.detectHandPose (IntPtr srcptr, Int32 w, Int32 h) OpenNIDepthmapViewer.FixedUpdate () (at Assets/OpenNI/Scripts/OpenNIDepthmapViewer.cs:152)

Any help is appreciated.

Thanks, Kumar

1
Have you tried answers.unity3d.com ? It may take a few hours, but it is likely that you'll get a better answer there. - Slime recipe

1 Answers

0
votes

The stride parameter in the Bitmap() constructor is wrong - stride should be the number of bytes a row in the image occupies (necessary since some formats like BMP require that every row of pixels start on a DWORD-aligned address or some other such requirements)