简体   繁体   中英

Passing Image/Depth data from Unity C# to external C# dll

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

Bitmap()构造函数中的stride参数是错误的-stride应该是图像中一行所占用的字节数(这是必需的,因为某些格式(如BMP要求每一行像素都以DWORD对齐的地址开头或其他一些此类要求) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM